netlink: fix wrong subscription bitmask to group mapping in
Subsystems (2)
PATCH 1/1 netlink: fix wrong subscription bitmask to group mapping in
The subscription bitmask passed via struct sockaddr_nl is converted to the group number when calling the netlink_bind() and netlink_unbind() callbacks.
The conversion is however incorrect since bitmask (1 << 0) needs to be mapped to group number 1. Note that you cannot specify the group number 0 (usually known as _NONE) from setsockopt() using NETLINK_ADD_MEMBERSHIP since this is rejected through -EINVAL.
This problem became noticeable since 97840cb ("netfilter: nfnetlink:
fix insufficient validation in nfnetlink_bind") when binding to bitmask (1 << 0) in ctnetlink.
---
v2: Rebased upon current net tree. Previous patch:
http://patchwork.ozlabs.org/patch/426205/
did not apply cleanly.
net/netlink/af_netlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netlink/af_netlink.c +2 -2
@@ -1438,7 +1438,7 @@ static void netlink_undo_bind(int group, long unsigned int groups,for (undo =0 ; undo < group; undo++)if (test_bit (undo, &groups)) - nlk->netlink_unbind (sock_net (sk), undo); + nlk->netlink_unbind (sock_net (sk), undo +1 ); } static int netlink_bind(struct socket *sock, struct sockaddr *addr,
@@ -1476,7 +1476,7 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr,for (group =0 ; group < nlk->ngroups; group++) {if (!test_bit (group, &groups))continue ; - err = nlk->netlink_bind (net, group); + err = nlk->netlink_bind (net, group +1 );if (!err)continue ;netlink_undo_bind (group, groups, sk);
Signature · 1 line
1.7.10.4
Quoted 9 lines · Pablo Neira Ayuso
The subscription bitmask passed via struct
sockaddr_nlis converted to the group number when calling thenetlink_bind()andnetlink_unbind()callbacks.The conversion is however incorrect since bitmask (1 << 0) needs to be mapped to group number 1. Note that you cannot specify the group number 0 (usually known as
_NONE) fromsetsockopt()usingNETLINK_ADD_MEMBERSHIPsince this is rejected through-EINVAL.
Quoted 7 lines
This problem became noticeable since 97840cb ("netfilter: nfnetlink:
fix insufficient validation innfnetlink_bind") when binding to bitmask (1 << 0) in ctnetlink.Reported-by Andre Tomt <[email protected]>Reported-by Ivan Delalande <[email protected]>Signed-off-by Pablo Neira Ayuso <[email protected]>
Thanks a lot for this fix!
Quoted 24 lines
---
v2: Rebased upon current net tree. Previous patch:http://patchwork.ozlabs.org/patch/426205/
did not apply cleanly.
net/netlink/af_netlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/netlink/af_netlink.c +1
-1@@ -1438,7 +1438,7 @@ static void netlink_undo_bind(int group, long unsigned int groups,for (undo =0 ; undo < group; undo++)if (test_bit (undo, &groups)) - nlk->netlink_unbind (sock_net (sk), undo); + nlk->netlink_unbind (sock_net (sk), undo +1 ); } static int netlink_bind(struct socket *sock, struct sockaddr *addr,
net/netlink/af_netlink.c static int netlink_bind(struct socket *sock, struct sockaddr *addr, · line 1482
Quoted 8 lines
net/netlink/af_netlink.c +1
-1@@ -1476,7 +1476,7 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr,for (group =0 ; group < nlk->ngroups; group++) {if (!test_bit (group, &groups))continue ; - err = nlk->netlink_bind (net, group); + err = nlk->netlink_bind (net, group +1 );if (!err)continue ;netlink_undo_bind (group, groups, sk);
I guess this should also be group + 1 there:
netlink_undo_bind(group + 1, groups, sk);
Signature · 2 lines
Ivan "Colona" Delalande Arista Networks
Quoted 55 lines · Ivan Delalande
Quoted 9 lines · Pablo Neira Ayuso
The subscription bitmask passed via struct
sockaddr_nlis converted to the group number when calling thenetlink_bind()andnetlink_unbind()callbacks.The conversion is however incorrect since bitmask (1 << 0) needs to be mapped to group number 1. Note that you cannot specify the group number 0 (usually known as
_NONE) fromsetsockopt()usingNETLINK_ADD_MEMBERSHIPsince this is rejected through-EINVAL.Quoted 7 lines
This problem became noticeable since 97840cb ("netfilter: nfnetlink:
fix insufficient validation innfnetlink_bind") when binding to bitmask (1 << 0) in ctnetlink.Reported-by Andre Tomt <[email protected]>Reported-by Ivan Delalande <[email protected]>Signed-off-by Pablo Neira Ayuso <[email protected]>Thanks a lot for this fix!
Quoted 24 lines
---
v2: Rebased upon current net tree. Previous patch:http://patchwork.ozlabs.org/patch/426205/
did not apply cleanly.
net/netlink/af_netlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/netlink/af_netlink.c +1
-1@@ -1438,7 +1438,7 @@ static void netlink_undo_bind(int group, long unsigned int groups,for (undo =0 ; undo < group; undo++)if (test_bit (undo, &groups)) - nlk->netlink_unbind (sock_net (sk), undo); + nlk->netlink_unbind (sock_net (sk), undo +1 ); } static int netlink_bind(struct socket *sock, struct sockaddr *addr,net/netlink/af_netlink.c static int netlink_bind(struct socket *sock, struct sockaddr *addr, · line 1482
Quoted 8 lines
net/netlink/af_netlink.c +1
-1@@ -1476,7 +1476,7 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr,for (group =0 ; group < nlk->ngroups; group++) {if (!test_bit (group, &groups))continue ; - err = nlk->netlink_bind (net, group); + err = nlk->netlink_bind (net, group +1 );if (!err)continue ;netlink_undo_bind (group, groups, sk);I guess this should also be group + 1 there:
Quoted 1 line
netlink_undo_bind(group + 1, groups, sk);
We don't need that change you suggest.
Asumming nlk->netlink_bind(...) fails when 'group' is 0, then we have nothing to undo.
See netlink_undo_bind():
for (undo = 0; undo < group; undo++)
if (test_bit(undo, &groups))
nlk->netlink_unbind(sock_net(sk), undo + 1);
'undo' and 'group' will be both 0, so nothing is undone as expected.
So my patch seems good to me after second look. Let me know if you have more concerns, thanks.
From: Pablo Neira Ayuso <[email protected]>
Date: Thu, 29 Jan 2015 10:51:53 +0100
Quoted 9 lines
The subscription bitmask passed via struct
sockaddr_nlis converted to the group number when calling thenetlink_bind()andnetlink_unbind()callbacks.The conversion is however incorrect since bitmask (1 << 0) needs to be mapped to group number 1. Note that you cannot specify the group number 0 (usually known as
_NONE) fromsetsockopt()usingNETLINK_ADD_MEMBERSHIPsince this is rejected through-EINVAL.
Quoted 7 lines
This problem became noticeable since 97840cb ("netfilter: nfnetlink:
fix insufficient validation innfnetlink_bind") when binding to bitmask (1 << 0) in ctnetlink.Reported-by Andre Tomt <[email protected]>Reported-by Ivan Delalande <[email protected]>Signed-off-by Pablo Neira Ayuso <[email protected]>
Applied, thanks Pablo.