Subject: [PATCH] ipv4/ip_sockglue.c: copy msg_control optval from user to kernel space

From: H Hartley Sweeten <[email-masked]>
Date: Fri, 15 Jan 2010 10:24:59 -0700

ipv4/ip_sockglue.c: copy msg_control optval from user to kernel space

In do_ip_getsockopt the char __user *optval is used directly in
IP_PKTOPTIONS for the msg.msg_control and not copied from
user to kernel address space. This produces a sparse warning:

warning: incorrect type in assignment (different address spaces)
   expected void *msg_control
   got char [noderef] <asn:1>*optval

Fix this by using copy _from_user to set msg.msg_control.

Signed-off-by: H Hartley Sweeten <[email-masked]>
Cc: David S. Miller <[email-masked]>
Cc: Alexey Kuznetsov <[email-masked]>
Cc: "Pekka Savola (ipv6)" <[email-masked]>
Cc: James Morris <[email-masked]>
Cc: Hideaki YOSHIFUJI <[email-masked]>
Cc: Patrick McHardy <[email-masked]>

---

diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index cafad9b..8065456 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -1173,7 +1173,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
 		if (sk->sk_type != SOCK_STREAM)
 			return -ENOPROTOOPT;
 
-		msg.msg_control = optval;
+		if (copy_from_user(msg.msg_control, optval, len))
+			return -EFAULT;
 		msg.msg_controllen = len;
 		msg.msg_flags = 0;