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

From: Baozeng Ding <[email-masked]>
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 <[email-masked]>
---
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(-)

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();
-- 
1.9.1