Nfnetlink and ipset fixes
Subsystems (2)
cover Nfnetlink and ipset fixes
Hi,
The 2 first patches fixes the same issue, but in 2 different place.
Patch 1:
So here is how the issue can be reprocuced:
Create a netlink message, targeting ipset subsystem. And send a command on id 0 (IPSET_CMD_NONE):
This will lead to a crash on line 188 of nfnetlink.c since nc->call is NULL (so you get a NULL dereference).
Or Patch 2:
Same issue.
It fixes ipset to handle the IPSET_CMD_NONE, return -EOPNOTSUPP.
Patch 3:
While doing patch 1 I figured out rcu_read_unlock() is not called in case nla_parse() error, so it fixes it.
Br,
Tomasz Bursztyka (3):
nfnetlink: Check callbacks before using those in nfnetlink_rcv_msg
ipset: Handle properly an IPSET_CMD_NONE
nfnetlink: Unlock a previously locked rcu_read in nfnetlink_rcv_msg
net/netfilter/ipset/ip_set_core.c | 12 ++++++++++++ net/netfilter/nfnetlink.c | 8 ++++++-- 2 files changed, 18 insertions(+), 2 deletions(-)
Signature · 1 line
1.7.8.6
PATCH 1/3 nfnetlink: Check callbacks before using those in nfnetlink_rcv_msg
nfnetlink_rcv_msg() might call a NULL callback which will cause NULL pointer dereference.
--- net/netfilter/nfnetlink.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
net/netfilter/nfnetlink.c +3 -1
@@ -184,9 +184,11 @@ replay: lockdep_is_held(&nfnl_mutex)) != ss || nfnetlink_find_client(type, ss) != nc) err = -EAGAIN ; - else + else if (nc->call) err = nc->call (net->nfnl, skb, nlh, (const struct nlattr **)cda); + else + err = -EINVAL ;nfnl_unlock (); }if (err == -EAGAIN )
Signature · 1 line
1.7.8.6
Pablo Neira Ayuso
maintainerRe: [PATCH 1/3] nfnetlink: Check callbacks before using those in nfnetlink_rcv_msg
Quoted 13 lines · Tomasz Bursztyka
nfnetlink_rcv_msg()might call a NULL callback which will cause NULL pointer dereference.Signed-off-by Tomasz Bursztyka <[email protected]>--- net/netfilter/nfnetlink.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)net/netfilter/nfnetlink.c +0
-0
net/netfilter/nfnetlink.c replay: · line 191
Quoted 9 lines
net/netfilter/nfnetlink.c +3
-1@@ -184,9 +184,11 @@ replay: lockdep_is_held(&nfnl_mutex)) != ss || nfnetlink_find_client(type, ss) != nc) err = -EAGAIN ; - else + else if (nc->call) err = nc->call (net->nfnl, skb, nlh, (const struct nlattr **)cda); + else + err = -EINVAL ;
Hm, I think this is redundant. We got the ipset problem fixed with 2/3. I think we can add some BUG_ON instead as all nc->call needs to be defined. Otherwise, spot a bug message so it is fixed.
Re: [PATCH 1/3] nfnetlink: Check callbacks before using those in nfnetlink_rcv_msg
Quoted 4 lines · Pablo Neira Ayuso
Quoted 3 lines · Tomasz Bursztyka
nfnetlink_rcv_msg()might call a NULL callback which will cause NULL pointer dereference.
Quoted 16 lines
net/netfilter/nfnetlink.c replay: · line 191
Quoted 12 lines
Signed-off-by Tomasz Bursztyka <[email protected]>---
net/netfilter/nfnetlink.c +3
-1@@ -184,9 +184,11 @@ replay: lockdep_is_held(&nfnl_mutex)) != ss || nfnetlink_find_client(type, ss) != nc) err = -EAGAIN ; - else + else if (nc->call) err = nc->call (net->nfnl, skb, nlh, (const struct nlattr **)cda); + else + err = -EINVAL ;Hm, I think this is redundant. We got the ipset problem fixed with 2/3. I think we can add some
BUG_ONinstead as allnc->callneeds to be defined. Otherwise, spot a bug message so it is fixed.
Seriously, we have run into NULL dereferences at this place so often that it should not be discarded as a PEBKAC issue. Yes, it is the programmer's responsibility to fill in .call, but error handling is anytime better than driving one's machine into the pit stop due to a NULL deref or BUG_ON.
Florian Westphal
maintainerRe: [PATCH 1/3] nfnetlink: Check callbacks before using those in nfnetlink_rcv_msg
Quoted 18 lines · Jan Engelhardt
Quoted 16 lines · Pablo Neira Ayuso
net/netfilter/nfnetlink.c replay: · line 191
Quoted 11 lines · Tomasz Bursztyka
---
net/netfilter/nfnetlink.c +3
-1@@ -184,9 +184,11 @@ replay: lockdep_is_held(&nfnl_mutex)) != ss || nfnetlink_find_client(type, ss) != nc) err = -EAGAIN ; - else + else if (nc->call) err = nc->call (net->nfnl, skb, nlh, (const struct nlattr **)cda); + else + err = -EINVAL ;Hm, I think this is redundant. We got the ipset problem fixed with 2/3. I think we can add some
BUG_ONinstead as allnc->callneeds to be defined. Otherwise, spot a bug message so it is fixed.
Quoted 5 lines
Seriously, we have run into NULL dereferences at this place so often that it should not be discarded as a PEBKAC issue. Yes, it is the programmer's responsibility to fill in .call, but error handling is anytime better than driving one's machine into the pit stop due to a NULL deref or
BUG_ON.
Agreed. I think this should be WARN_ON_ONCE + ret EINVAL. We also do this with various places that e.g. fill netlink messages so that adding new attributes without bumping allocation sizes is reported without crashes. Since we've started to move the performance-critical nfnetlink stuff over to ->call_rcu the extra NULL test should not harm fastpath either.
Pablo Neira Ayuso
maintainerRe: [PATCH 1/3] nfnetlink: Check callbacks before using those in nfnetlink_rcv_msg
Quoted 25 lines · Florian Westphal
Quoted 18 lines · Jan Engelhardt
Quoted 16 lines · Pablo Neira Ayuso
net/netfilter/nfnetlink.c replay: · line 191
Quoted 11 lines · Tomasz Bursztyka
---
net/netfilter/nfnetlink.c +3
-1@@ -184,9 +184,11 @@ replay: lockdep_is_held(&nfnl_mutex)) != ss || nfnetlink_find_client(type, ss) != nc) err = -EAGAIN ; - else + else if (nc->call) err = nc->call (net->nfnl, skb, nlh, (const struct nlattr **)cda); + else + err = -EINVAL ;Hm, I think this is redundant. We got the ipset problem fixed with 2/3. I think we can add some
BUG_ONinstead as allnc->callneeds to be defined. Otherwise, spot a bug message so it is fixed.Quoted 5 lines
Seriously, we have run into NULL dereferences at this place so often that it should not be discarded as a PEBKAC issue. Yes, it is the programmer's responsibility to fill in .call, but error handling is anytime better than driving one's machine into the pit stop due to a NULL deref or
BUG_ON.
Quoted 6 lines
Agreed. I think this should be
WARN_ON_ONCE+ ret EINVAL. We also do this with various places that e.g. fill netlink messages so that adding new attributes without bumping allocation sizes is reported without crashes. Since we've started to move the performance-critical nfnetlink stuff over to ->call_rcu the extra NULL test should not harm fastpath either.
OK, fair enough. I've enqueued this to nf-next.
PATCH 2/3 ipset: Handle properly an IPSET_CMD_NONE
In reply to Tomasz Bursztyka--- net/netfilter/ipset/ip_set_core.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
net/netfilter/ipset/ip_set_core.c +12 -0
@@ -640,6 +640,14 @@ find_free_id(const char *name, ip_set_id_t *index, struct ip_set **set) }static int +ip_set_none (struct sock *ctnl,struct sk_buff *skb, +const struct nlmsghdr *nlh, +const struct nlattr *const attr[]) +{ +return -EOPNOTSUPP ; +} + +static int ip_set_create (struct sock *ctnl,struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const attr[])
@@ -1539,6 +1547,10 @@ nlmsg_failure: }static const struct nfnl_callback ip_set_netlink_subsys_cb[IPSET_MSG_MAX ] = { + [IPSET_CMD_NONE ] = { + .call = ip_set_none, + .attr_count =IPSET_ATTR_CMD_MAX , + }, [IPSET_CMD_CREATE ] = { .call = ip_set_create, .attr_count =IPSET_ATTR_CMD_MAX ,
Signature · 1 line
1.7.8.6
Re: [PATCH 2/3] ipset: Handle properly an IPSET_CMD_NONE
Quoted 1 line · Tomasz Bursztyka
Signed-off-by Tomasz Bursztyka <[email protected]>
Never occured to me to send IPSET_CMD_NONE :-).
Best regards,
Jozsef
Quoted 42 lines
--- net/netfilter/ipset/ip_set_core.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)net/netfilter/ipset/ip_set_core.c +12
-0@@ -640,6 +640,14 @@ find_free_id(const char *name, ip_set_id_t *index, struct ip_set **set) }static int +ip_set_none (struct sock *ctnl,struct sk_buff *skb, +const struct nlmsghdr *nlh, +const struct nlattr *const attr[]) +{ +return -EOPNOTSUPP ; +} + +static int ip_set_create (struct sock *ctnl,struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const attr[])@@ -1539,6 +1547,10 @@ nlmsg_failure: }static const struct nfnl_callback ip_set_netlink_subsys_cb[IPSET_MSG_MAX ] = { + [IPSET_CMD_NONE ] = { + .call = ip_set_none, + .attr_count =IPSET_ATTR_CMD_MAX , + }, [IPSET_CMD_CREATE ] = { .call = ip_set_create, .attr_count =IPSET_ATTR_CMD_MAX ,Signature · 6 lines
1.7.8.6 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences
H-1525 Budapest 114, POB. 49, Hungary
Re: [PATCH 2/3] ipset: Handle properly an IPSET_CMD_NONE
Quoted 7 lines · Jozsef Kadlecsik
Quoted 1 line · Tomasz Bursztyka
Signed-off-by Tomasz Bursztyka <[email protected]>Acked-by Jozsef Kadlecsik <[email protected]>Never occured to me to send
IPSET_CMD_NONE:-).
Applied, thanks.
PATCH 3/3 nfnetlink: Unlock a previously locked rcu_read in nfnetlink_rcv_msg
In reply to Tomasz Bursztyka--- net/netfilter/nfnetlink.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
net/netfilter/nfnetlink.c +3 -1
@@ -169,8 +169,10 @@ replay: err =nla_parse (cda, ss->cb[cb_id].attr_count, attr, attrlen, ss->cb[cb_id].policy); -if (err <0 ) +if (err <0 ) { +rcu_read_unlock ();return err; + }if (nc->call_rcu) { err = nc->call_rcu(net->nfnl, skb, nlh,
Signature · 1 line
1.7.8.6
Re: [PATCH 3/3] nfnetlink: Unlock a previously locked rcu_read in nfnetlink_rcv_msg
Quoted 11 lines · Tomasz Bursztyka
Signed-off-by Tomasz Bursztyka <[email protected]>--- net/netfilter/nfnetlink.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)net/netfilter/nfnetlink.c +0
-0@@ -169,8 +169,10 @@ replay:
net/netfilter/nfnetlink.c replay: · line 178
Quoted 10 lines
net/netfilter/nfnetlink.c +3
-1err =nla_parse (cda, ss->cb[cb_id].attr_count, attr, attrlen, ss->cb[cb_id].policy); -if (err <0 ) +if (err <0 ) { +rcu_read_unlock ();return err; + }if (nc->call_rcu) { err = nc->call_rcu(net->nfnl, skb, nlh,
Nice catch, thanks.
Please someone add in changelog to ease stable team work :
Bug added in commit 6b75e3e8d664a9a (netfilter: nfnetlink: add RCU in nfnetlink_rcv_msg())
Re: [PATCH 3/3] nfnetlink: Unlock a previously locked rcu_read in nfnetlink_rcv_msg
Quoted 25 lines · Eric Dumazet
Quoted 11 lines · Tomasz Bursztyka
Signed-off-by Tomasz Bursztyka <[email protected]>--- net/netfilter/nfnetlink.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)net/netfilter/nfnetlink.c +0
-0@@ -169,8 +169,10 @@ replay:net/netfilter/nfnetlink.c replay: · line 178
Quoted 10 lines
net/netfilter/nfnetlink.c +3
-1err =nla_parse (cda, ss->cb[cb_id].attr_count, attr, attrlen, ss->cb[cb_id].policy); -if (err <0 ) +if (err <0 ) { +rcu_read_unlock ();return err; + }if (nc->call_rcu) { err = nc->call_rcu(net->nfnl, skb, nlh,Nice catch, thanks.
Quoted 6 lines
Please someone add in changelog to ease stable team work :
Bug added in commit
6b75e3e8d664a9a(netfilter: nfnetlink: add RCU innfnetlink_rcv_msg())Acked-by Eric Dumazet <[email protected]>
Applied, thanks.