[PATCH 1/3] net: netrom: fix integer overflow in nr_queue_rx_frame()
From: Mashiro Chen
Date: Tue Apr 07 2026 - 13:16:57 EST
nr_sock.fraglen is declared as unsigned short, so accumulating
received fragment lengths via
nr->fraglen += skb->len;
can silently wrap around to a small value once the total exceeds
65535 bytes. When the final fragment arrives (NR_MORE_FLAG clear),
the wrapped fraglen is passed to alloc_skb(), which allocates an
undersized buffer. The subsequent skb_put() and skb_copy_from_linear_data()
loop then writes the actual full data into it, resulting in a heap
buffer overflow.
An attacker with NR_STATE_3 access (i.e. after completing a NET/ROM
connection handshake, which open BBS/node services allow to any
callsign) can trigger this by sending a stream of NR_INFO frames
with the MORE flag set until fraglen wraps, followed by a final
NR_INFO frame.
Fix by checking whether adding the incoming skb's length to the
accumulated fraglen would exceed USHRT_MAX before each accumulation.
If so, purge the fragment queue, reset fraglen, and return an error
to signal receive-busy to the caller.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Mashiro Chen <mashiro.chen@xxxxxxxxxxx>
---
net/netrom/nr_in.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/net/netrom/nr_in.c b/net/netrom/nr_in.c
index 97944db6b5ac6..0b7cdb99ae501 100644
--- a/net/netrom/nr_in.c
+++ b/net/netrom/nr_in.c
@@ -36,12 +36,22 @@ static int nr_queue_rx_frame(struct sock *sk, struct sk_buff *skb, int more)
nr_start_idletimer(sk);
if (more) {
+ if ((unsigned int)nr->fraglen + skb->len > USHRT_MAX) {
+ skb_queue_purge(&nr->frag_queue);
+ nr->fraglen = 0;
+ return 1;
+ }
nr->fraglen += skb->len;
skb_queue_tail(&nr->frag_queue, skb);
return 0;
}
if (!more && nr->fraglen > 0) { /* End of fragment */
+ if ((unsigned int)nr->fraglen + skb->len > USHRT_MAX) {
+ skb_queue_purge(&nr->frag_queue);
+ nr->fraglen = 0;
+ return 1;
+ }
nr->fraglen += skb->len;
skb_queue_tail(&nr->frag_queue, skb);
--
2.53.0