Patchwork net: pre-clear the returned sockaddr_storage variable

login
register
mail settings
Submitter Kees Cook
Date April 9, 2013, 5:50 p.m.
Message ID <20130409175024.GA19308@www.outflux.net>
Download mbox | patch
Permalink /patch/235150/
State Rejected
Delegated to: David Miller
Headers show

Comments

Kees Cook - April 9, 2013, 5:50 p.m.
To avoid future stack content leaks in the various protocols, pre-clear
the returned memory.

Signed-off-by: Kees Cook <keescook@chromium.org>
Suggested-by: Brad Spengler <spender@grsecurity.net>
---
 net/socket.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Eric Dumazet - April 9, 2013, 6:10 p.m.
On Tue, 2013-04-09 at 10:50 -0700, Kees Cook wrote:
> To avoid future stack content leaks in the various protocols, pre-clear
> the returned memory.
> 
> Signed-off-by: Kees Cook <keescook@chromium.org>
> Suggested-by: Brad Spengler <spender@grsecurity.net>
> ---
>  net/socket.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/socket.c b/net/socket.c
> index 88f759a..4d2af0d 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -1838,7 +1838,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
>  	struct socket *sock;
>  	struct iovec iov;
>  	struct msghdr msg;
> -	struct sockaddr_storage address;
> +	struct sockaddr_storage address = { };
>  	int err, err2;
>  	int fput_needed;
>  
> @@ -2185,7 +2185,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
>  	int err, total_len, len;
>  
>  	/* kernel mode address */
> -	struct sockaddr_storage addr;
> +	struct sockaddr_storage addr = { };
>  
>  	/* user mode address pointers */
>  	struct sockaddr __user *uaddr;
> -- 
> 1.7.9.5
> 
> 

Nack, for obvious performance reasons.



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller - April 9, 2013, 7:05 p.m.
From: Kees Cook <keescook@chromium.org>
Date: Tue, 9 Apr 2013 10:50:24 -0700

> To avoid future stack content leaks in the various protocols, pre-clear
> the returned memory.
> 
> Signed-off-by: Kees Cook <keescook@chromium.org>
> Suggested-by: Brad Spengler <spender@grsecurity.net>

No thanks, clearing 2 full cache lines unnecessarily on every socket
call has real cost.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/net/socket.c b/net/socket.c
index 88f759a..4d2af0d 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1838,7 +1838,7 @@  SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
 	struct socket *sock;
 	struct iovec iov;
 	struct msghdr msg;
-	struct sockaddr_storage address;
+	struct sockaddr_storage address = { };
 	int err, err2;
 	int fput_needed;
 
@@ -2185,7 +2185,7 @@  static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
 	int err, total_len, len;
 
 	/* kernel mode address */
-	struct sockaddr_storage addr;
+	struct sockaddr_storage addr = { };
 
 	/* user mode address pointers */
 	struct sockaddr __user *uaddr;