Skip to content

Commit 3173d5b

Browse files
Liping Zhangummakynes
authored andcommitted
netfilter: ctnetlink: make it safer when checking the ct helper name
One CPU is doing ctnetlink_change_helper(), while another CPU is doing unhelp() at the same time. So even if help->helper is not NULL at first, the later statement strcmp(help->helper->name, ...) may still access the NULL pointer. So we must use rcu_read_lock and rcu_dereference to avoid such _bad_ thing happen. Fixes: f95d7a4 ("netfilter: ctnetlink: Fix regression in CTA_HELP processing") Signed-off-by: Liping Zhang <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 8b5995d commit 3173d5b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

net/netfilter/nf_conntrack_netlink.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,11 +1488,16 @@ static int ctnetlink_change_helper(struct nf_conn *ct,
14881488
* treat the second attempt as a no-op instead of returning
14891489
* an error.
14901490
*/
1491-
if (help && help->helper &&
1492-
!strcmp(help->helper->name, helpname))
1493-
return 0;
1494-
else
1495-
return -EBUSY;
1491+
err = -EBUSY;
1492+
if (help) {
1493+
rcu_read_lock();
1494+
helper = rcu_dereference(help->helper);
1495+
if (helper && !strcmp(helper->name, helpname))
1496+
err = 0;
1497+
rcu_read_unlock();
1498+
}
1499+
1500+
return err;
14961501
}
14971502

14981503
if (!strcmp(helpname, "")) {

0 commit comments

Comments
 (0)