Potential xdr_xcode_array2 security issue (was: Re: [PATCH] RPC: Encode and decode arbitrary XDR arrays)
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): [email protected]
* Linux Kernel Mailing List:
Quoted 7 lines
(quoted diff) +7
-0+xdr_xcode_array2(struct xdr_buf *buf, unsigned int base, + struct xdr_array2_desc *desc, int encode) +{ + char *elem = NULL, *c; + unsigned int copied = 0, todo, avail_here; + struct page **ppages = NULL; + int err;
Review
Quoted 10 lines
(quoted diff) +10
-0+ + if (encode) { + if (xdr_encode_word(buf, base, desc->array_len) != 0) + return -EINVAL; + } else { + if (xdr_decode_word(buf, base, &desc->array_len) != 0 || + (unsigned long) base + 4 + desc->array_len * + desc->elem_size > buf->len) + return -EINVAL; + }
This looks suspiciously like CVE-2002-0391.
Quoted 1 line · Florian Weimer
This looks suspiciously like CVE-2002-0391.
Thanks, Florian. How about the attached patch?
Cheers,
Andreas.
From: Andreas Gruenbacher <[email protected]>
Subject: Overflow in xdr input validation
The bounds check in xdr_xcode_array2 can overflow. Reported by Florian Weimer <[email protected]>.
net/sunrpc/xdr.c +3 -4
@@ -989,8 +989,7 @@ xdr_xcode_array2(struct xdr_buf *buf, unreturn -EINVAL ; }else {if (xdr_decode_word (buf, base, &desc->array_len) !=0 || - (unsigned long ) base +4 + desc->array_len * - desc->elem_size > buf->len) + desc->array_len > (buf->len - base -4 ) / desc->elem_size)return -EINVAL ; } base +=4 ;
@@ -1158,8 +1157,8 @@ int xdr_encode_array2(struct xdr_buf *buf, unsigned int base, struct xdr_array2_desc *desc) { - if ((unsigned long) base + 4 + desc->array_len * desc->elem_size > - buf->head->iov_len + buf->page_len + buf->tail->iov_len) + if (buf->head->iov_len + buf->page_len + buf->tail->iov_len - + base < desc->array_len * desc->elem_size + 4) return -EINVAL;return xdr_xcode_array2 (buf, base, desc,1 );
Re: Potential xdr_xcode_array2 security issue
* Andreas Gruenbacher:
Quoted 4 lines · Florian Weimer
Quoted 1 line
This looks suspiciously like CVE-2002-0391.
Thanks, Florian. How about the attached patch?
I don't know the code, so I can't tell if you must protect against desc->elem_size beign zero. I also don't understand the second hunk.
Re: Potential xdr_xcode_array2 security issue
Quoted 1 line · Florian Weimer
[...] I can't tell if you must protect against
desc->elem_sizebeign zero.
No.
-- Andreas.