hooks: fix a missing-check bug in selinux_add_mnt_opt()
Subsystems (3)
PATCH 1/1 hooks: fix a missing-check bug in selinux_add_mnt_opt()
In selinux_add_mnt_opt(), 'val' is allcoted by kmemdup_nul(). It returns NULL when fails. So 'val' should be checked.
---
security/selinux/hooks.c +5 -2
@@ -1052,8 +1052,11 @@ static int selinux_add_mnt_opt(const char *option, const char *val, int len,if (token == Opt_error)return -EINVAL ; -if (token != Opt_seclabel) - val =kmemdup_nul (val, len,GFP_KERNEL ); +if (token != Opt_seclabel) { + val =kmemdup_nul (val, len,GFP_KERNEL ); +if (!val) +return -ENOMEM ; + } rc =selinux_add_opt (token, val, mnt_opts);if (unlikely (rc)) {kfree (val);
Quoted 4 lines · Gen Zhang
In
selinux_add_mnt_opt(), 'val' is allcoted bykmemdup_nul(). It returns NULL when fails. So 'val' should be checked.Signed-off-by Gen Zhang <[email protected]>
Please add a Fixes tag here, too:
Quoted 6 lines
---
security/selinux/hooks.c +0
-0
security/selinux/hooks.c static int selinux_add_mnt_opt(const char *option, const char *val, int len, · line 1058
Quoted 9 lines
security/selinux/hooks.c +4
-2@@ -1052,8 +1052,11 @@ static int selinux_add_mnt_opt(const char *option, const char *val, int len,if (token == Opt_error)return -EINVAL ; -if (token != Opt_seclabel) - val =kmemdup_nul (val, len,GFP_KERNEL ); +if (token != Opt_seclabel) { + val =kmemdup_nul (val, len,GFP_KERNEL ); +if (!val) +return -ENOMEM ;
There is one extra tab character in the above three lines ^^^
security/selinux/hooks.c static int selinux_add_mnt_opt(const char *option, const char *val, int len, · line 1062
Quoted 4 lines
security/selinux/hooks.c +1
-0+ } rc =selinux_add_opt (token, val, mnt_opts);if (unlikely (rc)) {kfree (val);
Thanks,
--
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.
PATCH v2 1/1 hooks: fix a missing-check bug in selinux_add_mnt_opt()
In selinux_add_mnt_opt(), 'val' is allcoted by kmemdup_nul(). It returns NULL when fails. So 'val' should be checked.
---
security/selinux/hooks.c +5 -2
@@ -1052,8 +1052,11 @@ static int selinux_add_mnt_opt(const char *option, const char *val, int len,if (token == Opt_error)return -EINVAL ; -if (token != Opt_seclabel) - val =kmemdup_nul (val, len,GFP_KERNEL ); +if (token != Opt_seclabel) { + val =kmemdup_nul (val, len,GFP_KERNEL ); +if (!val) +return -ENOMEM ; + } rc =selinux_add_opt (token, val, mnt_opts);if (unlikely (rc)) {kfree (val);
Paul Moore
maintainerQuoted 6 lines · Gen Zhang
In
selinux_add_mnt_opt(), 'val' is allcoted bykmemdup_nul(). It returns NULL when fails. So 'val' should be checked.Signed-off-by Gen Zhang <[email protected]>Fixes 757cbe597fe8 ("LSM: new method: ->sb_add_mnt_opt()")
Previous comments regarding "selinux:" instead of "hooks:" apply here as well.
Quoted 5 lines
security/selinux/hooks.c +0
-0
security/selinux/hooks.c static int selinux_add_mnt_opt(const char *option, const char *val, int len, · line 1058
Quoted 9 lines
security/selinux/hooks.c +4
-2@@ -1052,8 +1052,11 @@ static int selinux_add_mnt_opt(const char *option, const char *val, int len,if (token == Opt_error)return -EINVAL ; -if (token != Opt_seclabel) - val =kmemdup_nul (val, len,GFP_KERNEL ); +if (token != Opt_seclabel) { + val =kmemdup_nul (val, len,GFP_KERNEL ); +if (!val) +return -ENOMEM ;
It looks like this code is only ever called by NFS, which will eventually clean up mnt_opts via security_free_mnt_opts(), but since the selinux_add_opt() error handler below cleans up mnt_opts it might be safer to do the same here in case this function is called multiple times to add multiple options.
Quoted 4 lines
security/selinux/hooks.c +1
-0+ } rc =selinux_add_opt (token, val, mnt_opts);if (unlikely (rc)) {kfree (val);
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 10 lines · Paul Moore
Quoted 6 lines · Gen Zhang
In
selinux_add_mnt_opt(), 'val' is allcoted bykmemdup_nul(). It returns NULL when fails. So 'val' should be checked.Signed-off-by Gen Zhang <[email protected]>Fixes 757cbe597fe8 ("LSM: new method: ->sb_add_mnt_opt()")Previous comments regarding "selinux:" instead of "hooks:" apply here as well.
Thanks for your comments, Paul. I will make some changes.
Quoted 21 lines
Quoted 5 lines
security/selinux/hooks.c +0
-0security/selinux/hooks.c static int selinux_add_mnt_opt(const char *option, const char *val, int len, · line 1058
Quoted 9 lines
security/selinux/hooks.c +4
-2@@ -1052,8 +1052,11 @@ static int selinux_add_mnt_opt(const char *option, const char *val, int len,if (token == Opt_error)return -EINVAL ; -if (token != Opt_seclabel) - val =kmemdup_nul (val, len,GFP_KERNEL ); +if (token != Opt_seclabel) { + val =kmemdup_nul (val, len,GFP_KERNEL ); +if (!val) +return -ENOMEM ;It looks like this code is only ever called by NFS, which will eventually clean up
mnt_optsviasecurity_free_mnt_opts(), but since theselinux_add_opt()error handler below cleans upmnt_optsit might be safer to do the same here in case this function is called multiple times to add multiple options.
Quoted 8 lines
Quoted 4 lines
security/selinux/hooks.c +1
-0+ } rc =selinux_add_opt (token, val, mnt_opts);if (unlikely (rc)) {kfree (val);Signature · 2 lines
paul moore www.paul-moore.com
Thanks
Gen
Hello!
Quoted 1 line · Gen Zhang
In
selinux_add_mnt_opt(), 'val' is allcoted bykmemdup_nul(). It returns
Allocated?
Quoted 3 lines
NULL when fails. So 'val' should be checked.
Signed-off-by Gen Zhang <[email protected]>
[...]
MBR, Sergei
Quoted 7 lines · Sergei Shtylyov
Hello!
Quoted 1 line · Gen Zhang
In
selinux_add_mnt_opt(), 'val' is allcoted bykmemdup_nul(). It returnsAllocated?
Thanks for your reply, Sergei. I used 'allocated' because kmemdup_nul() does some allocation in its implementation. And its docs descrips:
"Return: newly allocated copy of @s with NUL-termination or %NULL in case of error". I think it is proper to use 'allocated' here. But it could be 'assigned', which is better, right?
Thanks
Gen
Quoted 7 lines
Quoted 4 lines
NULL when fails. So 'val' should be checked.
Signed-off-by Gen Zhang <[email protected]>[...]
MBR, Sergei
Quoted 8 lines · Gen Zhang
Quoted 5 lines · Gen Zhang
Quoted 2 lines
In
selinux_add_mnt_opt(), 'val' is allcoted bykmemdup_nul(). It returnsAllocated?
Thanks for your reply, Sergei. I used 'allocated' because
kmemdup_nul()does some allocation in its implementation. And its docs descrips:
Describes?
Quoted 3 lines
"Return: newly allocated copy of @s with NUL-termination or %NULL in case of error". I think it is proper to use 'allocated' here. But it could be 'assigned', which is better, right?
I was only trying to point out the typos in this word. :-)
Quoted 7 lines
Thanks
GenQuoted 5 lines
Quoted 4 lines
NULL when fails. So 'val' should be checked.
Signed-off-by Gen Zhang <[email protected]>[...]
MBR, Sergei
Quoted 22 lines · Sergei Shtylyov
Quoted 8 lines · Gen Zhang
Quoted 5 lines · Gen Zhang
Quoted 2 lines
In
selinux_add_mnt_opt(), 'val' is allcoted bykmemdup_nul(). It returnsAllocated?
Thanks for your reply, Sergei. I used 'allocated' because
kmemdup_nul()does some allocation in its implementation. And its docs descrips:Describes?
Quoted 3 lines
"Return: newly allocated copy of @s with NUL-termination or %NULL in case of error". I think it is proper to use 'allocated' here. But it could be 'assigned', which is better, right?
I was only trying to point out the typos in this word. :-)
Quoted 3 lines
Thanks
GenQuoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
NULL when fails. So 'val' should be checked.
Signed-off-by Gen Zhang <[email protected]>[...]
MBR, Sergei
Well, my mistake. Thanks for your comments, Sergei!
Thanks
Gen