]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: hamradio: bpqether: validate frame length in bpq_rcv()
authorMashiro Chen <mashiro.chen@mailbox.org>
Thu, 9 Apr 2026 02:49:26 +0000 (10:49 +0800)
committerJakub Kicinski <kuba@kernel.org>
Sun, 12 Apr 2026 20:19:03 +0000 (13:19 -0700)
The BPQ length field is decoded as:

  len = skb->data[0] + skb->data[1] * 256 - 5;

If the sender sets bytes [0..1] to values whose combined value is
less than 5, len becomes negative.  Passing a negative int to
skb_trim() silently converts to a huge unsigned value, causing the
function to be a no-op.  The frame is then passed up to AX.25 with
its original (untrimmed) payload, delivering garbage beyond the
declared frame boundary.

Additionally, a negative len corrupts the 64-bit rx_bytes counter
through implicit sign-extension.

Add a bounds check before pulling the length bytes: reject frames
where len is negative or exceeds the remaining skb data.

Acked-by: Joerg Reuter <jreuter@yaina.de>
Signed-off-by: Mashiro Chen <mashiro.chen@mailbox.org>
Link: https://patch.msgid.link/20260409024927.24397-2-mashiro.chen@mailbox.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/hamradio/bpqether.c

index 045c5177262eafed6894ff66b23e9c1c758d9725..214fd1f819a1bb54c49fb928d343b7603b31136d 100644 (file)
@@ -187,6 +187,9 @@ static int bpq_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_ty
 
        len = skb->data[0] + skb->data[1] * 256 - 5;
 
+       if (len < 0 || len > skb->len - 2)
+               goto drop_unlock;
+
        skb_pull(skb, 2);       /* Remove the length bytes */
        skb_trim(skb, len);     /* Set the length of the data */