Skip to content

Commit 893c47d

Browse files
Austin Kimpcmoore
authored andcommitted
selinux: return early for possible NULL audit buffers
audit_log_start() may return NULL in below cases: - when audit is not initialized. - when audit backlog limit exceeds. After the call to audit_log_start() is made and then possible NULL audit buffer argument is passed to audit_log_*() functions, audit_log_*() functions return immediately in case of a NULL audit buffer argument. But it is optimal to return early when audit_log_start() returns NULL, because it is not necessary for audit_log_*() functions to be called with NULL audit buffer argument. So add exception handling for possible NULL audit buffers where return value can be handled from callers. Signed-off-by: Austin Kim <[email protected]> [PM: tweak subject line] Signed-off-by: Paul Moore <[email protected]>
1 parent e73f0f0 commit 893c47d

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

security/selinux/hooks.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3325,6 +3325,8 @@ static int selinux_inode_setxattr(struct user_namespace *mnt_userns,
33253325
}
33263326
ab = audit_log_start(audit_context(),
33273327
GFP_ATOMIC, AUDIT_SELINUX_ERR);
3328+
if (!ab)
3329+
return rc;
33283330
audit_log_format(ab, "op=setxattr invalid_context=");
33293331
audit_log_n_untrustedstring(ab, value, audit_size);
33303332
audit_log_end(ab);
@@ -6552,6 +6554,8 @@ static int selinux_setprocattr(const char *name, void *value, size_t size)
65526554
ab = audit_log_start(audit_context(),
65536555
GFP_ATOMIC,
65546556
AUDIT_SELINUX_ERR);
6557+
if (!ab)
6558+
return error;
65556559
audit_log_format(ab, "op=fscreate invalid_context=");
65566560
audit_log_n_untrustedstring(ab, value, audit_size);
65576561
audit_log_end(ab);

security/selinux/ss/services.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,8 @@ static int compute_sid_handle_invalid_context(
16731673
if (context_struct_to_string(policydb, newcontext, &n, &nlen))
16741674
goto out;
16751675
ab = audit_log_start(audit_context(), GFP_ATOMIC, AUDIT_SELINUX_ERR);
1676+
if (!ab)
1677+
goto out;
16761678
audit_log_format(ab,
16771679
"op=security_compute_sid invalid_context=");
16781680
/* no need to record the NUL with untrusted strings */

0 commit comments

Comments
 (0)