4e6258a
From 95baa60a0da80a0143e3ddd4d3725758b4513825 Mon Sep 17 00:00:00 2001
4e6258a
From: Gen Zhang <blackgod016574@gmail.com>
4e6258a
Date: Fri, 24 May 2019 11:19:46 +0800
4e6258a
Subject: ipv6_sockglue: Fix a missing-check bug in ip6_ra_control()
4e6258a
4e6258a
In function ip6_ra_control(), the pointer new_ra is allocated a memory
4e6258a
space via kmalloc(). And it is used in the following codes. However,
4e6258a
when there is a memory allocation error, kmalloc() fails. Thus null
4e6258a
pointer dereference may happen. And it will cause the kernel to crash.
4e6258a
Therefore, we should check the return value and handle the error.
4e6258a
4e6258a
Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
4e6258a
Signed-off-by: David S. Miller <davem@davemloft.net>
4e6258a
---
4e6258a
 net/ipv6/ipv6_sockglue.c | 2 ++
4e6258a
 1 file changed, 2 insertions(+)
4e6258a
4e6258a
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
4e6258a
index 40f21fef25ff..0a3d035feb61 100644
4e6258a
--- a/net/ipv6/ipv6_sockglue.c
4e6258a
+++ b/net/ipv6/ipv6_sockglue.c
4e6258a
@@ -68,6 +68,8 @@ int ip6_ra_control(struct sock *sk, int sel)
4e6258a
 		return -ENOPROTOOPT;
4e6258a
 
4e6258a
 	new_ra = (sel >= 0) ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL;
4e6258a
+	if (sel >= 0 && !new_ra)
4e6258a
+		return -ENOMEM;
4e6258a
 
4e6258a
 	write_lock_bh(&ip6_ra_lock);
4e6258a
 	for (rap = &ip6_ra_chain; (ra = *rap) != NULL; rap = &ra->next) {
4e6258a
-- 
4e6258a
cgit 1.2-0.3.lf.el7
4e6258a