diff options
author | Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | 2011-08-24 22:45:03 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-08-24 22:45:03 -0400 |
commit | bc909d9ddbf7778371e36a651d6e4194b1cc7d4c (patch) | |
tree | 45fb13261b012c61a64713ee13f5c7fe60a046dd /net/socket.c | |
parent | c6f59d13e24187ff95427a9f4a5a7e14fb8faf5a (diff) |
sendmmsg/sendmsg: fix unsafe user pointer access
Dereferencing a user pointer directly from kernel-space without going
through the copy_from_user family of functions is a bad idea. Two of
such usages can be found in the sendmsg code path called from sendmmsg,
added by
commit c71d8ebe7a4496fb7231151cb70a6baa0cb56f9a upstream.
commit 5b47b8038f183b44d2d8ff1c7d11a5c1be706b34 in the 3.0-stable tree.
Usages are performed through memcmp() and memcpy() directly. Fix those
by using the already copied msg_sys structure instead of the __user *msg
structure. Note that msg_sys can be set to NULL by verify_compat_iovec()
or verify_iovec(), which requires additional NULL pointer checks.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: David Goulet <dgoulet@ev0ke.net>
CC: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
CC: Anton Blanchard <anton@samba.org>
CC: David S. Miller <davem@davemloft.net>
CC: stable <stable@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/socket.c')
-rw-r--r-- | net/socket.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/net/socket.c b/net/socket.c index 24a77400b65e..ffe92ca32f2a 100644 --- a/net/socket.c +++ b/net/socket.c | |||
@@ -1965,8 +1965,9 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg, | |||
1965 | * used_address->name_len is initialized to UINT_MAX so that the first | 1965 | * used_address->name_len is initialized to UINT_MAX so that the first |
1966 | * destination address never matches. | 1966 | * destination address never matches. |
1967 | */ | 1967 | */ |
1968 | if (used_address && used_address->name_len == msg_sys->msg_namelen && | 1968 | if (used_address && msg_sys->msg_name && |
1969 | !memcmp(&used_address->name, msg->msg_name, | 1969 | used_address->name_len == msg_sys->msg_namelen && |
1970 | !memcmp(&used_address->name, msg_sys->msg_name, | ||
1970 | used_address->name_len)) { | 1971 | used_address->name_len)) { |
1971 | err = sock_sendmsg_nosec(sock, msg_sys, total_len); | 1972 | err = sock_sendmsg_nosec(sock, msg_sys, total_len); |
1972 | goto out_freectl; | 1973 | goto out_freectl; |
@@ -1978,8 +1979,9 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg, | |||
1978 | */ | 1979 | */ |
1979 | if (used_address && err >= 0) { | 1980 | if (used_address && err >= 0) { |
1980 | used_address->name_len = msg_sys->msg_namelen; | 1981 | used_address->name_len = msg_sys->msg_namelen; |
1981 | memcpy(&used_address->name, msg->msg_name, | 1982 | if (msg_sys->msg_name) |
1982 | used_address->name_len); | 1983 | memcpy(&used_address->name, msg_sys->msg_name, |
1984 | used_address->name_len); | ||
1983 | } | 1985 | } |
1984 | 1986 | ||
1985 | out_freectl: | 1987 | out_freectl: |