[PATCH v2] rose: fix OOB reads on short CLEAR REQUEST frames.
Ashutosh Desai <[email protected]> Thu, 9 Apr 2026 15:19:06 +0000
| Newsgroups | org.kernel.vger.linux-hams,org.kernel.vger.linux-kernel,org.kernel.vger.netdev |
|---|---|
| Message-ID | <[email protected]> |
rose_process_rx_frame() passes skb directly to rose_decode(), which reads skb->data[2] without any prior length check. For CLEAR REQUEST frames the state machines then read skb->data[3] and skb->data[4] as the cause and diagnostic bytes. The original fix checked skb->len after the rose_decode() call, which was wrong for two reasons: rose_decode() already accessed skb->data[2] before the check ran, and skb->len counts bytes across non-linear fragments while skb->data only covers the linear head - so even a passing len check doesn't guarantee the bytes are safe to read directly. Eric Dumazet pointed out that pskb_may_pull() is the right approach here. Add a pskb_may_pull(skb, 3) check before rose_decode() to cover its frame[2] access, and a pskb_may_pull(skb, 5) check afterwards for the CLEAR REQUEST path to cover the cause and diagnostic reads. Suggested-by: Eric Dumazet <[email protected]> Signed-off-by: Ashutosh Desai <[email protected]> --- net/rose/rose_in.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/net/rose/rose_in.c b/net/rose/rose_in.c index 0276b393f..b9f01a11e 100644 --- a/net/rose/rose_in.c +++ b/net/rose/rose_in.c @@ -269,8 +269,18 @@ int rose_process_rx_frame(struct sock *sk, struct sk_buff *skb) if (rose->state == ROSE_STATE_0) return 0; + if (!pskb_may_pull(skb, 3)) { + kfree_skb(skb); + return 0; + } + frametype = rose_decode(skb, &ns, &nr, &q, &d, &m); + if (frametype == ROSE_CLEAR_REQUEST && !pskb_may_pull(skb, 5)) { + kfree_skb(skb); + return 0; + } + switch (rose->state) { case ROSE_STATE_1: queued = rose_state1_machine(sk, skb, frametype); -- 2.34.1