Skip to content

Commit 6bf97c0

Browse files
Dominique Martinetgregkh
authored andcommitted
9p/net: put a lower bound on msize
commit 574d356 upstream. If the requested msize is too small (either from command line argument or from the server version reply), we won't get any work done. If it's *really* too small, nothing will work, and this got caught by syzbot recently (on a new kmem_cache_create_usercopy() call) Just set a minimum msize to 4k in both code paths, until someone complains they have a use-case for a smaller msize. We need to check in both mount option and server reply individually because the msize for the first version request would be unchecked with just a global check on clnt->msize. Link: http://lkml.kernel.org/r/1541407968-31350-1-git-send-email-asmadeus@codewreck.org Reported-by: syzbot+0c1d61e4db7db94102ca@syzkaller.appspotmail.com Signed-off-by: Dominique Martinet <dominique.martinet@cea.fr> Cc: Eric Van Hensbergen <ericvh@gmail.com> Cc: Latchesar Ionkov <lucho@ionkov.net> Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent af7cc8e commit 6bf97c0

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

net/9p/client.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ static int parse_opts(char *opts, struct p9_client *clnt)
181181
ret = r;
182182
continue;
183183
}
184+
if (option < 4096) {
185+
p9_debug(P9_DEBUG_ERROR,
186+
"msize should be at least 4k\n");
187+
ret = -EINVAL;
188+
continue;
189+
}
184190
clnt->msize = option;
185191
break;
186192
case Opt_trans:
@@ -993,10 +999,18 @@ static int p9_client_version(struct p9_client *c)
993999
else if (!strncmp(version, "9P2000", 6))
9941000
c->proto_version = p9_proto_legacy;
9951001
else {
1002+
p9_debug(P9_DEBUG_ERROR,
1003+
"server returned an unknown version: %s\n", version);
9961004
err = -EREMOTEIO;
9971005
goto error;
9981006
}
9991007

1008+
if (msize < 4096) {
1009+
p9_debug(P9_DEBUG_ERROR,
1010+
"server returned a msize < 4096: %d\n", msize);
1011+
err = -EREMOTEIO;
1012+
goto error;
1013+
}
10001014
if (msize < c->msize)
10011015
c->msize = msize;
10021016

@@ -1055,6 +1069,13 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
10551069
if (clnt->msize > clnt->trans_mod->maxsize)
10561070
clnt->msize = clnt->trans_mod->maxsize;
10571071

1072+
if (clnt->msize < 4096) {
1073+
p9_debug(P9_DEBUG_ERROR,
1074+
"Please specify a msize of at least 4k\n");
1075+
err = -EINVAL;
1076+
goto free_client;
1077+
}
1078+
10581079
err = p9_client_version(clnt);
10591080
if (err)
10601081
goto close_trans;

0 commit comments

Comments
 (0)