Skip to contentSkip to conversation

ax25: fix OOB read after address header strip in ax25_rcv()

PATCH Superseded Ashutosh Desai 2 participants 4 messages Apr 15 – Apr 16

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 ax25: fix OOB read after address header strip in ax25_rcv()

A remote station can send a crafted KISS frame that is just long enough to pass ax25_addr_parse() (minimum 14 address bytes) but carries no control or PID bytes. After ax25_kiss_rcv() strips the KISS framing byte and ax25_rcv() strips the address header with skb_pull(), skb->len drops to zero. The subsequent reads of skb->data[0] (control byte) and skb->data[1] (PID byte) are then out of bounds, which can crash the kernel or leak heap memory to a remote attacker.

Use pskb_may_pull(skb, 2) after the skb_pull() to ensure both bytes are in the linear area before reading them. Discard malformed frames that carry no control/PID pair.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")

---
V2 -> V3: remove incorrect Suggested-by; add symptom, Fixes, Cc stable V1 -> V2: use pskb_may_pull(skb, 2) instead of skb->len < 2

v2: https://lore.kernel.org/netdev/[email protected]/
v1: https://lore.kernel.org/netdev/[email protected]/

 net/ax25/ax25_in.c | 5 +++++
 1 file changed, 5 insertions(+)
net/ax25/ax25_in.c +5 -0
index d75b3e9ed93d..6a71dea876a1 100644
@@ -217,6 +217,11 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
 	 */
 	skb_pull(skb, ax25_addr_size(&dp));
 
+	if (!pskb_may_pull(skb, 2)) {
+		kfree_skb(skb);
+		return 0;
+	}
+
 	/* For our port addresses ? */
 	if (ax25cmp(&dest, dev_addr) == 0 && dp.lastrepeat + 1 == dp.ndigi)
 		mine = 1;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 11 lines · On Wed, 15 Apr 2026 06:36:54 +0000 Ashutosh Desai <[email protected]>…

A remote station can send a crafted KISS frame that is just long enough to pass ax25_addr_parse() (minimum 14 address bytes) but carries no control or PID bytes. After ax25_kiss_rcv() strips the KISS framing byte and ax25_rcv() strips the address header with skb_pull(), skb->len drops to zero. The subsequent reads of skb->data[0] (control byte) and skb->data[1] (PID byte) are then out of bounds, which can crash the kernel or leak heap memory to a remote attacker.

Use pskb_may_pull(skb, 2) after the skb_pull() to ensure both bytes are in the linear area before reading them. Discard malformed frames that carry no control/PID pair.

Is it just worth linearising the skb on entry to all this code? I believe all the frames are relatively short and low frequency. So the actual overhead is insignificant, but it makes all the sanity checks trivial.
It is even likely (hand waving) that the extra copy for non-linear data is faster than all the checks for non-linear data.

David

#2 lore raw
Quoted 1 line · David Laight

Is it just worth linearising the skb on entry to all this code?

Thanks for the feedback, David.

skb_linearize() on entry is a nice idea for simplifying sanity checks overall, but it wouldn't fix this particular bug on its own - the issue is skb->len dropping to zero after skb_pull(), not non-linear data. We'd still need a length check regardless. pskb_may_pull(skb, 2) handles both in one call.

That said, linearizing on entry to ax25_rcv() as a cleanup to simplify future checks sounds worthwhile - happy to send that as a separate net-next patch.

#3 lore raw
Quoted 10 lines · On Wed, 15 Apr 2026 22:39:13 -0700 (PDT) Ashutosh Desai…
Quoted 1 line · David Laight

Is it just worth linearising the skb on entry to all this code?

Thanks for the feedback, David.

skb_linearize() on entry is a nice idea for simplifying sanity checks overall, but it wouldn't fix this particular bug on its own - the issue is skb->len dropping to zero after skb_pull(), not non-linear data. We'd still need a length check regardless. pskb_may_pull(skb, 2) handles both in one call.

The skb->len >= 2 check will be a lot cheaper/smaller.

Quoted 3 lines

That said, linearizing on entry to ax25_rcv() as a cleanup to simplify future checks sounds worthwhile - happy to send that as a separate net-next patch.

I think you proposed just checking skb->len in an earlier version and it was pointed out that the skb may not be linear.
So perhaps linearize as part of this fix and leave the simplifcation of any other checks to later.

David