diff options
author | Tomas Bortoli <tomasbortoli@gmail.com> | 2018-07-23 17:44:04 +0200 |
---|---|---|
committer | Dominique Martinet <dominique.martinet@cea.fr> | 2018-08-13 09:34:58 +0900 |
commit | f984579a01d85166ee7380204a96d978a67687a1 (patch) | |
tree | 6921952e63cd2ec0cb11625de49fb4395e0d4ce4 /net/9p/client.c | |
parent | 9f476d7c540cb57556d3cc7e78704e6cd5100f5f (diff) | |
download | linux-stable-f984579a01d85166ee7380204a96d978a67687a1.tar.gz linux-stable-f984579a01d85166ee7380204a96d978a67687a1.tar.bz2 linux-stable-f984579a01d85166ee7380204a96d978a67687a1.zip |
9p: validate PDU length
This commit adds length check for the PDU size.
The size contained in the header has to match the actual size,
except for TCP (trans_fd.c) where actual length is not known ahead
and the header's length will be checked only against the validity
range.
Link: http://lkml.kernel.org/r/20180723154404.2406-1-tomasbortoli@gmail.com
Signed-off-by: Tomas Bortoli <tomasbortoli@gmail.com>
Reported-by: syzbot+65c6b72f284a39d416b4@syzkaller.appspotmail.com
To: Eric Van Hensbergen <ericvh@gmail.com>
To: Ron Minnich <rminnich@sandia.gov>
To: Latchesar Ionkov <lucho@ionkov.net>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Dominique Martinet <dominique.martinet@cea.fr>
Diffstat (limited to 'net/9p/client.c')
-rw-r--r-- | net/9p/client.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/net/9p/client.c b/net/9p/client.c index 33717b1b84d8..20088aa06343 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -469,20 +469,11 @@ p9_parse_header(struct p9_fcall *pdu, int32_t *size, int8_t *type, int16_t *tag, int err; pdu->offset = 0; - if (pdu->size == 0) - pdu->size = 7; err = p9pdu_readf(pdu, 0, "dbw", &r_size, &r_type, &r_tag); if (err) goto rewind_and_exit; - pdu->size = r_size; - pdu->id = r_type; - pdu->tag = r_tag; - - p9_debug(P9_DEBUG_9P, "<<< size=%d type: %d tag: %d\n", - pdu->size, pdu->id, pdu->tag); - if (type) *type = r_type; if (tag) @@ -490,6 +481,16 @@ p9_parse_header(struct p9_fcall *pdu, int32_t *size, int8_t *type, int16_t *tag, if (size) *size = r_size; + if (pdu->size != r_size || r_size < 7) { + err = -EINVAL; + goto rewind_and_exit; + } + + pdu->id = r_type; + pdu->tag = r_tag; + + p9_debug(P9_DEBUG_9P, "<<< size=%d type: %d tag: %d\n", + pdu->size, pdu->id, pdu->tag); rewind_and_exit: if (rewind) @@ -516,6 +517,12 @@ static int p9_check_errors(struct p9_client *c, struct p9_req_t *req) int ecode; err = p9_parse_header(req->rc, NULL, &type, NULL, 0); + if (req->rc->size >= c->msize) { + p9_debug(P9_DEBUG_ERROR, + "requested packet size too big: %d\n", + req->rc->size); + return -EIO; + } /* * dump the response from server * This should be after check errors which poplulate pdu_fcall. |