netlink: fix null pointer dereference on nlk->groups
Subsystems (2)
PATCH 1/1 netlink: fix null pointer dereference on nlk->groups
If groups is not 0 and nlk->groups is NULL, it will not return immediately and cause a null pointer dereference later.
--- net/netlink/af_netlink.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
net/netlink/af_netlink.c +7 -3
@@ -1524,6 +1524,7 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr,int err;long unsigned int groups = nladdr->nl_groups;bool bound; +unsigned long nlgroups;if (addr_len <sizeof (struct sockaddr_nl ))return -EINVAL ;
@@ -1576,14 +1577,17 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr, } } -if (!groups && (nlk->groups ==NULL || !(u32 )nlk->groups[0 ])) +if (nlk->groups ==NULL ) +return 0 ; + nlgroups = nlk->groups[0 ]; +if (!groups && !(u32 )nlgroups)return 0 ;netlink_table_grab ();netlink_update_subscriptions (sk, nlk->subscriptions +hweight32 (groups) - -hweight32 (nlk->groups[0 ])); - nlk->groups[0 ] = (nlk->groups[0 ] & ~0xffffffffUL ) | groups; +hweight32 (nlgroups)); + nlk->groups[0 ] = (nlgroups & ~0xffffffffUL ) | groups;netlink_update_listeners (sk);netlink_table_ungrab ();
Signature · 1 line
1.9.1
Hello.
Quoted 12 lines · Baozeng Ding
If groups is not 0 and
nlk->groupsis NULL, it will not return immediately and cause a null pointer dereference later.Signed-off-by Baozeng Ding <[email protected]>--- net/netlink/af_netlink.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)net/netlink/af_netlink.c +0
-0
[...]
net/netlink/af_netlink.c static int netlink_bind(struct socket *sock, struct sockaddr *addr, · line 1580
Quoted 6 lines
net/netlink/af_netlink.c +1
-1@@ -1576,14 +1577,17 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr, } } -if (!groups && (nlk->groups ==NULL || !(u32 )nlk->groups[0 ])) +if (nlk->groups ==NULL )
'!nlk->groups' is preferred in the networking code.
[...]
MBR, Sergei
PATCH v2 1/1 netlink: fix null pointer dereference on nlk->groups
In reply to Baozeng DingIf groups is not 0 and nlk->groups is NULL, it will not return immediately and cause a null pointer dereference later.
---
This version uses the preferred networking coding style. Thanks for Sergei's feedback. Also the patch keeps the original author's coding style as much as possible.
--- net/netlink/af_netlink.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/netlink/af_netlink.c +4 -1
@@ -1576,7 +1576,10 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr, } } -if (!groups && (nlk->groups ==NULL || !(u32 )nlk->groups[0 ])) +if (!nlk->groups) +return 0 ; + +if (!groups && !(u32 )nlk->groups[0 ])return 0 ;netlink_table_grab ();
Signature · 1 line
1.9.1
David Miller
maintainerFrom: Baozeng Ding <[email protected]>
Date: Sat, 9 Jan 2016 23:56:41 +0800
Quoted 8 lines
If groups is not 0 and
nlk->groupsis NULL, it will not return immediately and cause a null pointer dereference later.Signed-off-by Baozeng Ding <[email protected]>---
This version uses the preferred networking coding style. Thanks for Sergei's feedback. Also the patch keeps the original author's coding style as much as possible.
Is this an actual legal state? If not, add a WARN_ON() check.
Otherwise, provide a proper OOPS log and explain how the state can be achieved.
Thanks.
PATCH v3 1/1 netlink: fix null pointer dereference on nlk->groups
In reply to Baozeng DingIf groups is not 0 and nlk->groups is NULL, it will not return immediately and cause a null pointer dereference later.
---
The v3 version adds WARN_ON, suggested by David Miller. Thanks for David's feedback.
--- net/netlink/af_netlink.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/netlink/af_netlink.c +4 -1
@@ -1576,7 +1576,10 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr, } } -if (!groups && (nlk->groups ==NULL || !(u32 )nlk->groups[0 ])) +if (WARN_ON (!nlk->groups)) +return 0 ; + +if (!groups && !(u32 )nlk->groups[0 ])return 0 ;netlink_table_grab ();
Signature · 1 line
1.9.1
Quoted 7 lines · Baozeng Ding
If groups is not 0 and
nlk->groupsis NULL, it will not return immediately and cause a null pointer dereference later.Signed-off-by Baozeng Ding <[email protected]>---
The v3 version addsWARN_ON, suggested by David Miller. Thanks for David's feedback.
But can you explain how can we get to this situation?
Quoted 25 lines
--- net/netlink/af_netlink.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/netlink/af_netlink.c +4
-1@@ -1576,7 +1576,10 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr, } } -if (!groups && (nlk->groups ==NULL || !(u32 )nlk->groups[0 ])) +if (WARN_ON (!nlk->groups)) +return 0 ; + +if (!groups && !(u32 )nlk->groups[0 ])return 0 ;
netlink_table_grab();
--
1.9.1
Quoted 10 lines · Denis Kirjanov
Quoted 7 lines · Baozeng Ding
If groups is not 0 and
nlk->groupsis NULL, it will not return immediately and cause a null pointer dereference later.Signed-off-by Baozeng Ding <[email protected]>---
The v3 version addsWARN_ON, suggested by David Miller. Thanks for David's feedback.But can you explain how can we get to this situation?
Indeed, this patch makes no sense as it stands. If groups is not NULL, then we should have allocated nlk->groups prior to reaching this point. If that allocation failed, then we should have already bailed out long ago. Perhaps we have a race condition that needs to be closed with a lock?
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
David Miller
maintainerFrom: Baozeng Ding <[email protected]>
Date: Tue, 12 Jan 2016 19:10:43 +0800
Quoted 7 lines
If groups is not 0 and
nlk->groupsis NULL, it will not return immediately and cause a null pointer dereference later.Signed-off-by Baozeng Ding <[email protected]>---
The v3 version addsWARN_ON, suggested by David Miller. Thanks for David's feedback.
My feedback was also that the situation is illegal, and therefore you have to explain to us how this can actually occur.