[-next] smack: fix a missing-check bug in smack_sb_eat_lsm_opts()
diff mbox series

Message ID 20200401071055.8265-1-chenzhou10@huawei.com
State New
Headers show
Series
  • [-next] smack: fix a missing-check bug in smack_sb_eat_lsm_opts()
Related show

Commit Message

chenzhou April 1, 2020, 7:10 a.m. UTC
In smack_sb_eat_lsm_opts(), 'arg' is allocated by kmemdup_nul().
It returns NULL when fails, add check for it.

Signed-off-by: Chen Zhou <chenzhou10@huawei.com>
---
 security/smack/smack_lsm.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Tetsuo Handa April 1, 2020, 12:39 p.m. UTC | #1
On 2020/04/01 16:10, Chen Zhou wrote:
> In smack_sb_eat_lsm_opts(), 'arg' is allocated by kmemdup_nul().
> It returns NULL when fails, add check for it.

Thanks. But this check is not needed, for smack_add_opt() returns NULL if arg == NULL.

Patch
diff mbox series

diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 2862fc3..9ec30f3 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -731,6 +731,8 @@  static int smack_sb_eat_lsm_opts(char *options, void **mnt_opts)
 		token = match_opt_prefix(from, len, &arg);
 		if (token != Opt_error) {
 			arg = kmemdup_nul(arg, from + len - arg, GFP_KERNEL);
+			if (!arg)
+				return -ENOMEM;
 			rc = smack_add_opt(token, arg, mnt_opts);
 			if (unlikely(rc)) {
 				kfree(arg);