nfs: fix possible null-ptr-deref when parsing param
authorHawkins Jiawei <yin31149@gmail.com>
Sun, 23 Oct 2022 16:39:45 +0000 (00:39 +0800)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Tue, 6 Dec 2022 15:43:24 +0000 (10:43 -0500)
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>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/fs_context.c

index 09833ec102fca9a91754f47555aa2c68cbd9ff38..9bcd53d5c7d468d7e5eadf39c1fcf439be439be8 100644 (file)
@@ -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)) {