Skip to content

Commit 9bb698b

Browse files
rgbriggsgregkh
authored andcommitted
audit: move calcs after alloc and check when logging set loginuid
commit 76a658c upstream. Move the calculations of values after the allocation in case the allocation fails. This avoids wasting effort in the rare case that it fails, but more importantly saves us extra logic to release the tty ref. Signed-off-by: Richard Guy Briggs <[email protected]> Signed-off-by: Paul Moore <[email protected]> Cc: Ben Hutchings <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent bea8a67 commit 9bb698b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

kernel/auditsc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,14 +1981,15 @@ static void audit_log_set_loginuid(kuid_t koldloginuid, kuid_t kloginuid,
19811981
if (!audit_enabled)
19821982
return;
19831983

1984+
ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_LOGIN);
1985+
if (!ab)
1986+
return;
1987+
19841988
uid = from_kuid(&init_user_ns, task_uid(current));
19851989
oldloginuid = from_kuid(&init_user_ns, koldloginuid);
19861990
loginuid = from_kuid(&init_user_ns, kloginuid),
19871991
tty = audit_get_tty(current);
19881992

1989-
ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_LOGIN);
1990-
if (!ab)
1991-
return;
19921993
audit_log_format(ab, "pid=%d uid=%u", task_pid_nr(current), uid);
19931994
audit_log_task_context(ab);
19941995
audit_log_format(ab, " old-auid=%u auid=%u tty=%s old-ses=%u ses=%u res=%d",

0 commit comments

Comments
 (0)