All of lore.kernel.org
 help / color / mirror / Atom feed
From: " Zhongjun Tan" <hbut_tan@163.com>
To: casey@schaufler-ca.com, jmorris@namei.org, serge@hallyn.com
Cc: linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Zhongjun Tan <tanzhongjun@yulong.com>
Subject: [PATCH v3] lsm:fix a missing-check bug in smack_sb_eat_lsm_opts()
Date: Mon, 19 Apr 2021 10:55:17 +0800	[thread overview]
Message-ID: <20210419025517.551-1-hbut_tan@163.com> (raw)

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

diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 223a6da..020929f 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -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)
-- 
1.9.1



                 reply	other threads:[~2021-04-19  2:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210419025517.551-1-hbut_tan@163.com \
    --to=hbut_tan@163.com \
    --cc=casey@schaufler-ca.com \
    --cc=jmorris@namei.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=serge@hallyn.com \
    --cc=tanzhongjun@yulong.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.