linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lsm:fix a missing-check bug in smack_sb_eat_lsm_opts()
@ 2021-04-16  9:53  Zhongjun Tan
  2021-04-16 13:36 ` Al Viro
  0 siblings, 1 reply; 3+ messages in thread
From:  Zhongjun Tan @ 2021-04-16  9:53 UTC (permalink / raw)
  To: casey, jmorris, serge; +Cc: linux-security-module, linux-kernel, Zhongjun Tan

From: Zhongjun Tan <tanzhongjun@yulong.com>

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.

Signed-off-by: Zhongjun Tan <tanzhongjun@yulong.com>
---
 security/smack/smack_lsm.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 223a6da..0d5439f 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -696,10 +696,11 @@ static int smack_sb_eat_lsm_opts(char *options, void **mnt_opts)
 {
 	char *from = options, *to = options;
 	bool first = true;
+	int rc;
 
 	while (1) {
 		char *next = strchr(from, ',');
-		int token, len, rc;
+		int token, len;
 		char *arg = NULL;
 
 		if (next)
@@ -710,13 +711,14 @@ 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) {
+				rc = -ENOMEM;
+				goto free_mnt_opts;
 			rc = smack_add_opt(token, arg, mnt_opts);
+			}
 			if (unlikely(rc)) {
 				kfree(arg);
-				if (*mnt_opts)
-					smack_free_mnt_opts(*mnt_opts);
-				*mnt_opts = NULL;
-				return rc;
+				goto free_mnt_opts;
 			}
 		} else {
 			if (!first) {	// copy with preceding comma
@@ -734,6 +736,13 @@ static int smack_sb_eat_lsm_opts(char *options, void **mnt_opts)
 	}
 	*to = '\0';
 	return 0;
+
+free_mnt_opts:
+	if (*mnt_opts) {
+		smack_free_mnt_opts(*mnt_opts);
+		*mnt_opts = NULL;
+	}
+	return rc;
 }
 
 /**
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] lsm:fix a missing-check bug in smack_sb_eat_lsm_opts()
  2021-04-16  9:53 [PATCH] lsm:fix a missing-check bug in smack_sb_eat_lsm_opts()  Zhongjun Tan
@ 2021-04-16 13:36 ` Al Viro
  2021-04-19  2:58   ` Zhongjun Tan
  0 siblings, 1 reply; 3+ messages in thread
From: Al Viro @ 2021-04-16 13:36 UTC (permalink / raw)
  To:  Zhongjun Tan
  Cc: casey, jmorris, serge, linux-security-module, linux-kernel, Zhongjun Tan

On Fri, Apr 16, 2021 at 05:53:03PM +0800,  Zhongjun Tan wrote:

> @@ -710,13 +711,14 @@ 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) {
> +				rc = -ENOMEM;
> +				goto free_mnt_opts;
>  			rc = smack_add_opt(token, arg, mnt_opts);

			if (arg)
	  			rc = smack_add_opt(token, arg, mnt_opts);
			else
				rc = -ENOMEM;

and no other changes are needed anywhere...

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] lsm:fix a missing-check bug in smack_sb_eat_lsm_opts()
  2021-04-16 13:36 ` Al Viro
@ 2021-04-19  2:58   ` Zhongjun Tan
  0 siblings, 0 replies; 3+ messages in thread
From: Zhongjun Tan @ 2021-04-19  2:58 UTC (permalink / raw)
  To: Al Viro
  Cc: casey, jmorris, serge, linux-security-module, linux-kernel, Zhongjun Tan

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=GB18030, Size: 719 bytes --]

On Fri, 16 Apr 2021 13:36:01 +0000
Al Viro <viro@zeniv.linux.org.uk> wrote:

> On Fri, Apr 16, 2021 at 05:53:03PM +0800, 0„2Zhongjun Tan wrote:
> 
> > @@ -710,13 +711,14 @@ 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) {
> > +				rc = -ENOMEM;
> > +				goto free_mnt_opts;
> >  			rc = smack_add_opt(token, arg, mnt_opts);  
> 
> 			if (arg)
> 	  			rc = smack_add_opt(token, arg,
> mnt_opts); else
> 				rc = -ENOMEM;
> 
> and no other changes are needed anywhere...

update patch v3 , just four codes and no other changes are needed. 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-19  2:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-16  9:53 [PATCH] lsm:fix a missing-check bug in smack_sb_eat_lsm_opts()  Zhongjun Tan
2021-04-16 13:36 ` Al Viro
2021-04-19  2:58   ` Zhongjun Tan

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).