mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Hawkins Jiawei <yin31149@gmail.com>,
	Trond Myklebust <trond.myklebust@hammerspace.com>,
	Anna Schumaker <anna@kernel.org>
Cc: 18801353760@163.com, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org
Subject: Re: [PATCH -next 2/5] nfs: fix possible null-ptr-deref when parsing param
Date: Mon, 24 Oct 2022 06:53:46 -0400	[thread overview]
Message-ID: <627dd3b048812fe8127058a66fd5a4aafca8242a.camel@kernel.org> (raw)
In-Reply-To: <20221023163945.39920-3-yin31149@gmail.com>

On Mon, 2022-10-24 at 00:39 +0800, Hawkins Jiawei wrote:
> According to commit "vfs: parse: deal with zero length string value",
> kernel will set the param->string to null pointer in vfs_parse_fs_string()
> if fs string has zero length.
> 
> Yet the problem is that, nfs_fs_context_parse_param() will dereferences the
> param->string, without checking whether it is a null pointer, which may
> trigger a null-ptr-deref bug.
> 
> This patch solves it by adding sanity check on param->string
> in nfs_fs_context_parse_param().
> 
> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
> ---
>  fs/nfs/fs_context.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/fs/nfs/fs_context.c b/fs/nfs/fs_context.c
> index 4da701fd1424..0c330bc13ef2 100644
> --- a/fs/nfs/fs_context.c
> +++ b/fs/nfs/fs_context.c
> @@ -684,6 +684,8 @@ static int nfs_fs_context_parse_param(struct fs_context *fc,
>  			return ret;
>  		break;
>  	case Opt_vers:
> +		if (!param->string)
> +			goto out_invalid_value;
>  		trace_nfs_mount_assign(param->key, param->string);
>  		ret = nfs_parse_version_string(fc, param->string);
>  		if (ret < 0)
> @@ -696,6 +698,8 @@ static int nfs_fs_context_parse_param(struct fs_context *fc,
>  		break;
>  
>  	case Opt_proto:
> +		if (!param->string)
> +			goto out_invalid_value;
>  		trace_nfs_mount_assign(param->key, param->string);
>  		protofamily = AF_INET;
>  		switch (lookup_constant(nfs_xprt_protocol_tokens, param->string, -1)) {
> @@ -732,6 +736,8 @@ static int nfs_fs_context_parse_param(struct fs_context *fc,
>  		break;
>  
>  	case Opt_mountproto:
> +		if (!param->string)
> +			goto out_invalid_value;
>  		trace_nfs_mount_assign(param->key, param->string);
>  		mountfamily = AF_INET;
>  		switch (lookup_constant(nfs_xprt_protocol_tokens, param->string, -1)) {


Looks reasonable. I took a quick look for other fsparam_string values
that might not handle a NULL pointer correctly, but I didn't see any.

Reviewed-by: Jeff Layton <jlayton@kernel.org>

  reply	other threads:[~2022-10-24 10:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-23 16:39 [PATCH -next 0/5] fs: " Hawkins Jiawei
2022-10-23 16:39 ` [PATCH -next 1/5] smb3: " Hawkins Jiawei
2022-10-23 16:39 ` [PATCH -next 2/5] nfs: " Hawkins Jiawei
2022-10-24 10:53   ` Jeff Layton [this message]
2022-10-23 16:39 ` [PATCH -next 3/5] ceph: " Hawkins Jiawei
2022-10-24  0:38   ` Xiubo Li
2022-10-24  0:55   ` Xiubo Li
2022-10-24  2:04     ` Hawkins Jiawei
2022-10-24  2:17       ` Xiubo Li
2022-10-23 16:39 ` [PATCH -next 4/5] gfs2: " Hawkins Jiawei
2022-10-24  9:42   ` Andreas Grünbacher
2022-10-23 16:39 ` [PATCH -next 5/5] proc: " Hawkins Jiawei
2022-10-23 16:48 ` [PATCH -next 0/5] fs: " Al Viro
2022-10-24  0:42   ` Hawkins Jiawei
2022-10-24  3:34     ` Ian Kent
2022-10-31 11:28       ` Tetsuo Handa
2022-11-01  0:32         ` Ian Kent

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=627dd3b048812fe8127058a66fd5a4aafca8242a.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=18801353760@163.com \
    --cc=anna@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trond.myklebust@hammerspace.com \
    --cc=yin31149@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome