Skip to contentSkip to conversation

net: netrom: fix memory leak in nr_output()

PATCH In review Deepanshu Kartikey 3 participants 3 messages Nov 29, 2025 – Dec 4, 2025

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

PATCH 1/1 net: netrom: fix memory leak in nr_output()

When nr_output() fragments a large packet, it calls sock_alloc_send_skb() in a loop to allocate skbs for each fragment. If this allocation fails, the function returns without freeing the original skb that was passed in, causing a memory leak.

Add the missing kfree_skb() call before returning on allocation failure.

---
 net/netrom/nr_out.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/netrom/nr_out.c +0 -1
index 5e531394a724..2b3cbceb0b52 100644
@@ -43,8 +42,11 @@ void nr_output(struct sock *sk, struct sk_buff *skb)
 		frontlen = skb_headroom(skb);
 
 		while (skb->len > 0) {
-			if ((skbn = sock_alloc_send_skb(sk, frontlen + NR_MAX_PACKET_SIZE, 0, &err)) == NULL)
			skbn = sock_alloc_send_skb(sk, frontlen + NR_MAX_PACKET_SIZE, 0, &err);
			if (skbn == NULL) {

+ kfree_skb(skb);
return;
+ }

skb_reserve(skbn, frontlen);

Signature · 1 line
2.43.0
#1 lore raw
Quoted 1 line · Deepanshu Kartikey

When nr_output() fragments a large packet, it calls sock_alloc_send_skb()

Hi!

Coincidentally, we both are working on this issue simultaneously.

From the syz test requests:
https://syzkaller.appspot.com/bug?extid=d7abc36bbbb6d7d40b58

I sended the test patch earlier, only a dozen seconds...

------
Best regards
Wang Liang

Quoted 32 lines

in a loop to allocate skbs for each fragment. If this allocation fails, the function returns without freeing the original skb that was passed in, causing a memory leak.

Add the missing kfree_skb() call before returning on allocation failure.

---
  net/netrom/nr_out.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
net/netrom/nr_out.c +2 -1
index 5e531394a724..2b3cbceb0b52 100644
@@ -43,8 +42,11 @@ void nr_output(struct sock *sk, struct sk_buff *skb)
  		frontlen = skb_headroom(skb);
 
  		while (skb->len > 0) {
-			if ((skbn = sock_alloc_send_skb(sk, frontlen + NR_MAX_PACKET_SIZE, 0, &err)) == NULL)
 			skbn = sock_alloc_send_skb(sk, frontlen + NR_MAX_PACKET_SIZE, 0, &err);
 			if (skbn == NULL) {
+				kfree_skb(skb);
  				return;
+			}
 
  			skb_reserve(skbn, frontlen);
maintainer
#2 lore raw
Quoted 11 lines · Wang Liang
Quoted 1 line · Deepanshu Kartikey

When nr_output() fragments a large packet, it calls sock_alloc_send_skb()

Hi!

Coincidentally, we both are working on this issue simultaneously.

From the syz test requests:
https://syzkaller.appspot.com/bug?extid=d7abc36bbbb6d7d40b58

I sended the test patch earlier, only a dozen seconds...

FTR and future similar cases, we don't have the send time information handy. Instead we use the timestamp as available on patchwork.

In this specific case Deepanshu's patch landed first, but does not apply cleanly, so I'll apply Wang's one.

Cheers,

Paolo