* [PATCH -next 2/5] nfs: fix possible null-ptr-deref when parsing param
[not found] <20221023163945.39920-1-yin31149@gmail.com>
@ 2022-10-23 16:39 ` Hawkins Jiawei
2022-10-24 10:53 ` Jeff Layton
0 siblings, 1 reply; 2+ messages in thread
From: Hawkins Jiawei @ 2022-10-23 16:39 UTC (permalink / raw)
To: yin31149, Trond Myklebust, Anna Schumaker
Cc: 18801353760, linux-kernel, linux-fsdevel, linux-nfs
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)) {
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH -next 2/5] nfs: fix possible null-ptr-deref when parsing param
2022-10-23 16:39 ` [PATCH -next 2/5] nfs: fix possible null-ptr-deref when parsing param Hawkins Jiawei
@ 2022-10-24 10:53 ` Jeff Layton
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Layton @ 2022-10-24 10:53 UTC (permalink / raw)
To: Hawkins Jiawei, Trond Myklebust, Anna Schumaker
Cc: 18801353760, linux-kernel, linux-fsdevel, linux-nfs
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>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-24 10:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20221023163945.39920-1-yin31149@gmail.com>
2022-10-23 16:39 ` [PATCH -next 2/5] nfs: fix possible null-ptr-deref when parsing param Hawkins Jiawei
2022-10-24 10:53 ` Jeff Layton
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).