* [PATCH net v4 1/2] net/x25: Fix potential double free of skb
2026-03-31 7:43 [PATCH net v4 0/2] net/x25: Fix overflow and double free Martin Schiller
@ 2026-03-31 7:43 ` Martin Schiller
2026-03-31 7:43 ` [PATCH net v4 2/2] net/x25: Fix overflow when accumulating packets Martin Schiller
2026-04-02 11:50 ` [PATCH net v4 0/2] net/x25: Fix overflow and double free patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Martin Schiller @ 2026-03-31 7:43 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman
Cc: Yiming Qian, linux-x25, netdev, linux-kernel, security,
Martin Schiller
When alloc_skb fails in x25_queue_rx_frame it calls kfree_skb(skb) at
line 48 and returns 1 (error).
This error propagates back through the call chain:
x25_queue_rx_frame returns 1
|
v
x25_state3_machine receives the return value 1 and takes the else
branch at line 278, setting queued=0 and returning 0
|
v
x25_process_rx_frame returns queued=0
|
v
x25_backlog_rcv at line 452 sees queued=0 and calls kfree_skb(skb)
again
This would free the same skb twice. Looking at x25_backlog_rcv:
net/x25/x25_in.c:x25_backlog_rcv() {
...
queued = x25_process_rx_frame(sk, skb);
...
if (!queued)
kfree_skb(skb);
}
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Martin Schiller <ms@dev.tdt.de>
---
net/x25/x25_in.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/net/x25/x25_in.c b/net/x25/x25_in.c
index b981a4828d08c2e6676749a06035910eab01e6cd..0dbc73efab1cbd4d98fa77d7a72a2b665203511b 100644
--- a/net/x25/x25_in.c
+++ b/net/x25/x25_in.c
@@ -44,10 +44,9 @@ static int x25_queue_rx_frame(struct sock *sk, struct sk_buff *skb, int more)
if (x25->fraglen > 0) { /* End of fragment */
int len = x25->fraglen + skb->len;
- if ((skbn = alloc_skb(len, GFP_ATOMIC)) == NULL){
- kfree_skb(skb);
+ skbn = alloc_skb(len, GFP_ATOMIC);
+ if (!skbn)
return 1;
- }
skb_queue_tail(&x25->fragment_queue, skb);
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH net v4 2/2] net/x25: Fix overflow when accumulating packets
2026-03-31 7:43 [PATCH net v4 0/2] net/x25: Fix overflow and double free Martin Schiller
2026-03-31 7:43 ` [PATCH net v4 1/2] net/x25: Fix potential double free of skb Martin Schiller
@ 2026-03-31 7:43 ` Martin Schiller
2026-04-02 11:50 ` [PATCH net v4 0/2] net/x25: Fix overflow and double free patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Martin Schiller @ 2026-03-31 7:43 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman
Cc: Yiming Qian, linux-x25, netdev, linux-kernel, security,
Martin Schiller
Add a check to ensure that `x25_sock.fraglen` does not overflow.
The `fraglen` also needs to be resetted when purging `fragment_queue` in
`x25_clear_queues()`.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Suggested-by: Yiming Qian <yimingqian591@gmail.com>
Signed-off-by: Martin Schiller <ms@dev.tdt.de>
---
net/x25/x25_in.c | 4 ++++
net/x25/x25_subr.c | 1 +
2 files changed, 5 insertions(+)
diff --git a/net/x25/x25_in.c b/net/x25/x25_in.c
index 0dbc73efab1cbd4d98fa77d7a72a2b665203511b..e47ebd8acd21bff8d8fa1f5f48163145e9ac00f2 100644
--- a/net/x25/x25_in.c
+++ b/net/x25/x25_in.c
@@ -34,6 +34,10 @@ static int x25_queue_rx_frame(struct sock *sk, struct sk_buff *skb, int more)
struct sk_buff *skbo, *skbn = skb;
struct x25_sock *x25 = x25_sk(sk);
+ /* make sure we don't overflow */
+ if (x25->fraglen + skb->len > USHRT_MAX)
+ return 1;
+
if (more) {
x25->fraglen += skb->len;
skb_queue_tail(&x25->fragment_queue, skb);
diff --git a/net/x25/x25_subr.c b/net/x25/x25_subr.c
index 0285aaa1e93c17233748d38eef6d8b5c6059b67a..159708d9ad20cb2e6db24ead67daf1e9d6258f64 100644
--- a/net/x25/x25_subr.c
+++ b/net/x25/x25_subr.c
@@ -40,6 +40,7 @@ void x25_clear_queues(struct sock *sk)
skb_queue_purge(&x25->interrupt_in_queue);
skb_queue_purge(&x25->interrupt_out_queue);
skb_queue_purge(&x25->fragment_queue);
+ x25->fraglen = 0;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH net v4 0/2] net/x25: Fix overflow and double free
2026-03-31 7:43 [PATCH net v4 0/2] net/x25: Fix overflow and double free Martin Schiller
2026-03-31 7:43 ` [PATCH net v4 1/2] net/x25: Fix potential double free of skb Martin Schiller
2026-03-31 7:43 ` [PATCH net v4 2/2] net/x25: Fix overflow when accumulating packets Martin Schiller
@ 2026-04-02 11:50 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-04-02 11:50 UTC (permalink / raw)
To: Martin Schiller
Cc: davem, edumazet, kuba, pabeni, horms, yimingqian591, linux-x25,
netdev, linux-kernel, security
Hello:
This series was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Tue, 31 Mar 2026 09:43:16 +0200 you wrote:
> This patch set includes 2 fixes:
>
> The first removes a potential double free of received skb
> The second fixes an overflow when accumulating packets with the more-bit
> set.
>
> Signed-off-by: Martin Schiller <ms@dev.tdt.de>
>
> [...]
Here is the summary with links:
- [net,v4,1/2] net/x25: Fix potential double free of skb
https://git.kernel.org/netdev/net/c/d10a26aa4d07
- [net,v4,2/2] net/x25: Fix overflow when accumulating packets
https://git.kernel.org/netdev/net/c/a1822cb524e8
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread