Message ID | 1491051344-29766-1-git-send-email-zlpnobody@163.com |
---|---|
State | Accepted |
Delegated to: | Pablo Neira |
Headers | show |
On Sat, Apr 01, 2017 at 08:55:44PM +0800, Liping Zhang wrote: > From: Liping Zhang <zlpnobody@gmail.com> > > 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. Applied, thanks. -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c index 59ee27d..7b83bbf 100644 --- a/net/netfilter/nf_conntrack_netlink.c +++ b/net/netfilter/nf_conntrack_netlink.c @@ -1488,11 +1488,16 @@ static int ctnetlink_change_helper(struct nf_conn *ct, * treat the second attempt as a no-op instead of returning * an error. */ - if (help && help->helper && - !strcmp(help->helper->name, helpname)) - return 0; - else - return -EBUSY; + err = -EBUSY; + if (help) { + rcu_read_lock(); + helper = rcu_dereference(help->helper); + if (helper && !strcmp(helper->name, helpname)) + err = 0; + rcu_read_unlock(); + } + + return err; } if (!strcmp(helpname, "")) {