[PATCH] af_rose/x25: Sanity check the maximum user frame size

Previous thread: [PATCH] appletalk: this warning can go I think by Alan Cox on Thursday, March 26, 2009 - 1:49 pm. (2 messages)

Next thread: [patch] xfrm: spin_lock() should be spin_unlock() in xfrm_state.c by Chuck Ebbert on Thursday, March 26, 2009 - 3:58 pm. (4 messages)
From: Alan Cox
Date: Thursday, March 26, 2009 - 2:58 pm

Otherwise we can wrap the sizes and end up sending garbage.

Closes #10423

Signed-off-by: Alan Cox <alan@lxorguk.ukuu.org.uk>
---

 net/netrom/af_netrom.c |    6 +++++-
 net/rose/af_rose.c     |    4 ++++
 net/x25/af_x25.c       |    6 ++++++
 3 files changed, 15 insertions(+), 1 deletions(-)


diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
index e9c05b8..29953b0 100644
--- a/net/netrom/af_netrom.c
+++ b/net/netrom/af_netrom.c
@@ -1082,7 +1082,11 @@ static int nr_sendmsg(struct kiocb *iocb, struct socket *sock,
 
 	SOCK_DEBUG(sk, "NET/ROM: sendto: Addresses built.\n");
 
-	/* Build a packet */
+	/* Build a packet - the conventional user limit is 236 bytes. We can
+	   do ludicrously large NetROM frames but must not overflow */
+	if (len > 65536)
+		return -EMSGSIZE;
+	
 	SOCK_DEBUG(sk, "NET/ROM: sendto: building packet.\n");
 	size = len + NR_NETWORK_LEN + NR_TRANSPORT_LEN;
 
diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c
index 0139264..5e75bbf 100644
--- a/net/rose/af_rose.c
+++ b/net/rose/af_rose.c
@@ -1124,6 +1124,10 @@ static int rose_sendmsg(struct kiocb *iocb, struct socket *sock,
 
 	/* Build a packet */
 	SOCK_DEBUG(sk, "ROSE: sendto: building packet.\n");
+	/* Sanity check the packet size */
+	if (len > 65535)
+		return -EMSGSIZE;
+
 	size = len + AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN;
 
 	if ((skb = sock_alloc_send_skb(sk, size, msg->msg_flags & MSG_DONTWAIT, &err)) == NULL)
diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
index 9fc5b02..88d80f5 100644
--- a/net/x25/af_x25.c
+++ b/net/x25/af_x25.c
@@ -1037,6 +1037,12 @@ static int x25_sendmsg(struct kiocb *iocb, struct socket *sock,
 		sx25.sx25_addr   = x25->dest_addr;
 	}
 
+	/* Sanity check the packet size */
+	if (len > 65535) {
+		rc = -EMSGSIZE;
+		goto out;
+	}
+
 	SOCK_DEBUG(sk, "x25_sendmsg: sendto: Addresses built.\n");
 
 	/* Build a packet */

--

From: David Miller
Date: Friday, March 27, 2009 - 12:29 am

From: Alan Cox <alan@lxorguk.ukuu.org.uk>

   ^^^^^^^^^^^^^

please fix the tab monster :-) Or, alternatively, check the patch
either with GIT's automatic checks (or using checkpatch.pl if you
haven't eaten recently)

--

Previous thread: [PATCH] appletalk: this warning can go I think by Alan Cox on Thursday, March 26, 2009 - 1:49 pm. (2 messages)

Next thread: [patch] xfrm: spin_lock() should be spin_unlock() in xfrm_state.c by Chuck Ebbert on Thursday, March 26, 2009 - 3:58 pm. (4 messages)