Skip to contentSkip to conversation

lsm:fix a missing-check bug in smack_sb_eat_lsm_opts()

PATCH New Zhongjun Tan 1 participant 1 message Apr 19, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 lsm:fix a missing-check bug in smack_sb_eat_lsm_opts()

From: Zhongjun Tan <[email protected]>

In smack_sb_eat_lsm_opts(), 'arg' is allocated by kmemdup_nul(). It returns NULL when fails. So 'arg' should be checked. And 'mnt_opts' should be freed when error.

---
changes in v1:
update the commit information.
changes in v2:
fix brace error
changes in v3:
As viro said, just four codes and no other changes are needed.

security/smack/smack_lsm.c | 5 ++++-

 1 file changed, 4 insertions(+), 1 deletion(-)
security/smack/smack_lsm.c +4 -1
index 223a6da..020929f 100644
@@ -710,7 +710,10 @@ 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);
-			rc = smack_add_opt(token, arg, mnt_opts);
+			if (arg)
+				rc = smack_add_opt(token, arg, mnt_opts);
+			else
+				rc = -ENOMEM;
 			if (unlikely(rc)) {
 				kfree(arg);
 				if (*mnt_opts)
Signature · 1 line
1.9.1