Skip to content

Commit 5559405

Browse files
JiaweiHawkTrond Myklebust
authored andcommitted
nfs: fix possible null-ptr-deref when parsing param
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 <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent d564d2c commit 5559405

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

fs/nfs/fs_context.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,8 @@ static int nfs_fs_context_parse_param(struct fs_context *fc,
684684
return ret;
685685
break;
686686
case Opt_vers:
687+
if (!param->string)
688+
goto out_invalid_value;
687689
trace_nfs_mount_assign(param->key, param->string);
688690
ret = nfs_parse_version_string(fc, param->string);
689691
if (ret < 0)
@@ -696,6 +698,8 @@ static int nfs_fs_context_parse_param(struct fs_context *fc,
696698
break;
697699

698700
case Opt_proto:
701+
if (!param->string)
702+
goto out_invalid_value;
699703
trace_nfs_mount_assign(param->key, param->string);
700704
protofamily = AF_INET;
701705
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,
732736
break;
733737

734738
case Opt_mountproto:
739+
if (!param->string)
740+
goto out_invalid_value;
735741
trace_nfs_mount_assign(param->key, param->string);
736742
mountfamily = AF_INET;
737743
switch (lookup_constant(nfs_xprt_protocol_tokens, param->string, -1)) {

0 commit comments

Comments
 (0)