* [PATCH net] net: add validation for the socket syscall protocol argument
@ 2015-12-14 16:17 Hannes Frederic Sowa
2015-12-14 18:59 ` Cong Wang
2015-12-14 19:32 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Hannes Frederic Sowa @ 2015-12-14 16:17 UTC (permalink / raw)
To: netdev
郭永刚 reported that one could simply crash the kernel as root by
using a simple program:
int socket_fd;
struct sockaddr_in addr;
addr.sin_port = 0;
addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_family = 10;
socket_fd = socket(10,3,0x40000000);
connect(socket_fd , &addr,16);
AF_INET, AF_INET6 sockets actually only support 8-bit protocol
identifiers. inet_sock's skc_protocol field thus is sized accordingly,
thus larger protocol identifiers simply cut off the higher bits and
store a zero in the protocol fields.
This could lead to e.g. NULL function pointer because as a result of
the cut off inet_num is zero and we call down to inet_autobind, which
is NULL for raw sockets.
kernel: Call Trace:
kernel: [<ffffffff816db90e>] ? inet_autobind+0x2e/0x70
kernel: [<ffffffff816db9a4>] inet_dgram_connect+0x54/0x80
kernel: [<ffffffff81645069>] SYSC_connect+0xd9/0x110
kernel: [<ffffffff810ac51b>] ? ptrace_notify+0x5b/0x80
kernel: [<ffffffff810236d8>] ? syscall_trace_enter_phase2+0x108/0x200
kernel: [<ffffffff81645e0e>] SyS_connect+0xe/0x10
kernel: [<ffffffff81779515>] tracesys_phase2+0x84/0x89
I found no particular commit which introduced this problem.
CVE: CVE-2015-8543
Reported-by: 郭永刚 <guoyonggang@360.cn>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
---
net/ipv4/af_inet.c | 3 +++
net/ipv6/af_inet6.c | 3 +++
net/socket.c | 3 +++
3 files changed, 9 insertions(+)
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 11c4ca1..cfb4496 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -257,6 +257,9 @@ static int inet_create(struct net *net, struct socket *sock, int protocol,
int try_loading_module = 0;
int err;
+ if (protocol >= IPPROTO_MAX)
+ return -EINVAL;
+
sock->state = SS_UNCONNECTED;
/* Look for the requested type/protocol pair. */
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 8ec0df7..9fb093c 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -109,6 +109,9 @@ static int inet6_create(struct net *net, struct socket *sock, int protocol,
int try_loading_module = 0;
int err;
+ if (protocol >= IPPROTO_MAX)
+ return -EINVAL;
+
/* Look for the requested type/protocol pair. */
lookup_protocol:
err = -ESOCKTNOSUPPORT;
diff --git a/net/socket.c b/net/socket.c
index 456fadb..d2f3d49 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1098,6 +1098,9 @@ int __sock_create(struct net *net, int family, int type, int protocol,
return -EAFNOSUPPORT;
if (type < 0 || type >= SOCK_MAX)
return -EINVAL;
+ /* upper bound should be tested by per-protocol .create callbacks */
+ if (protocol < 0)
+ return -EINVAL;
/* Compatibility.
--
2.5.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] net: add validation for the socket syscall protocol argument
2015-12-14 16:17 [PATCH net] net: add validation for the socket syscall protocol argument Hannes Frederic Sowa
@ 2015-12-14 18:59 ` Cong Wang
2015-12-14 19:32 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Cong Wang @ 2015-12-14 18:59 UTC (permalink / raw)
To: Hannes Frederic Sowa; +Cc: netdev
On Mon, Dec 14, 2015 at 8:17 AM, Hannes Frederic Sowa
<hannes@stressinduktion.org> wrote:
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -1098,6 +1098,9 @@ int __sock_create(struct net *net, int family, int type, int protocol,
> return -EAFNOSUPPORT;
> if (type < 0 || type >= SOCK_MAX)
> return -EINVAL;
> + /* upper bound should be tested by per-protocol .create callbacks */
> + if (protocol < 0)
> + return -EINVAL;
Why? At least bt_sock_create() and netlink_create() do both upper bound
and lower bound checks.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] net: add validation for the socket syscall protocol argument
2015-12-14 16:17 [PATCH net] net: add validation for the socket syscall protocol argument Hannes Frederic Sowa
2015-12-14 18:59 ` Cong Wang
@ 2015-12-14 19:32 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2015-12-14 19:32 UTC (permalink / raw)
To: hannes; +Cc: netdev
From: Hannes Frederic Sowa <hannes@stressinduktion.org>
Date: Mon, 14 Dec 2015 17:17:49 +0100
> diff --git a/net/socket.c b/net/socket.c
> index 456fadb..d2f3d49 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -1098,6 +1098,9 @@ int __sock_create(struct net *net, int family, int type, int protocol,
> return -EAFNOSUPPORT;
> if (type < 0 || type >= SOCK_MAX)
> return -EINVAL;
> + /* upper bound should be tested by per-protocol .create callbacks */
> + if (protocol < 0)
> + return -EINVAL;
>
Please get rid of this part of your patch and resubmit, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-12-14 19:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-14 16:17 [PATCH net] net: add validation for the socket syscall protocol argument Hannes Frederic Sowa
2015-12-14 18:59 ` Cong Wang
2015-12-14 19:32 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).