* [PATCH] hooks: fix a missing-check bug in selinux_sb_eat_lsm_opts()
@ 2019-05-30 3:53 Gen Zhang
2019-05-30 4:39 ` William Roberts
2019-05-30 8:28 ` Ondrej Mosnacek
0 siblings, 2 replies; 7+ messages in thread
From: Gen Zhang @ 2019-05-30 3:53 UTC (permalink / raw)
To: paul, tony.luck, sds, eparis; +Cc: selinux, linux-kernel, bpf
In selinux_sb_eat_lsm_opts(), 'arg' is allocated by kmemdup_nul(). It
returns NULL when fails. So 'arg' should be checked.
Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
---
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 3ec702c..5a9e959 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -2635,6 +2635,8 @@ static int selinux_sb_eat_lsm_opts(char *options, void **mnt_opts)
*q++ = c;
}
arg = kmemdup_nul(arg, q - arg, GFP_KERNEL);
+ if (!arg)
+ return 0;
}
rc = selinux_add_opt(token, arg, mnt_opts);
if (unlikely(rc)) {
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] hooks: fix a missing-check bug in selinux_sb_eat_lsm_opts()
2019-05-30 3:53 [PATCH] hooks: fix a missing-check bug in selinux_sb_eat_lsm_opts() Gen Zhang
@ 2019-05-30 4:39 ` William Roberts
2019-05-30 7:38 ` Gen Zhang
2019-05-30 8:28 ` Ondrej Mosnacek
1 sibling, 1 reply; 7+ messages in thread
From: William Roberts @ 2019-05-30 4:39 UTC (permalink / raw)
To: Gen Zhang
Cc: Paul Moore, tony.luck, Stephen Smalley, Eric Paris, selinux,
linux-kernel, bpf
On Wed, May 29, 2019 at 8:55 PM Gen Zhang <blackgod016574@gmail.com> wrote:
>
> In selinux_sb_eat_lsm_opts(), 'arg' is allocated by kmemdup_nul(). It
> returns NULL when fails. So 'arg' should be checked.
>
> Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
> ---
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index 3ec702c..5a9e959 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -2635,6 +2635,8 @@ static int selinux_sb_eat_lsm_opts(char *options, void **mnt_opts)
> *q++ = c;
> }
> arg = kmemdup_nul(arg, q - arg, GFP_KERNEL);
> + if (!arg)
> + return 0;
The routine seems to return 0 on success, why would it return 0 on ENOMEM?
> }
> rc = selinux_add_opt(token, arg, mnt_opts);
> if (unlikely(rc)) {
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] hooks: fix a missing-check bug in selinux_sb_eat_lsm_opts()
2019-05-30 4:39 ` William Roberts
@ 2019-05-30 7:38 ` Gen Zhang
0 siblings, 0 replies; 7+ messages in thread
From: Gen Zhang @ 2019-05-30 7:38 UTC (permalink / raw)
To: William Roberts
Cc: Paul Moore, tony.luck, Stephen Smalley, Eric Paris, selinux,
linux-kernel, bpf
On Wed, May 29, 2019 at 09:39:50PM -0700, William Roberts wrote:
> On Wed, May 29, 2019 at 8:55 PM Gen Zhang <blackgod016574@gmail.com> wrote:
> >
> > In selinux_sb_eat_lsm_opts(), 'arg' is allocated by kmemdup_nul(). It
> > returns NULL when fails. So 'arg' should be checked.
> >
> > Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
> > ---
> > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> > index 3ec702c..5a9e959 100644
> > --- a/security/selinux/hooks.c
> > +++ b/security/selinux/hooks.c
> > @@ -2635,6 +2635,8 @@ static int selinux_sb_eat_lsm_opts(char *options, void **mnt_opts)
> > *q++ = c;
> > }
> > arg = kmemdup_nul(arg, q - arg, GFP_KERNEL);
> > + if (!arg)
> > + return 0;
>
> The routine seems to return 0 on success, why would it return 0 on ENOMEM?
>
Thanks for your reply, William. I re-examined the source code and didn't
figure out what the return value should be in this situation. Could it
be a -ENOMEM? Do you have any idea?
Thanks
Gen
> > }
> > rc = selinux_add_opt(token, arg, mnt_opts);
> > if (unlikely(rc)) {
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] hooks: fix a missing-check bug in selinux_sb_eat_lsm_opts()
2019-05-30 3:53 [PATCH] hooks: fix a missing-check bug in selinux_sb_eat_lsm_opts() Gen Zhang
2019-05-30 4:39 ` William Roberts
@ 2019-05-30 8:28 ` Ondrej Mosnacek
2019-05-30 8:51 ` [PATCH v2] " Gen Zhang
1 sibling, 1 reply; 7+ messages in thread
From: Ondrej Mosnacek @ 2019-05-30 8:28 UTC (permalink / raw)
To: Gen Zhang
Cc: Paul Moore, tony.luck, Stephen Smalley, Eric Paris, selinux,
Linux kernel mailing list, bpf
On Thu, May 30, 2019 at 5:53 AM Gen Zhang <blackgod016574@gmail.com> wrote:
> In selinux_sb_eat_lsm_opts(), 'arg' is allocated by kmemdup_nul(). It
> returns NULL when fails. So 'arg' should be checked.
>
> Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
Since it looks like you are going to respin this patch, please add:
Fixes: 99dbbb593fe6 ("selinux: rewrite selinux_sb_eat_lsm_opts()")
to the commit message so that there is a record of which commit
introduced the issue (then it can be picked up automatically for
backport into the relevant stable kernels).
Thanks for spotting the issue and sending the patch(es)!
> ---
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index 3ec702c..5a9e959 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -2635,6 +2635,8 @@ static int selinux_sb_eat_lsm_opts(char *options, void **mnt_opts)
> *q++ = c;
> }
> arg = kmemdup_nul(arg, q - arg, GFP_KERNEL);
> + if (!arg)
> + return 0;
> }
> rc = selinux_add_opt(token, arg, mnt_opts);
> if (unlikely(rc)) {
--
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v2] hooks: fix a missing-check bug in selinux_sb_eat_lsm_opts()
2019-05-30 8:28 ` Ondrej Mosnacek
@ 2019-05-30 8:51 ` Gen Zhang
2019-05-30 11:52 ` Ondrej Mosnacek
0 siblings, 1 reply; 7+ messages in thread
From: Gen Zhang @ 2019-05-30 8:51 UTC (permalink / raw)
To: Ondrej Mosnacek
Cc: Paul Moore, tony.luck, Stephen Smalley, Eric Paris, selinux,
Linux kernel mailing list, bpf
In selinux_sb_eat_lsm_opts(), 'arg' is allocated by kmemdup_nul(). It
returns NULL when fails. So 'arg' should be checked.
Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
Fixes: 99dbbb593fe6 ("selinux: rewrite selinux_sb_eat_lsm_opts()")
---
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 3ec702c..5a9e959 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -2635,6 +2635,8 @@ static int selinux_sb_eat_lsm_opts(char *options, void **mnt_opts)
*q++ = c;
}
arg = kmemdup_nul(arg, q - arg, GFP_KERNEL);
+ if (!arg)
+ return -ENOMEM;
}
rc = selinux_add_opt(token, arg, mnt_opts);
if (unlikely(rc)) {
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v2] hooks: fix a missing-check bug in selinux_sb_eat_lsm_opts()
2019-05-30 8:51 ` [PATCH v2] " Gen Zhang
@ 2019-05-30 11:52 ` Ondrej Mosnacek
2019-05-30 15:16 ` William Roberts
0 siblings, 1 reply; 7+ messages in thread
From: Ondrej Mosnacek @ 2019-05-30 11:52 UTC (permalink / raw)
To: Gen Zhang
Cc: Paul Moore, tony.luck, Stephen Smalley, Eric Paris, selinux,
Linux kernel mailing list, bpf
On Thu, May 30, 2019 at 10:51 AM Gen Zhang <blackgod016574@gmail.com> wrote:
> In selinux_sb_eat_lsm_opts(), 'arg' is allocated by kmemdup_nul(). It
> returns NULL when fails. So 'arg' should be checked.
>
> Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
> Fixes: 99dbbb593fe6 ("selinux: rewrite selinux_sb_eat_lsm_opts()")
> ---
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index 3ec702c..5a9e959 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -2635,6 +2635,8 @@ static int selinux_sb_eat_lsm_opts(char *options, void **mnt_opts)
> *q++ = c;
> }
> arg = kmemdup_nul(arg, q - arg, GFP_KERNEL);
> + if (!arg)
> + return -ENOMEM;
> }
> rc = selinux_add_opt(token, arg, mnt_opts);
> if (unlikely(rc)) {
Looking at the callers of security_sb_eat_lsm_opts() (which is the
function that eventually calls the selinux_sb_eat_lsm_opts() hook),
-ENOMEM should be appropriate here.
Reviewed-by: Ondrej Mosnacek <omosnace@redhat.com>
--
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v2] hooks: fix a missing-check bug in selinux_sb_eat_lsm_opts()
2019-05-30 11:52 ` Ondrej Mosnacek
@ 2019-05-30 15:16 ` William Roberts
0 siblings, 0 replies; 7+ messages in thread
From: William Roberts @ 2019-05-30 15:16 UTC (permalink / raw)
To: Ondrej Mosnacek
Cc: Gen Zhang, Paul Moore, tony.luck, Stephen Smalley, Eric Paris,
selinux, Linux kernel mailing list, bpf
On Thu, May 30, 2019 at 4:52 AM Ondrej Mosnacek <omosnace@redhat.com> wrote:
>
> On Thu, May 30, 2019 at 10:51 AM Gen Zhang <blackgod016574@gmail.com> wrote:
> > In selinux_sb_eat_lsm_opts(), 'arg' is allocated by kmemdup_nul(). It
> > returns NULL when fails. So 'arg' should be checked.
> >
> > Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
> > Fixes: 99dbbb593fe6 ("selinux: rewrite selinux_sb_eat_lsm_opts()")
> > ---
> > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> > index 3ec702c..5a9e959 100644
> > --- a/security/selinux/hooks.c
> > +++ b/security/selinux/hooks.c
> > @@ -2635,6 +2635,8 @@ static int selinux_sb_eat_lsm_opts(char *options, void **mnt_opts)
> > *q++ = c;
> > }
> > arg = kmemdup_nul(arg, q - arg, GFP_KERNEL);
> > + if (!arg)
> > + return -ENOMEM;
Yeah -ENOMEM is correct here. Ack by me.
> > }
> > rc = selinux_add_opt(token, arg, mnt_opts);
> > if (unlikely(rc)) {
>
> Looking at the callers of security_sb_eat_lsm_opts() (which is the
> function that eventually calls the selinux_sb_eat_lsm_opts() hook),
> -ENOMEM should be appropriate here.
>
> Reviewed-by: Ondrej Mosnacek <omosnace@redhat.com>
>
> --
> Ondrej Mosnacek <omosnace at redhat dot com>
> Software Engineer, Security Technologies
> Red Hat, Inc.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-05-30 15:16 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-30 3:53 [PATCH] hooks: fix a missing-check bug in selinux_sb_eat_lsm_opts() Gen Zhang
2019-05-30 4:39 ` William Roberts
2019-05-30 7:38 ` Gen Zhang
2019-05-30 8:28 ` Ondrej Mosnacek
2019-05-30 8:51 ` [PATCH v2] " Gen Zhang
2019-05-30 11:52 ` Ondrej Mosnacek
2019-05-30 15:16 ` William Roberts
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®