Skip to contentSkip to conversation

net/x25: Fix overflow and double free

PATCH Applied Martin Schiller 2 participants 4 messages Mar 31 – Apr 2

Subsystems (3)
lore
Share & tools
lore

Martin Schiller

author maintainer
#0 lore raw

v4 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]>
author maintainer
#1 lore raw

PATCH 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
    |
    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")
---
 net/x25/x25_in.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
net/x25/x25_in.c +2 -3
index b981a4828d08c2e6676749a06035910eab01e6cd..0dbc73efab1cbd4d98fa77d7a72a2b665203511b 100644
@@ -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
author maintainer
#2 lore raw

PATCH v4 2/2 net/x25: Fix overflow when accumulating packets

In reply to 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")
---
 net/x25/x25_in.c   | 4 ++++
 net/x25/x25_subr.c | 1 +
 2 files changed, 5 insertions(+)
net/x25/x25_in.c +4 -0
index 0dbc73efab1cbd4d98fa77d7a72a2b665203511b..e47ebd8acd21bff8d8fa1f5f48163145e9ac00f2 100644
@@ -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
index 0285aaa1e93c17233748d38eef6d8b5c6059b67a..159708d9ad20cb2e6db24ead67daf1e9d6258f64 100644
@@ -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
#3 lore raw
In reply to Martin Schiller
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.

[...]

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