Skip to contentSkip to conversation

netfilter: cttimeout: Fix one possible use-after-free issue

PATCH Superseded [email protected] 2 participants 4 messages Apr 6, 2017 – Apr 13, 2017

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: cttimeout: Fix one possible use-after-free issue

From: Gao Feng <[email protected]>

The function ctnl_untimeout is used to untimeout every conntrack which is using the timeout. But it is necessary to add one barrier synchronize_rcu because of racing. Maybe one conntrack has already owned this timeout, but it is not inserted into unconfirmed list or the hash list, when ctnl_untimeout untimeout the conntracks

---
 net/netfilter/nfnetlink_cttimeout.c | 5 +++++
 1 file changed, 5 insertions(+)
net/netfilter/nfnetlink_cttimeout.c +5 -0
index 47d6656..af0cc87 100644
@@ -304,6 +304,11 @@ static void ctnl_untimeout(struct net *net, struct ctnl_timeout *timeout)
 	spinlock_t *lock;
 	int i, cpu;
 
+	/* Make sure the conntrack using the timeout already in the unconfirmed
+	 * list or in the hash table.
+	 */
+	synchronize_rcu();
+
 	for_each_possible_cpu(cpu) {
 		struct ct_pcpu *pcpu = per_cpu_ptr(net->ct.pcpu_lists, cpu);
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 7 lines · On Thu, Apr 06, 2017 at 07:09:09PM +0800, [email protected] wrote:

From: Gao Feng <[email protected]>

The function ctnl_untimeout is used to untimeout every conntrack which is using the timeout. But it is necessary to add one barrier synchronize_rcu because of racing. Maybe one conntrack has already owned this timeout, but it is not inserted into unconfirmed list or the hash list, when ctnl_untimeout untimeout the conntracks

This object is released via kfree_rcu().

You have to describe better the race scenario.

author
#2 lore raw
Quoted 10 lines

-----Original Message-----
From: Pablo Neira Ayuso [mailto:[email protected]]

Quoted 6 lines · On Thu, Apr 06, 2017 at 07:09:09PM +0800, [email protected] wrote:

The function ctnl_untimeout is used to untimeout every conntrack which is using the timeout. But it is necessary to add one barrier synchronize_rcu because of racing. Maybe one conntrack has already owned this timeout, but it is not inserted into unconfirmed list or the hash list, when ctnl_untimeout untimeout the conntracks

Quoted 3 lines

This object is released via kfree_rcu().

You have to describe better the race scenario.

Let me describe it with a call path
CPU1 CPU2
alloc new conn
add timeout ext

ctnl_timeout_try_del
untimeout all conns in list

kfree_rcu.
conn is confirmed.

As the show above, when cpu2 untimeout all conns in list, the new conn of cpu1
is not confirmed. The new conn still owns the timeout pointer. After the timeout
mem is freed really, it points to one invalid mem.

Regards
Feng

#3 lore raw
Quoted 22 lines · Gao Feng
Quoted 10 lines

-----Original Message-----
From: Pablo Neira Ayuso [mailto:[email protected]]

Quoted 6 lines · On Thu, Apr 06, 2017 at 07:09:09PM +0800, [email protected] wrote:

The function ctnl_untimeout is used to untimeout every conntrack which is using the timeout. But it is necessary to add one barrier synchronize_rcu because of racing. Maybe one conntrack has already owned this timeout, but it is not inserted into unconfirmed list or the hash list, when ctnl_untimeout untimeout the conntracks

Quoted 3 lines

This object is released via kfree_rcu().

You have to describe better the race scenario.

Let me describe it with a call path
CPU1 CPU2
alloc new conn
add timeout ext

ctnl_timeout_try_del
untimeout all conns in list

Quoted 8 lines

kfree_rcu.
conn is confirmed.

As the show above, when cpu2 untimeout all conns in list, the new conn of cpu1
is not confirmed. The new conn still owns the timeout pointer. After the timeout
mem is freed really, it points to one invalid mem.

You add this to your patch description and resubmit.

Please, send me one patch or two maximum at a time. Until I don't apply one, you don't send me a new one.