From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8FDDC433E0 for ; Fri, 31 Jul 2020 17:19:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B67CE22B3F for ; Fri, 31 Jul 2020 17:19:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596215979; bh=yxLFBtERe8UngePE6Ae91aGE2Ev7MNPNAO2x8RUFAKY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=rAK9oys56z5iFisNaNGr92gKsrthDI2+M5XFJqQpZ/77ugbvavBtBufGwb4eBdpyw o+wJVzISESTLNmw0diG5KfXtMG6gEFNJcEhkIn0z8yqfrB4EfSW6p181JHMdTsjH2g GXDgEozcJmyGnp/EwflnJ54o8IUZQDeeNwPKTHos= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732988AbgGaRTj (ORCPT ); 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-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3421EC433DF for ; Fri, 31 Jul 2020 17:19:41 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 01FD722B3F for ; Fri, 31 Jul 2020 17:19:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="FJM6T0vb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 01FD722B3F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-kernel-mentees-bounces@lists.linuxfoundation.org Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id D2C4E863DC; Fri, 31 Jul 2020 17:19:40 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id r823OyOhb2po; Fri, 31 Jul 2020 17:19:39 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 9FECA8636D; Fri, 31 Jul 2020 17:19:39 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 96129C0050; Fri, 31 Jul 2020 17:19:39 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id DE763C004D for ; Fri, 31 Jul 2020 17:19:38 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id C8915214E9 for ; Fri, 31 Jul 2020 17:19:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id I8f-KChUfyhd for ; Fri, 31 Jul 2020 17:19:38 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by silver.osuosl.org (Postfix) with ESMTPS id 34E802107F for ; Fri, 31 Jul 2020 17:19:38 +0000 (UTC) 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 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-Disposition: inline In-Reply-To: <20200731143604.GF24045@ziepe.ca> Cc: rds-devel@oss.oracle.com, Arnd Bergmann , Leon Romanovsky , linux-rdma@vger.kernel.org, netdev@vger.kernel.org, Santosh Shilimkar , linux-kernel@vger.kernel.org, "David S. Miller" , Jakub Kicinski , linux-kernel-mentees@lists.linuxfoundation.org, Peilin Ye , Dan Carpenter Subject: Re: [Linux-kernel-mentees] [PATCH net] rds: Prevent kernel-infoleak in rds_notify_queue_get() X-BeenThere: linux-kernel-mentees@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-kernel-mentees-bounces@lists.linuxfoundation.org Sender: "Linux-kernel-mentees" 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 _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees