lsm_audit,selinux: add exception handling for possible NULL audit buffers
PATCH 1/1 lsm_audit,selinux: add exception handling for possible NULL audit buffers
From: Austin Kim <[email protected]>
It is possible for audit_log_start() to return NULL on error. 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
@@ -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
@@ -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
Paul Moore
maintainerQuoted 5 lines · Austin Kim
From: Austin Kim <[email protected]>
It is possible for
audit_log_start()to return NULL on error. So add exception handling for possible NULL audit buffers where return value can be handled from callers.
Hi.
The patch looks fine to me, but I think the description doesn't tell the full story and I'm worried that people might misunderstand why this patch is worthwhile. I would suggest you revise the commit description to explain that in these cases it is safe to return early when audit_log_start() returns NULL because the only non-cleanup processing left in these functions is to generate an audit record. Returning early in these cases is a performance optimization and not a correctness issue; the audit_log_*() functions can support being passed a NULL audit_buffer argument.
Quoted 43 lines
Signed-off-by Austin Kim <[email protected]>--- security/selinux/hooks.c | 4 ++++ security/selinux/ss/services.c | 2 ++ 2 files changed, 6 insertions(+)security/selinux/hooks.c +4
-0@@ -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
-1@@ -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 */ --2.20.1
Signature · 2 lines
paul moore www.paul-moore.com
2021년 7월 13일 (화) 오전 11:49, Paul Moore <[email protected]>님이 작성:
Quoted 8 lines · Austin Kim
Quoted 5 lines
From: Austin Kim <[email protected]>
It is possible for
audit_log_start()to return NULL on error. So add exception handling for possible NULL audit buffers where return value can be handled from callers.
Quoted 8 lines
Hi.
The patch looks fine to me, but I think the description doesn't tell the full story and I'm worried that people might misunderstand why this patch is worthwhile. I would suggest you revise the commit description to explain that in these cases it is safe to return early when
audit_log_start()returns NULL because the only non-cleanup processing left in these functions is to generate an audit record.
Thanks for valuable feedback.
Let me resend the patch with revised 'commit description', as you recommended.
Quoted 51 lines
Returning early in these cases is a performance optimization and not a correctness issue; the audit_log_*() functions can support being passed a NULL
audit_bufferargument.Quoted 42 lines
Signed-off-by Austin Kim <[email protected]>--- security/selinux/hooks.c | 4 ++++ security/selinux/ss/services.c | 2 ++ 2 files changed, 6 insertions(+)security/selinux/hooks.c +4
-0@@ -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
-1@@ -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 */ --Quoted 1 line
2.20.1
--
paul moore
www.paul-moore.com