diff mbox

[v2] netlink: fix null pointer dereference on nlk->groups

Message ID 1452355001-30295-1-git-send-email-sploving1@gmail.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Baozeng Ding Jan. 9, 2016, 3:56 p.m. UTC
If groups is not 0 and nlk->groups is NULL, it will not return
immediately and cause a null pointer dereference later.

Signed-off-by: Baozeng Ding <sploving1@gmail.com>
---
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(-)

Comments

David Miller Jan. 11, 2016, 4:27 a.m. UTC | #1
From: Baozeng Ding <sploving1@gmail.com>
Date: Sat,  9 Jan 2016 23:56:41 +0800

> If groups is not 0 and nlk->groups is NULL, it will not return
> immediately and cause a null pointer dereference later.
> 
> Signed-off-by: Baozeng Ding <sploving1@gmail.com>
> ---
> 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.
diff mbox

Patch

diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 59651af..eeff14a 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -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();