ipv4/ip_sockglue.c: copy msg_control optval from user to kernel space
Subsystems (3)
PATCH 1/1 ipv4/ip_sockglue.c: copy msg_control optval from user to kernel space
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.
---
net/ipv4/ip_sockglue.c +2 -1
@@ -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 ;
David Miller
maintainerFrom: H Hartley Sweeten <[email protected]>
Date: Fri, 15 Jan 2010 10:24:59 -0700
Quoted 6 lines
ipv4/ip_sockglue.c: copymsg_controloptval from user to kernel spaceIn
do_ip_getsockoptthe char__user*optval is used directly inIP_PKTOPTIONSfor the msg.msg_control and not copied from user to kernel address space. This produces a sparse warning:
Quoted 7 lines
warning: incorrect type in assignment (different address spaces)
expected void*msg_control
got char [noderef] <asn:1>*optvalFix this by using copy
_from_userto set msg.msg_control.Signed-off-by H Hartley Sweeten <[email protected]>
This isn't right.
We want the 'optval' pointer itself, not the data it points to, stored in msg.msg_control
And 'msg_control' is, in this case a user pointer.
It just isn't annotated (along with the rest of struct msghdr) with "__user" because we mix the usage of this object with kernel and user pointers.
How did you test your change?
A message that is not in the archive (sent off-list or not yet received): [email protected]
David Miller
maintainerFrom: "H Hartley Sweeten" <[email protected]>
Date: Sat, 16 Jan 2010 01:22:21 -0500
Quoted 6 lines · David Miller
Quoted 1 line
How did you test your change?
Hmm... I saw the sparse warning and tried this to fix it. The code compiled fine and the warning was gone. When I booted the resulting kernel I didn't see any issues. I must not have went down this code path in my testing.
I'm going to ask you a second time.
What was your test case? How did you test the change?
I don't think you tested your change at all besides seeing that gcc would accept the code and sparse stopped spitting out a warning. And you're vagueness about your testing methodology will only work to confirm my suspicions.
I find it unlikely, at best, for you to have tested that code path, as 'msg' is an uninitilized stack variable at this point in the code, so 'msg->msg_control' is going to be a garbage pointer, and therefore copying to it would result in a crash.
I don't even think you read and understood the code you are editing.
I suspect you just wanted to kill the sparse warning somehow, you found a way that made the compiler and sparse eat it, and you simply ran with it.
And that really upsets me.
Fixing sparse warnings should not be a mindless exercise. You should understand the code you are changing.