* [PATCH] lsm_audit,selinux: add exception handling for possible NULL audit buffers
@ 2021-07-12 23:48 Austin Kim
2021-07-13 2:49 ` Paul Moore
0 siblings, 1 reply; 3+ messages in thread
From: Austin Kim @ 2021-07-12 23:48 UTC (permalink / raw)
To: paul, stephen.smalley.work, eparis, omosnace
Cc: selinux, linux-kernel, austin.kim, kernel-team, austindh.kim
From: Austin Kim <austin.kim@lge.com>
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.
Signed-off-by: Austin Kim <austin.kim@lge.com>
---
security/selinux/hooks.c | 4 ++++
security/selinux/ss/services.c | 2 ++
2 files changed, 6 insertions(+)
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index b0032c42333e..9e84e6635f2f 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -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);
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index d84c77f370dc..e5f1b2757a83 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] lsm_audit,selinux: add exception handling for possible NULL audit buffers
2021-07-12 23:48 [PATCH] lsm_audit,selinux: add exception handling for possible NULL audit buffers Austin Kim
@ 2021-07-13 2:49 ` Paul Moore
2021-07-13 3:40 ` Austin Kim
0 siblings, 1 reply; 3+ messages in thread
From: Paul Moore @ 2021-07-13 2:49 UTC (permalink / raw)
To: Austin Kim
Cc: Stephen Smalley, Eric Paris, Ondrej Mosnacek, selinux,
linux-kernel, austin.kim, kernel-team
On Mon, Jul 12, 2021 at 7:48 PM Austin Kim <austindh.kim@gmail.com> wrote:
> From: Austin Kim <austin.kim@lge.com>
>
> 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.
> Signed-off-by: Austin Kim <austin.kim@lge.com>
> ---
> security/selinux/hooks.c | 4 ++++
> security/selinux/ss/services.c | 2 ++
> 2 files changed, 6 insertions(+)
>
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index b0032c42333e..9e84e6635f2f 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -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);
> diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
> index d84c77f370dc..e5f1b2757a83 100644
> --- a/security/selinux/ss/services.c
> +++ b/security/selinux/ss/services.c
> @@ -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
--
paul moore
www.paul-moore.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] lsm_audit,selinux: add exception handling for possible NULL audit buffers
2021-07-13 2:49 ` Paul Moore
@ 2021-07-13 3:40 ` Austin Kim
0 siblings, 0 replies; 3+ messages in thread
From: Austin Kim @ 2021-07-13 3:40 UTC (permalink / raw)
To: Paul Moore
Cc: Stephen Smalley, Eric Paris, Ondrej Mosnacek, selinux,
Linux Kernel Mailing List, 김동현,
kernel-team
2021년 7월 13일 (화) 오전 11:49, Paul Moore <paul@paul-moore.com>님이 작성:
>
> On Mon, Jul 12, 2021 at 7:48 PM Austin Kim <austindh.kim@gmail.com> wrote:
> > From: Austin Kim <austin.kim@lge.com>
> >
> > 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.
Thanks for valuable feedback.
Let me resend the patch with revised 'commit description',
as you recommended.
> 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.
>
> > Signed-off-by: Austin Kim <austin.kim@lge.com>
> > ---
> > security/selinux/hooks.c | 4 ++++
> > security/selinux/ss/services.c | 2 ++
> > 2 files changed, 6 insertions(+)
> >
> > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> > index b0032c42333e..9e84e6635f2f 100644
> > --- a/security/selinux/hooks.c
> > +++ b/security/selinux/hooks.c
> > @@ -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);
> > diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
> > index d84c77f370dc..e5f1b2757a83 100644
> > --- a/security/selinux/ss/services.c
> > +++ b/security/selinux/ss/services.c
> > @@ -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
>
> --
> paul moore
> www.paul-moore.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-07-13 3:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-12 23:48 [PATCH] lsm_audit,selinux: add exception handling for possible NULL audit buffers Austin Kim
2021-07-13 2:49 ` Paul Moore
2021-07-13 3:40 ` Austin Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).