net/x25: Fix overflow and double free
Subsystems (3)
Martin Schiller
maintainerv4 cover net/x25: Fix overflow and double free
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.
---
Changes in v4:
- Do not call skb_free(skb) in case of overflow
- Add another patch to fix potential double free if alloc_skb fails
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Added missing Cc: Simon Horman <[email protected]>
- Added missing Fixes tag
- Replaced Reported-by: by Suggested-by:, because I cannot give an
URL to the required Closes: tag
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Use USHRT_MAX instead of sizeof(fraglen) nonsense
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Martin Schiller (2):
net/x25: Fix potential double free of skb net/x25: Fix overflow when accumulating packets
net/x25/x25_in.c | 9 ++++++--- net/x25/x25_subr.c | 1 + 2 files changed, 7 insertions(+), 3 deletions(-)
---
base-commit: a142d139168cce8d5776245b5494c7f7f5d7fb7d
change-id: 20260325-x25_fraglen-8fc240d1edd3
Best regards,
Signature · 1 line
Martin Schiller <[email protected]>
Martin Schiller
maintainerPATCH v4 1/2 net/x25: Fix potential double free of skb
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
|
vx25_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);
}--- net/x25/x25_in.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/x25/x25_in.c +2 -3
@@ -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);
Signature · 1 line
2.47.3
Martin Schiller
maintainerPATCH v4 2/2 net/x25: Fix overflow when accumulating packets
In reply to Martin SchillerAdd 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().
--- net/x25/x25_in.c | 4 ++++ net/x25/x25_subr.c | 1 + 2 files changed, 5 insertions(+)
net/x25/x25_in.c +4 -0
@@ -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);
net/x25/x25_subr.c +1 -0
@@ -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 ; }
Signature · 1 line
2.47.3
This series was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 9 lines · 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 <[email protected]>[...]
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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html