Skip to content

Commit ba1096c

Browse files
name2965kuba-moo
authored andcommitted
netrom: fix double-free in nr_route_frame()
In nr_route_frame(), old_skb is immediately freed without checking if nr_neigh->ax25 pointer is NULL. Therefore, if nr_neigh->ax25 is NULL, the caller function will free old_skb again, causing a double-free bug. Therefore, to prevent this, we need to modify it to check whether nr_neigh->ax25 is NULL before freeing old_skb. Cc: <stable@vger.kernel.org> Reported-by: syzbot+999115c3bf275797dc27@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/69694d6f.050a0220.58bed.0029.GAE@google.com/ Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Jeongjun Park <aha310510@gmail.com> Link: https://patch.msgid.link/20260119063359.10604-1-aha310510@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent cdf8de9 commit ba1096c

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

net/netrom/nr_route.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ int nr_route_frame(struct sk_buff *skb, ax25_cb *ax25)
752752
unsigned char *dptr;
753753
ax25_cb *ax25s;
754754
int ret;
755-
struct sk_buff *skbn;
755+
struct sk_buff *nskb, *oskb;
756756

757757
/*
758758
* Reject malformed packets early. Check that it contains at least 2
@@ -811,14 +811,16 @@ int nr_route_frame(struct sk_buff *skb, ax25_cb *ax25)
811811
/* We are going to change the netrom headers so we should get our
812812
own skb, we also did not know until now how much header space
813813
we had to reserve... - RXQ */
814-
if ((skbn=skb_copy_expand(skb, dev->hard_header_len, 0, GFP_ATOMIC)) == NULL) {
814+
nskb = skb_copy_expand(skb, dev->hard_header_len, 0, GFP_ATOMIC);
815+
816+
if (!nskb) {
815817
nr_node_unlock(nr_node);
816818
nr_node_put(nr_node);
817819
dev_put(dev);
818820
return 0;
819821
}
820-
kfree_skb(skb);
821-
skb=skbn;
822+
oskb = skb;
823+
skb = nskb;
822824
skb->data[14]--;
823825

824826
dptr = skb_push(skb, 1);
@@ -837,6 +839,9 @@ int nr_route_frame(struct sk_buff *skb, ax25_cb *ax25)
837839
nr_node_unlock(nr_node);
838840
nr_node_put(nr_node);
839841

842+
if (ret)
843+
kfree_skb(oskb);
844+
840845
return ret;
841846
}
842847

0 commit comments

Comments
 (0)