Skip to contentSkip to conversation

net: hamradio: fix missing input validation in bpqether and scc

PATCH Applied Mashiro Chen 3 participants 5 messages Apr 9 – Apr 12

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover net: hamradio: fix missing input validation in bpqether and scc

This series fixes two missing input validation bugs in the hamradio drivers. Both patches were reviewed by Joerg Reuter (hamradio maintainer).

v2 changes:
- bpqether: no code change; add Acked-by: Joerg Reuter
- scc: drop the upper bound of 4096 per reviewer feedback; only enforce the minimum of 16

Mashiro Chen (2):
net: hamradio: bpqether: validate frame length in bpq_rcv()
net: hamradio: scc: validate bufsize in SIOCSCCSMEM ioctl

 drivers/net/hamradio/bpqether.c | 3 +++
 drivers/net/hamradio/scc.c      | 2 ++
 2 files changed, 5 insertions(+)
Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 1/2 net: hamradio: bpqether: validate frame length in bpq_rcv()

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.

---
 drivers/net/hamradio/bpqether.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/hamradio/bpqether.c +3 -0
index 045c5177262eaf..214fd1f819a1bb 100644
@@ -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 */
 
Signature · 1 line
2.53.0
#2 lore raw

PATCH v2 2/2 net: hamradio: scc: validate bufsize in SIOCSCCSMEM ioctl

In reply to Mashiro Chen

The SIOCSCCSMEM ioctl copies a scc_mem_config from user space and assigns its bufsize field directly to scc->stat.bufsize without any range validation:

  scc->stat.bufsize = memcfg.bufsize;

If a privileged user (CAP_SYS_RAWIO) sets bufsize to 0, the receive interrupt handler later calls dev_alloc_skb(0) and immediately writes a KISS type byte via skb_put_u8() into a zero-capacity socket buffer, corrupting the adjacent skb_shared_info region.

Reject bufsize values smaller than 16; this is large enough to hold at least one KISS header byte plus useful data.

---
 drivers/net/hamradio/scc.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/hamradio/scc.c +2 -0
index ae5048efde686a..8569db4a71401c 100644
@@ -1909,6 +1909,8 @@ static int scc_net_siocdevprivate(struct net_device *dev,
 			if (!capable(CAP_SYS_RAWIO)) return -EPERM;
 			if (!arg || copy_from_user(&memcfg, arg, sizeof(memcfg)))
 				return -EINVAL;
+			if (memcfg.bufsize < 16)
+				return -EINVAL;
 			scc->stat.bufsize   = memcfg.bufsize;
 			return 0;
 		
Signature · 1 line
2.53.0
Acked-by on v2 2/2
#3 lore raw

Re: [PATCH v2 net 2/2] net: hamradio: scc: validate bufsize in SIOCSCCSMEM ioctl

Looks great, thanks!

    73, Joerg
Quoted 11 lines

The SIOCSCCSMEM ioctl copies a scc_mem_config from user space and assigns its bufsize field directly to scc->stat.bufsize without any range validation:

  scc->stat.bufsize = memcfg.bufsize;

If a privileged user (CAP_SYS_RAWIO) sets bufsize to 0, the receive interrupt handler later calls dev_alloc_skb(0) and immediately writes a KISS type byte via skb_put_u8() into a zero-capacity socket buffer, corrupting the adjacent skb_shared_info region.

Quoted 5 lines

Reject bufsize values smaller than 16; this is large enough to hold at least one KISS header byte plus useful data.

Quoted 21 lines
---
 drivers/net/hamradio/scc.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/hamradio/scc.c +2 -0
index ae5048efde686a..8569db4a71401c 100644
@@ -1909,6 +1909,8 @@ static int scc_net_siocdevprivate(struct net_device *dev,
 			if (!capable(CAP_SYS_RAWIO)) return -EPERM;
 			if (!arg || copy_from_user(&memcfg, arg, sizeof(memcfg)))
 				return -EINVAL;
+			if (memcfg.bufsize < 16)
+				return -EINVAL;
 			scc->stat.bufsize   = memcfg.bufsize;
 			return 0;
 
Signature · 1 line
2.53.0
Signature · 3 lines
Joerg Reuter                                    http://yaina.de/jreuter
And I make my way to where the warm scent of soil fills the evening air. 
Everything is waiting quietly out there....                 (Anne Clark)
#4 lore raw
In reply to Mashiro Chen
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Thu, 9 Apr 2026 10:49:25 +0800 you wrote:

This series fixes two missing input validation bugs in the hamradio drivers. Both patches were reviewed by Joerg Reuter (hamradio maintainer).

v2 changes:
- bpqether: no code change; add Acked-by: Joerg Reuter
- scc: drop the upper bound of 4096 per reviewer feedback; only enforce the minimum of 16

[...]

Here is the summary with links:
- [v2,net,1/2] net: hamradio: bpqether: validate frame length in bpq_rcv()

    https://git.kernel.org/netdev/net/c/6183bd8723a3
  - [v2,net,2/2] net: hamradio: scc: validate bufsize in SIOCSCCSMEM ioctl
    https://git.kernel.org/netdev/net/c/8263e484d662

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html