mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 08:24:42 +01:00
aa-unconfined: Fix race when reading proc/*/attr/current
aa-unconfined can fault if it looses the race between checkking if proc/*/attr/{apparmor/,}current exists, and actually opening the file. Catch open/file errors and ignore them like the file doesn't exist. Fixes: https://gitlab.com/apparmor/apparmor/-/issues/355 Signed-off-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
parent
95d9ba8d8b
commit
c4f649da92
1 changed files with 6 additions and 1 deletions
|
@ -101,13 +101,18 @@ def get_pids_netstat(netstat='netstat'):
|
|||
def read_proc_current(filename):
|
||||
attr = None
|
||||
|
||||
if os.path.exists(filename):
|
||||
try:
|
||||
# don't bother with if os.path.exists(filename): there is always a race
|
||||
with open_file_read(filename) as current:
|
||||
for line in current:
|
||||
line = line.strip()
|
||||
if line.endswith(' (complain)', 1) or line.endswith(' (enforce)', 1) or line.endswith(' (kill)', 1): # enforce at least one char as profile name
|
||||
# intentionally not checking for '(unconfined)', because $binary confined by $profile (unconfined) would look very confusing
|
||||
attr = line
|
||||
except OSError:
|
||||
# just ignore errors atm
|
||||
# print("Error trying to open {filename}")
|
||||
return None
|
||||
|
||||
return attr
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue