Skip to contentSkip to conversation

Potential xdr_xcode_array2 security issue (was: Re: [PATCH] RPC: Encode and decode arbitrary XDR arrays)

DISCUSSION Florian Weimer 2 participants 4 messages Jun 23, 2005 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

* 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.

#2 lore raw
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
Index: linux-2.6.5/net/sunrpc/xdr.c
===================================================================
@@ -989,8 +989,7 @@ xdr_xcode_array2(struct xdr_buf *buf, un
 			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)
+		    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);
#3 lore raw

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.

#4 lore raw

Re: Potential xdr_xcode_array2 security issue

Quoted 1 line · Florian Weimer

[...] I can't tell if you must protect against desc->elem_size beign zero.

No.

-- Andreas.