Skip to content

Commit d8e180d

Browse files
michichJames Morris
authored andcommitted
bsdacct: switch credentials for writing to the accounting file
When process accounting is enabled, every exiting process writes a log to the account file. In addition, every once in a while one of the exiting processes checks whether there's enough free space for the log. SELinux policy may or may not allow the exiting process to stat the fs. So unsuspecting processes start generating AVC denials just because someone enabled process accounting. For these filesystem operations, the exiting process's credentials should be temporarily switched to that of the process which enabled accounting, because it's really that process which wanted to have the accounting information logged. Signed-off-by: Michal Schmidt <[email protected]> Acked-by: David Howells <[email protected]> Acked-by: Serge Hallyn <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: James Morris <[email protected]>
1 parent 939a942 commit d8e180d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

kernel/acct.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,13 +491,17 @@ static void do_acct_process(struct bsd_acct_struct *acct,
491491
u64 run_time;
492492
struct timespec uptime;
493493
struct tty_struct *tty;
494+
const struct cred *orig_cred;
495+
496+
/* Perform file operations on behalf of whoever enabled accounting */
497+
orig_cred = override_creds(file->f_cred);
494498

495499
/*
496500
* First check to see if there is enough free_space to continue
497501
* the process accounting system.
498502
*/
499503
if (!check_free_space(acct, file))
500-
return;
504+
goto out;
501505

502506
/*
503507
* Fill the accounting struct with the needed info as recorded
@@ -578,6 +582,8 @@ static void do_acct_process(struct bsd_acct_struct *acct,
578582
sizeof(acct_t), &file->f_pos);
579583
current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
580584
set_fs(fs);
585+
out:
586+
revert_creds(orig_cred);
581587
}
582588

583589
/**

0 commit comments

Comments
 (0)