Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp226794pxa; Fri, 31 Jul 2020 10:22:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrJNbLgsvT1WWzuzbOP8XvcktYtDDn0ds4SR/zs2ZDj9WV1I6qUIAaSUYKpkM8nddipGIH X-Received: by 2002:aa7:c513:: with SMTP id o19mr4802860edq.327.1596216129366; Fri, 31 Jul 2020 10:22:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596216129; cv=none; d=google.com; s=arc-20160816; b=tJz4gCeniZN+4mHuw86mgYSOh7xRy08g3YNC6Zll3uI3+88ib3wo9zrY/Mzz8mTHba eSK3/LLWZUa+mRVcPmGkwqEIv8sIU073/tdI+7fTRd68nJpB1ZCtTuMhk5YNKXBUh05a UYXbCktPVlUcxi/bBhhliakZALmx0pCzFtz7fgnIlIimnH2wWh0pNX44Bq7N+vq/xqpm bwUw47+0XV21kG5v7e4Hins5c3VXpjQ7NNzTDLDI8eytaaw9YT1G4kAv+LmTCBPKgShd ZNvzsSX90g7f8WSY+PNnKLK/PfKZHOtfi5eKTs/3VRe4Q8dMqFAw9Z51NWb8Qu0jmFDh OIyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=9KpVVW2sw+T8nIP4be9zcEyS+gfSRcQ+b0GpXcAWzsk=; b=OPQZWw3djYCJrL+vDgeMFr8yON7pf8AQ6L0FXRIV71Q3afDjGA32HoyN90IUtjz7Fd OKB8Y+uBUYJlbczq3Ti0jSQGeBE6/8dHhP2RFOkc7WEfez6nOxsqNB4xdkWkxq7GkxrU AiCuLmTN1n78lhvwua4zzp8VjoVJ3p3Lct2Z/+H1zBugRqkxQQYTKIwQ+FB7z9yQVbIs G3O8QB7Y6ZASbGdR5TOER8OSGcrbCHe+UQfD/q3xRcrjaE5KnfOSrmbvwlPOdB8QvF4r LX1+RGV/OLI6sgoahBT6xSDjl5+Zkk6C3MT/8SC68aJ7cOq5kaohJlahtKBvrwLQ0WAA kanw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FJM6T0vb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id um11si5415743ejb.117.2020.07.31.10.21.46; Fri, 31 Jul 2020 10:22:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FJM6T0vb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733256AbgGaRTj (ORCPT + 99 others); Fri, 31 Jul 2020 13:19:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:40772 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732817AbgGaRTi (ORCPT ); Fri, 31 Jul 2020 13:19:38 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6645C2074B; Fri, 31 Jul 2020 17:19:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596215978; bh=yxLFBtERe8UngePE6Ae91aGE2Ev7MNPNAO2x8RUFAKY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FJM6T0vbEgq2PNNmTnnc65DNz/A50UbgHexnPy4ZP95gE8ClTSvPshL0drR9tvoqC Luj0SVJLc7CMxudDRUS2o57mBQ75nNh6SFidxxegIkiPaZrRJZtpzWaTW8Rc+03Jfz XCdf00Knp7UBGQTGQpqSCFA9Dz+RfqVPF4vs9i0M= Date: Fri, 31 Jul 2020 19:19:24 +0200 From: Greg Kroah-Hartman To: Jason Gunthorpe Cc: Leon Romanovsky , Peilin Ye , Santosh Shilimkar , "David S. Miller" , Jakub Kicinski , Dan Carpenter , Arnd Bergmann , linux-kernel-mentees@lists.linuxfoundation.org, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, rds-devel@oss.oracle.com, linux-kernel@vger.kernel.org Subject: Re: [Linux-kernel-mentees] [PATCH net] rds: Prevent kernel-infoleak in rds_notify_queue_get() Message-ID: <20200731171924.GA2014207@kroah.com> References: <20200730192026.110246-1-yepeilin.cs@gmail.com> <20200731045301.GI75549@unreal> <20200731053306.GA466103@kroah.com> <20200731053333.GB466103@kroah.com> <20200731140452.GE24045@ziepe.ca> <20200731142148.GA1718799@kroah.com> <20200731143604.GF24045@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200731143604.GF24045@ziepe.ca> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 31, 2020 at 11:36:04AM -0300, Jason Gunthorpe wrote: > On Fri, Jul 31, 2020 at 04:21:48PM +0200, Greg Kroah-Hartman wrote: > > > > The spec was updated in C11 to require zero'ing padding when doing > > > partial initialization of aggregates (eg = {}) > > > > > > """if it is an aggregate, every member is initialized (recursively) > > > according to these rules, and any padding is initialized to zero > > > bits;""" > > > > But then why does the compilers not do this? > > Do you have an example? At the moment, no, but we have had them in the past due to security issues we have had to fix for this. > > > Considering we have thousands of aggregate initializers it > > > seems likely to me Linux also requires a compiler with this C11 > > > behavior to operate correctly. > > > > Note that this is not an "operate correctly" thing, it is a "zero out > > stale data in structure paddings so that data will not leak to > > userspace" thing. > > Yes, not being insecure is "operate correctly", IMHO :) > > > > Does this patch actually fix anything? My compiler generates identical > > > assembly code in either case. > > > > What compiler version? > > I tried clang 10 and gcc 9.3 for x86-64. > > #include > > void test(void *out) > { > struct rds_rdma_notify { > unsigned long user_token; > unsigned int status; > } foo = {}; > memcpy(out, &foo, sizeof(foo)); > } > > $ gcc -mno-sse2 -O2 -Wall -std=c99 t.c -S > > test: > endbr64 > movq $0, (%rdi) > movq $0, 8(%rdi) > ret > > Just did this same test with gcc 4.4 and it also gave the same output.. > > Made it more complex with this: > > struct rds_rdma_notify { > unsigned long user_token; > unsigned char status; > unsigned long user_token1; > unsigned char status1; > unsigned long user_token2; > unsigned char status2; > unsigned long user_token3; > unsigned char status3; > unsigned long user_token4; > unsigned char status4; > } foo; > > And still got the same assembly vs memset on gcc 4.4. > > I tried for a bit and didn't find a way to get even old gcc 4.4 to not > initialize the holes. Odd, so it is just the "= {0};" that does not zero out the holes? thanks, greg k-h