Received: by 10.223.164.202 with SMTP id h10csp362164wrb; Wed, 15 Nov 2017 00:40:29 -0800 (PST) X-Google-Smtp-Source: AGs4zMbOye0poapeH5T1c35/2f9euT90bdqc9lMAkyAH+U5UdnD/mvePMkBxtA9z7GWiRbFvOp4U X-Received: by 10.99.95.194 with SMTP id t185mr14545044pgb.177.1510735229084; Wed, 15 Nov 2017 00:40:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510735229; cv=none; d=google.com; s=arc-20160816; b=ZYu3W+qmNWh2xKxOIGihwzAO/uRbFtBa4uaPO1C/ygBlPyTlT51pI0BqVlJHTWqf8E RZ/x25sRlUqCuWlZN72UarhxhtjmR/3pKuISGYZ6oF3pM5oK1Po7TgjaI0NgW3/5qZNw SlNuLLMoqGezRv2RvWFY3UZuFKtEPljgfxNc4ZoZfwpgeETsPyav0JU8xSm4wkAAb/5L WTFHIEc9fkJeT7lDz5SnWMAstU+HiPQgVGqSQYmZy13r4BhbRbZBcJESvyTri2uUG8GP i75/L7+GMgNWACY/VJ9PFGPPEzD96tAdVqAmZ2IcTNGfT2hL/N24XBSHVCjC5cR8x25X xpdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=IcJf52V1Be4aiGnK5ltQuOAKk+oeFx1gVQstWJ070WI=; b=kSI+VQktwOYG0mFAwBHZQAdvFoDzeyMFqyDztK6XeLuwQi67NlKUNo5mzG+oHV5fiX iGEzJapEWJq5udH2PBJVd1+78WHLIuPq2GwIvk9MldO6G546rSc/6MqqJAGClrTaMCp7 SMhnzcCMSBpYko/43kea57sw5pgfT7oduCuTNxPXi/9wIZvjpFgKcHWbZVeZi66CFkR8 9g4J81BHQcNP2chH2iN5/4QOGxPbv7XtLGZZ5J3kEPuouDuFZitVlNWAwQSHvG3GwDBb PMCpOUmwBRd6hoLh3PqIV7jc629P3P2S6QvQD8ooPNvhzLajGxXkbkUDiKkGG3cIYaIB WXmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=esbPQUHN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m189si5168657pfc.373.2017.11.15.00.40.16; Wed, 15 Nov 2017 00:40:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=esbPQUHN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757011AbdKOIWs (ORCPT + 88 others); Wed, 15 Nov 2017 03:22:48 -0500 Received: from mail-vk0-f67.google.com ([209.85.213.67]:55996 "EHLO mail-vk0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756335AbdKOIWl (ORCPT ); Wed, 15 Nov 2017 03:22:41 -0500 Received: by mail-vk0-f67.google.com with SMTP id b7so13892872vkh.12 for ; Wed, 15 Nov 2017 00:22:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=IcJf52V1Be4aiGnK5ltQuOAKk+oeFx1gVQstWJ070WI=; b=esbPQUHNoD0O7bwUGiv4gIudRknt5xMpBlwUUzSHpdlT7oT69mEZQwqS5RRwZ/G8dP YXDUF74e4PFT7t0klpLrhIAciLxkebZpyza9dYLF57T5xmgdQaYgKXwNCqef2PYSp+g4 6tpeo3Irrt3srBR05qY7mihrCHp9BkIlXR7YggrcioTkv+DUh7TmJ4s2S1NocqK7t6b4 56x42mu2oN/5kP1moNjQIPtmKQcINJ3P+WveUvTKgMQFxwa4PRciirT/0A1TD4VlyjjQ Mw0a6PBVjnSjMlp5TXxaiRkVfPFu3vcK0r09FoReCVvywwz6MYY5+81GYXoGip1MQRvi TfJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=IcJf52V1Be4aiGnK5ltQuOAKk+oeFx1gVQstWJ070WI=; b=DkpawFQjkOIewq/o4jARNSdbK4rA794cft3xEitYhgKYG04ntGYz3ucejVtO56HpP0 12IvIduseVRyDlfnH/OCpSsJ95bphX0O1wiwAoNNKvNG8hsSasNpLXI1PYP5fVI2G0h5 V4VIVJL7LimUEr8vspKvTTJ9J9DtH7Yt7yxRZqpPSOhTKQDHdVjM8AVioxaqYp/KfTUu Do8pFTwE13QbLq0DFcQcrgmBQkvWitNV5N4hUMkqxAJt/UwDwJpoHArVbSCN51Eq0DcY P++1ZXqAT8WnNpPvw0fh6jhMCHSmYkAQS3KVCshzNExzrZdUdJLunZ9BfL95a8RhcnzP o+SA== X-Gm-Message-State: AJaThX4jYOkU7dy2sh/iR6/ra5ncS5ZOxhFXY/+rdGxfSWoxyG9V8fNw zIrbRlzTa5vwWTzDchC/dkkN6TXjoofOZXcQVxknHw== X-Received: by 10.31.158.140 with SMTP id h134mr11105659vke.169.1510734160668; Wed, 15 Nov 2017 00:22:40 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.70.147 with HTTP; Wed, 15 Nov 2017 00:22:39 -0800 (PST) In-Reply-To: References: <20171031161445.GA140874@beast> <1509471094.3828.26.camel@edumazet-glaptop3.roam.corp.google.com> <871slikvvf.fsf@xmission.com> From: Alexander Potapenko Date: Wed, 15 Nov 2017 09:22:39 +0100 Message-ID: Subject: Re: [PATCH] net: recvmsg: Unconditionally zero struct sockaddr_storage To: Kees Cook Cc: "Eric W. Biederman" , Eric Dumazet , "David S. Miller" , Kostya Serebryany , Andrey Konovalov , Eric Dumazet , Network Development , LKML , security@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 1, 2017 at 7:23 PM, Kees Cook wrote: > On Wed, Nov 1, 2017 at 5:48 AM, Eric W. Biederman = wrote: >> Eric Dumazet writes: >> >>> 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 befo= re >>>> per-protocol handlers run. >>>> >>>> Note that leaks like this are mitigated by building with >>>> CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL=3Dy >>>> >>>> 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, s= truct user_msghdr __user *msg, >>>> struct sockaddr __user *uaddr; >>>> int __user *uaddr_len =3D COMPAT_NAMELEN(msg); >>>> >>>> + memset(&addr, 0, sizeof(addr)); >>>> msg_sys->msg_name =3D &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 store= s >>> 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. >> >> In this case it looks like the root cause is something in sctp >> not filling in the ipv6 sin6_scope_id. >> >> Which is not only a leak but a correctness bug. >> >> I ran the reproducer test program and while none of the leak checkers >> are telling me anything I have gotten as far as seeing that the returned >> length is correct and sometimes nonsense. >> >> Hmm. >> >> At a quick look it looks like all that is necessary is to do this: >> >> diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c >> index 51c488769590..6301913d0516 100644 >> --- a/net/sctp/ipv6.c >> +++ b/net/sctp/ipv6.c >> @@ -807,9 +807,10 @@ static void sctp_inet6_skb_msgname(struct sk_buff *= skb, char *msgname, >> addr->v6.sin6_flowinfo =3D 0; >> addr->v6.sin6_port =3D sh->source; >> addr->v6.sin6_addr =3D ipv6_hdr(skb)->saddr; >> - if (ipv6_addr_type(&addr->v6.sin6_addr) & IPV6_ADDR_LINK= LOCAL) { >> + if (ipv6_addr_type(&addr->v6.sin6_addr) & IPV6_ADDR_LINK= LOCAL) >> addr->v6.sin6_scope_id =3D sctp_v6_skb_iif(skb); >> - } >> + else >> + addr->v6.sin6_scope_id =3D 0; >> } >> >> *addr_len =3D sctp_v6_addr_to_user(sctp_sk(skb->sk), addr); >> >> Eric >> > > Thanks for digging into this Eric! Alexander, can you confirm this > fixes it for you when CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL is not > enabled? Sorry, I accidentally missed this patch. Yes, I confirm it fixes the problem with CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL disabled. > -Kees > > -- > Kees Cook > Pixel Security --=20 Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Stra=C3=9Fe, 33 80636 M=C3=BCnchen Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg From 1584097415917813656@xxx Wed Nov 15 02:30:20 +0000 2017 X-GM-THRID: 1582790393599156539 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread