From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753881AbdJaRbj (ORCPT ); Tue, 31 Oct 2017 13:31:39 -0400 Received: from mail-io0-f194.google.com ([209.85.223.194]:55005 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752335AbdJaRbh (ORCPT ); Tue, 31 Oct 2017 13:31:37 -0400 X-Google-Smtp-Source: ABhQp+Tvdffiyq4XfNTae35IY+kLMrNxtco3pdArZkVH/xK+HaXJKEhWSXT8oa3tfpHsowjgOLdIeA== Message-ID: <1509471094.3828.26.camel@edumazet-glaptop3.roam.corp.google.com> Subject: Re: [PATCH] net: recvmsg: Unconditionally zero struct sockaddr_storage From: Eric Dumazet To: Kees Cook Cc: "David S. Miller" , Alexander Potapenko , Kostya Serebryany , Andrey Konovalov , Eric Dumazet , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, security@kernel.org Date: Tue, 31 Oct 2017 10:31:34 -0700 In-Reply-To: <20171031161445.GA140874@beast> References: <20171031161445.GA140874@beast> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2017-10-31 at 09:14 -0700, Kees Cook wrote: > Some protocols do not correctly wipe the contents of the on-stack > struct sockaddr_storage sent down into recvmsg() (e.g. SCTP), and leak > kernel stack contents to userspace. This wipes it unconditionally before > per-protocol handlers run. > > Note that leaks like this are mitigated by building with > CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL=y > > Reported-by: Alexander Potapenko > Cc: "David S. Miller" > Cc: netdev@vger.kernel.org > Signed-off-by: Kees Cook > --- > net/socket.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/net/socket.c b/net/socket.c > index c729625eb5d3..34183f4fbdf8 100644 > --- a/net/socket.c > +++ b/net/socket.c > @@ -2188,6 +2188,7 @@ static int ___sys_recvmsg(struct socket *sock, struct user_msghdr __user *msg, > struct sockaddr __user *uaddr; > int __user *uaddr_len = COMPAT_NAMELEN(msg); > > + memset(&addr, 0, sizeof(addr)); > msg_sys->msg_name = &addr; > This kind of patch comes every year. Standard answer is : We fix the buggy protocol, we do not make everything slower just because we are lazy. struct sockaddr is 128 bytes, but IPV4 only uses a fraction of it. Also memset() is using long word stores, so next 4-byte or 2-byte stores on same location hit a performance problem on x86. By adding all these defensive programming, we would give strong incentives to bypass the kernel for networking. That would be bad.