Skip to contentSkip to conversation

llc: dont trust payload size on test cmd

PATCH In review Jim Westfall 3 participants 3 messages Feb 25, 2008 – Feb 27, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 llc: dont trust payload size on test cmd

Hi

In testing its not safe to trust the payload length we are given in a received llc test command header. Instead we should calculate this ourselves or run the risk of an skb_over_panic() if the received length in the header is > then the actual payload size.

include/net/llc_pdu.h +1 -1
diff -urp linux-2.6.24.2.org/include/net/llc_pdu.h linux-2.6.24.2/include/net/llc_pdu.h
@@ -348,7 +348,7 @@ static inline void llc_pdu_init_as_test_
 		struct llc_pdu_un *ev_pdu = llc_pdu_un_hdr(ev_skb);
 		int dsize;
 
-		dsize = ntohs(eth_hdr(ev_skb)->h_proto) - 3;
+		dsize = (ev_skb->tail - (u8 *)ev_pdu) - 3;
 		memcpy(((u8 *)pdu) + 3, ((u8 *)ev_pdu) + 3, dsize);
 		skb_put(skb, dsize);
 	}

----- End forwarded message -----

#1 lore raw
Quoted 6 lines · Jim Westfall

Hi

In testing its not safe to trust the payload length we are given in a received llc test command header. Instead we should calculate this ourselves or run the risk of an skb_over_panic() if the received length in the header is > then the actual payload size.

Shouldn't it be discarded?

include/net/llc_pdu.h static inline void llc_pdu_init_as_test_ · line 351

Quoted 12 lines

diff -urp linux-2.6.24.2.org/include/net/llc_pdu.h linux-2.6.24.2/include/net/llc_pdu.h

include/net/llc_pdu.h +1 -1
@@ -348,7 +348,7 @@ static inline void llc_pdu_init_as_test_
 		struct llc_pdu_un *ev_pdu = llc_pdu_un_hdr(ev_skb);
 		int dsize;
 
-		dsize = ntohs(eth_hdr(ev_skb)->h_proto) - 3;
+		dsize = (ev_skb->tail - (u8 *)ev_pdu) - 3;

In addition, dsize can be a minus. (with & without your patch)

include/net/llc_pdu.h static inline void llc_pdu_init_as_test_

Quoted 5 lines
include/net/llc_pdu.h +0 -1
 		memcpy(((u8 *)pdu) + 3, ((u8 *)ev_pdu) + 3, dsize);
 		skb_put(skb, dsize);
 	}
 
----- End forwarded message -----

[PATCH] LLC: discard malfromed llc packet

Discard llc packet which has invalid data size.

---
 net/llc/llc_input.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
net/llc/llc_input.c +5 -2
index c40c9b2..6ef80fe 100644
@@ -117,9 +117,12 @@ static inline int llc_fixup_skb(struct sk_buff *skb)
 	skb_pull(skb, llc_len);
 	if (skb->protocol == htons(ETH_P_802_2)) {
 		__be16 pdulen = eth_hdr(skb)->h_proto;
-		u16 data_size = ntohs(pdulen) - llc_len;
+		s32 data_size = ntohs(pdulen) - llc_len;
 
-		if (unlikely(pskb_trim_rcsum(skb, data_size)))
+		if (data_size < 0
+		    || ((skb->tail - (u8 *)pdu) - llc_len) < data_size)
+			return 0;
+		if (unlikely(pskb_trim_rcsum(skb, (unsigned int)data_size)))
 			return 0;
 	}
 	return 1;
Signature · 1 line
1.5.4
Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#2 lore raw
In reply to Jim Westfall

From: Jim Westfall <[email protected]>
Date: Mon, 25 Feb 2008 08:14:39 -0800

Quoted 6 lines

In testing its not safe to trust the payload length we are given in a received llc test command header. Instead we should calculate this ourselves or run the risk of an skb_over_panic() if the received length in the header is > then the actual payload size.

I think we should, rather, use the value given to us in the proto field, but validate it against the real packet length.

If it's found to be bogus, we should drop the packet.