ax25: fix OOB read after address header strip in ax25_rcv()
Subsystems (3)
PATCH v5 1/1 ax25: fix OOB read after address header strip in ax25_rcv()
A crafted AX.25 frame with a valid address header but no control byte causes skb->len to reach zero after skb_pull() strips the header. The subsequent reads of skb->data[0] (control) and skb->data[1] (PID) are then out of bounds.
Linearize the skb after confirming the device is an AX.25 interface. Guard with skb->len < 1 after the pull - one byte suffices for LAPB control frames which have no PID byte. Add a separate skb->len < 2 check inside the UI branch before accessing the PID byte.
---
v5:
- Move skb_linearize() to after ax25_dev_ax25dev() check; avoids unnecessary allocation for frames on non-AX.25 interfaces
- Lower general guard from skb->len < 2 to skb->len < 1; the stricter limit incorrectly dropped valid 1-byte LAPB control frames (SABM, DISC, UA, DM, RR) which carry no PID byte
- Add explicit skb->len < 2 check inside UI branch before the PID byte (skb->data[1]) access
v4:
- Linearize skb at entry to ax25_rcv(); replace pskb_may_pull() with skb->len < 2 check (per David Laight review)
v3:
- Remove incorrect Suggested-by; add Fixes:, Cc: stable@ v2:
- Replace skb->len check with pskb_may_pull(skb, 2)
Link to v4: https://lore.kernel.org/netdev/[email protected]/
Link to v3: https://lore.kernel.org/netdev/[email protected]/
Link to v2: https://lore.kernel.org/netdev/[email protected]/
Link to v1: https://lore.kernel.org/netdev/[email protected]/
net/ax25/ax25_in.c | 9 +++++++++ 1 file changed, 9 insertions(+)
net/ax25/ax25_in.c +9 -0
@@ -199,6 +199,9 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,if ((ax25_dev =ax25_dev_ax25dev (dev)) ==NULL ) goto free; +if (skb_linearize (skb)) + goto free; +/* * Parse the address header. */
@@ -217,6 +220,9 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,*/ skb_pull (skb,ax25_addr_size (&dp)); +if (skb->len <1 ) + goto free; +/* For our port addresses ? */ if (ax25cmp (&dest, dev_addr) ==0 && dp.lastrepeat +1 == dp.ndigi) mine =1 ;
@@ -227,6 +233,9 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,/* UI frame - bypass LAPB processing */ if ((*skb->data & ~0x10 ) ==AX25_UI && dp.lastrepeat +1 == dp.ndigi) { +if (skb->len <2 ) + goto free; +skb_set_transport_header (skb,2 );/* skip control and pid */ ax25_send_to_raw (&dest, skb, skb->data[1 ]);
Signature · 1 line
2.34.1
Quoted 1 line · Ashutosh Desai
[PATCH v5 net] ax25: fix OOB read after address header strip in
ax25_rcv()
Please ignore this patch. A net-deletions patch removing the entire ax25 and amateur radio subsystem was posted earlier today. This fix is no longer needed.