All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nf] netfilter: ctnetlink: make it safer when checking the ct helper name
@ 2017-04-01 12:55 Liping Zhang
  2017-04-08 21:10 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Liping Zhang @ 2017-04-01 12:55 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel, cernekee, Liping Zhang

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.

Fixes: f95d7a46bc57 ("netfilter: ctnetlink: Fix regression in CTA_HELP processing")
Signed-off-by: Liping Zhang <zlpnobody@gmail.com>
---
 net/netfilter/nf_conntrack_netlink.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

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, "")) {
-- 
2.5.5



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH nf] netfilter: ctnetlink: make it safer when checking the ct helper name
  2017-04-01 12:55 [PATCH nf] netfilter: ctnetlink: make it safer when checking the ct helper name Liping Zhang
@ 2017-04-08 21:10 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2017-04-08 21:10 UTC (permalink / raw)
  To: Liping Zhang; +Cc: netfilter-devel, cernekee, Liping Zhang

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-04-08 21:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-01 12:55 [PATCH nf] netfilter: ctnetlink: make it safer when checking the ct helper name Liping Zhang
2017-04-08 21:10 ` Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.