Skip to content

Commit 0f81eb4

Browse files
laf0rgeArnaldo Carvalho de Melo
authored andcommitted
[NETFILTER]: Fix double free after netlink_unicast() in ctnetlink
It's not necessary to free skb if netlink_unicast() failed. Signed-off-by: Yasuyuki Kozakai <[email protected]> Signed-off-by: Harald Welte <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent d2a7bb7 commit 0f81eb4

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

net/ipv4/netfilter/ip_conntrack_netlink.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
815815
IPCTNL_MSG_CT_NEW, 1, ct);
816816
ip_conntrack_put(ct);
817817
if (err <= 0)
818-
goto out;
818+
goto free;
819819

820820
err = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT);
821821
if (err < 0)
@@ -824,9 +824,9 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
824824
DEBUGP("leaving\n");
825825
return 0;
826826

827+
free:
828+
kfree_skb(skb2);
827829
out:
828-
if (skb2)
829-
kfree_skb(skb2);
830830
return -1;
831831
}
832832

@@ -1322,21 +1322,16 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
13221322
nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW,
13231323
1, exp);
13241324
if (err <= 0)
1325-
goto out;
1325+
goto free;
13261326

13271327
ip_conntrack_expect_put(exp);
13281328

1329-
err = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT);
1330-
if (err < 0)
1331-
goto free;
1332-
1333-
return err;
1329+
return netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT);
13341330

1331+
free:
1332+
kfree_skb(skb2);
13351333
out:
13361334
ip_conntrack_expect_put(exp);
1337-
free:
1338-
if (skb2)
1339-
kfree_skb(skb2);
13401335
return err;
13411336
}
13421337

0 commit comments

Comments
 (0)