[PATCH net-2.6] L2TP: Fix potential memory corruption in pppol2tp_recvmsg()

STALE6630d

2 messages, 2 authors, 2008-06-10 · open the first message on its own page

[PATCH net-2.6] L2TP: Fix potential memory corruption in pppol2tp_recvmsg()

From: James Chapman <jchapman@katalix.com>
Date: 2008-06-10 12:35:43

This patch fixes a potential memory corruption in
pppol2tp_recvmsg(). If skb->len is bigger than the caller's buffer
length, memcpy_toiovec() will go into unintialized data on the kernel
heap, interpret it as an iovec and start modifying memory.

The fix is to change the memcpy_toiovec() call to
skb_copy_datagram_iovec() so that paged packets (rare for PPPOL2TP)
are handled properly. Also check that the caller's buffer is big
enough for the data and set the MSG_TRUNC flag if it is not so.

Reported-by: Ilja <redacted>
Signed-off-by: James Chapman <jchapman@katalix.com>

--

A candidate for -stable?

Index: net-2.6/drivers/net/pppol2tp.c
===================================================================
--- net-2.6.orig/drivers/net/pppol2tp.c
+++ net-2.6/drivers/net/pppol2tp.c
@@ -783,14 +783,18 @@ static int pppol2tp_recvmsg(struct kiocb
 	err = 0;
 	skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
 				flags & MSG_DONTWAIT, &err);
-	if (skb) {
-		err = memcpy_toiovec(msg->msg_iov, (unsigned char *) skb->data,
-				     skb->len);
-		if (err < 0)
-			goto do_skb_free;
-		err = skb->len;
-	}
-do_skb_free:
+	if (!skb)
+		goto end;
+
+	if (len > skb->len)
+		len = skb->len;
+	else if (len < skb->len)
+		msg->msg_flags |= MSG_TRUNC;
+
+	err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, len);
+	if (likely(err == 0))
+		err = len;
+
 	kfree_skb(skb);
 end:
 	return err;

Re: [PATCH net-2.6] L2TP: Fix potential memory corruption in pppol2tp_recvmsg()

From: David Miller <davem@davemloft.net>
Date: 2008-06-10 19:36:12

From: James Chapman <jchapman@katalix.com>
Date: Tue, 10 Jun 2008 13:34:24 +0100
This patch fixes a potential memory corruption in
pppol2tp_recvmsg(). If skb->len is bigger than the caller's buffer
length, memcpy_toiovec() will go into unintialized data on the kernel
heap, interpret it as an iovec and start modifying memory.

The fix is to change the memcpy_toiovec() call to
skb_copy_datagram_iovec() so that paged packets (rare for PPPOL2TP)
are handled properly. Also check that the caller's buffer is big
enough for the data and set the MSG_TRUNC flag if it is not so.

Reported-by: Ilja <redacted>
Signed-off-by: James Chapman <jchapman@katalix.com>
Applied, thanks.

Please see:

http://marc.info/?l=linux-netdev&m=121262022428660&w=2

for a description of how I would like folks to format their
commit header lines for networking changes nowadays.  I fixed
it up by hand for you this time.
A candidate for -stable?
Yes, and I've queued it up for such.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help