Skip to contentSkip to conversation

lsm_audit,selinux: return early for possible NULL audit buffers

PATCH Applied Austin Kim 2 participants 3 messages Jul 14, 2021 SELinux security module

lore
Share & tools
lore

Austin Kim

author
#0 lore raw

PATCH v2 1/1 lsm_audit,selinux: return early for possible NULL audit buffers

From: Austin Kim <[email protected]>

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.

---
 security/selinux/hooks.c       | 4 ++++
 security/selinux/ss/services.c | 2 ++
 2 files changed, 6 insertions(+)
security/selinux/hooks.c +4 -0
index b0032c42333e..9e84e6635f2f 100644
@@ -3325,6 +3325,8 @@ static int selinux_inode_setxattr(struct user_namespace *mnt_userns,
 			}
 			ab = audit_log_start(audit_context(),
 					     GFP_ATOMIC, AUDIT_SELINUX_ERR);
+			if (!ab)
+				return rc;
 			audit_log_format(ab, "op=setxattr invalid_context=");
 			audit_log_n_untrustedstring(ab, value, audit_size);
 			audit_log_end(ab);
@@ -6552,6 +6554,8 @@ static int selinux_setprocattr(const char *name, void *value, size_t size)
 				ab = audit_log_start(audit_context(),
 						     GFP_ATOMIC,
 						     AUDIT_SELINUX_ERR);
+				if (!ab)
+					return error;
 				audit_log_format(ab, "op=fscreate invalid_context=");
 				audit_log_n_untrustedstring(ab, value, audit_size);
 				audit_log_end(ab);
security/selinux/ss/services.c +2 -0
index d84c77f370dc..e5f1b2757a83 100644
@@ -1673,6 +1673,8 @@ static int compute_sid_handle_invalid_context(
 	if (context_struct_to_string(policydb, newcontext, &n, &nlen))
 		goto out;
 	ab = audit_log_start(audit_context(), GFP_ATOMIC, AUDIT_SELINUX_ERR);
+	if (!ab)
+		goto out;
 	audit_log_format(ab,
 			 "op=security_compute_sid invalid_context=");
 	/* no need to record the NUL with untrusted strings */
Signature · 1 line
2.20.1
maintainer Applied
#1 lore raw
Quoted 17 lines · Austin Kim

From: Austin Kim <[email protected]>

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.

Quoted 8 lines

So add exception handling for possible NULL audit buffers where return value can be handled from callers.

---
 security/selinux/hooks.c       | 4 ++++
 security/selinux/ss/services.c | 2 ++
 2 files changed, 6 insertions(+)

Merged into selinux/next, thank you!

Signature · 2 lines
paul moore
www.paul-moore.com
author
#2 lore raw

2021년 7월 15일 (목) 오전 4:26, Paul Moore <[email protected]>님이 작성:

Quoted 22 lines · Austin Kim
Quoted 20 lines

From: Austin Kim <[email protected]>

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.

Quoted 7 lines
Quoted 5 lines
---
 security/selinux/hooks.c       | 4 ++++
 security/selinux/ss/services.c | 2 ++
 2 files changed, 6 insertions(+)

Merged into selinux/next, thank you!

Great, thanks for review and feedback.

Thanks,
Austin Kim

Quoted 4 lines

--
paul moore
www.paul-moore.com