Skip to contentSkip to conversation

netfilter: nfnetlink_cthelper: Fix memory leak

PATCH Pablo Neira Ayuso 1 participant 2 messages Mar 21, 2017 1 message not in the archive netfilter

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Pablo Neira Ayuso

author maintainer Applied
#1 lore raw
Quoted 1 line · Jeffy Chen

We have memory leaks of nf_conntrack_helper & expect_policy.

Applied, thanks.

author maintainer
#2 lore raw
In reply to a message not in the archive
Quoted 13 lines · Jeffy Chen

We have memory leaks of nf_conntrack_helper & expect_policy.

---

 net/netfilter/nfnetlink_cthelper.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/netfilter/nfnetlink_cthelper.c +0 -0
index de87823..99d4bd7 100644

net/netfilter/nfnetlink_cthelper.c nfnl_cthelper_parse_expect_policy(struct nf_conntrack_helper *helper, · line 196

Quoted 6 lines
net/netfilter/nfnetlink_cthelper.c +2 -0
@@ -191,6 +191,8 @@ nfnl_cthelper_parse_expect_policy(struct nf_conntrack_helper *helper,
 		if (ret < 0)
 			goto err;
 	}
+
+	kfree(helper->expect_policy);
 	helper->expect_policy = expect_policy;

This is fixing the leak, however this is not safe since a packet may be still walking on the older helper->expect_policy.

        old_expect_policy = helper->expect_policy);
        helper->expect_policy = expect_policy;
        kfree(old_expect_policy);

We need to protect this with RCU if we want to support expectation policy updates properly.

I'm going to take this patch, but we have to follow up on this.