Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1708542pxv; Fri, 23 Jul 2021 15:24:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwR74FjWS0hXYsPbIYXDVzBukm8Rx7o9lC6+kggrF6Fm3NIX8cVDPSnGhJST2d2wRMp/hvH X-Received: by 2002:a50:8d54:: with SMTP id t20mr7793836edt.288.1627079099291; Fri, 23 Jul 2021 15:24:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627079099; cv=none; d=google.com; s=arc-20160816; b=A72J0IQycHCvKAZE08wLNVEO8msbZBoQWJs7V7N5awFvbB9NWxjkxsWPiRV/pjuGi1 Tm9qhr1v0+KBZkZfRrye4mewAlG0skQqvYV+ZIlGy6m530CCWw946ZdSDuEvNaTGqzTG k2V7wQK9YGhIiomh3OPesd/tnCAF0Oq/UEsX2wvkTkbS/+crflD56RFa1pB+MrOzPVH7 c/hXKJWwOBiV5zZdO4dCp72YgBZO3112/KthAzaFVuL0rLfNrtxTmc+ZikmCt1pFvgdB VtT0ou20JRC3dSz4Qh3RlAGw17+W8Eh3pha3Mb7/kqvUaY85xSImkMpUiE56+Y/al4Dt F16g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=vYTn7+eGEI7Q1RMA/3vAFLMTCXFX8Sw72SaEzbA1bQ8=; b=KDekFWaYtDsE+CQ7B+huUA/Cvs3og1/k3am/lB8GalpUJJc2Fq5k/UgtGkknAyh/Zi 0+yqu2TBU6nHof27p6Ogulr/85t7QPZMzy7hr4G7Z4griPkv4MaRWvWg3D0dIrVyXD8p aGLyGEalQnT7U0g4CBelyIndiZf5I03+n5/uJMlHB+j4hk9oaSbUy5KK1B49P8F1XU6w sU/GE3VjiALNodvocq6l9t5kDrq2hUCvgMF3NhH4diF1md9oWWW2WgXKP8hbknVIZ99+ ejmbM1RbKSToNTWFoVrVsa7UbyLWbQM18R1SX4hWzbG66t/hNYCkGTgF8tKdgBomrrGW Tpjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=V8v8yV91; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kl11si31932688ejc.593.2021.07.23.15.24.36; Fri, 23 Jul 2021 15:24:59 -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=@chromium.org header.s=google header.b=V8v8yV91; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232752AbhGWVlm (ORCPT + 99 others); Fri, 23 Jul 2021 17:41:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231742AbhGWVll (ORCPT ); Fri, 23 Jul 2021 17:41:41 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1CC3C061575 for ; Fri, 23 Jul 2021 15:22:14 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id k1so4601341plt.12 for ; Fri, 23 Jul 2021 15:22:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=vYTn7+eGEI7Q1RMA/3vAFLMTCXFX8Sw72SaEzbA1bQ8=; b=V8v8yV910H1isJ5XsUEWBXTYWsOJ2rSQR7nS/ui+zSIfggH79Jz0nHagCxU0muqQcm JttIj9mM47GOQtuaCkUz0PdM6rv4stUaa5Gd+8SFgeaxz+uPcAmM1u2RuIlcbNy2pQUY MhkmLzKxElBo6mP+yWQljBaqw9zHg+M3fWs+k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=vYTn7+eGEI7Q1RMA/3vAFLMTCXFX8Sw72SaEzbA1bQ8=; b=obJiUL9W0W6ta5NI8UfGx6pzt0YI6d5sbzbjg6fT4Vp8eTr8NnQS0xfVX7TJEsvpem F5zhGBy+98RLqfAlCAu0sXVTqPPO3DzrWz5U2QaumSKZMVaQFOhiXMmQTJSD646T6+2I zGk/z7PMxnFZzVuj7UtTEOrQ8XX8wtJIvl4075vhK4yq3G1XzPA7PI3glU1G9qFP3yN6 AFQ4BbEszRsYcm98J2M8ocdilTcr+cdURLXYbgjNe/AITQPLHg6aDOr1c0sccxyiq+cJ CdRdRo2nUJUZU6PCeyIV2W610/DmWKi6/vRNxEw/gZ2ALpLt72TYiXzlt0S9GKev2q2w 4/qg== X-Gm-Message-State: AOAM530gbySa0pIeCEEXxVwsNxpPJP2P1seoTKAW6nwQ9vxURoEJi8N/ gyXWBbgLZtdUouS87FwUXrpFrw== X-Received: by 2002:a17:903:22ca:b029:12b:9109:4097 with SMTP id y10-20020a17090322cab029012b91094097mr5425468plg.54.1627078934265; Fri, 23 Jul 2021 15:22:14 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id z12sm28581207pjd.39.2021.07.23.15.22.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 15:22:13 -0700 (PDT) Date: Fri, 23 Jul 2021 15:22:12 -0700 From: Kees Cook To: Arnd Bergmann Cc: Denis Efremov , Dan Carpenter , Peilin Ye , Jens Axboe , "linux-kernel@vger.kernel.org" , linux-block , linux-kernel-mentees@lists.linuxfoundation.org Subject: Re: [Linux-kernel-mentees] [PATCH v2] block/floppy: Prevent kernel-infoleak in raw_cmd_copyout() Message-ID: <202107231520.32B389411@keescook> References: <20200728141946.426245-1-yepeilin.cs@gmail.com> <20200729115157.8519-1-yepeilin.cs@gmail.com> <20200729125820.GB1840@kadam> <202007301056.D3BD1805B0@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 30, 2020 at 10:45:02PM +0200, Arnd Bergmann wrote: > On Thu, Jul 30, 2020 at 8:10 PM Kees Cook wrote: > > On Thu, Jul 30, 2020 at 10:11:07AM +0200, Arnd Bergmann wrote: > > > > test_stackinit.c intended to use six cases (where "full" is in the sense > > of "all members are named", this is intentionally testing the behavior > > of padding hole initialization): > > Ok, so I read that correctly, thanks for confirming. > > > > > > > struct test_big_hole var = *arg; > > > > So this one is a "whole structure copy" which I didn't have any tests > > for, since I'd (perhaps inappropriately) assumed would be accomplished > > with memcpy() internally, which means the incoming "*arg"'s padding holes > > would be copied as-is. If the compiler is actually doing per-member copies > > and leaving holes in "var" untouched, that's unexpected, so clearly that > > needs to be added to test_stackinit.c! :) > > For some reason I remembered this not turning into a memcpy() > somewhere, but I can't reproduce it in any of my recent attempts, > just like what Denis found. > > > > or the a constructor like > > > > > > struct test_big_hole var; > > > var = (struct test_big_hole){ .one = arg->one, .two=arg->two, .three > > > = arg->three, .four = arg->four }; > > > > > > Kees, do you know whether those two would behave differently? > > > Would it make sense to also check for those, or am I perhaps > > > misreading your code and it already gets checked? > > > > I *think* the above constructor would be covered under "full runtime > > init", but it does also seem likely it would be handled similarly to > > the "whole structure copy" in the previous example. > > I would assume that at least with C99 it is more like the > "whole structure copy", based on the standard language of > > "The value of the compound literal is that of an unnamed > object initialized by the initializer list. If the compound literal > occurs outside the body of a function, the object has static > storage duration; otherwise, it has automatic storage duration > associated with the enclosing block." > > > I will go add more tests... > > Thanks! Well, nearly exactly a year later, I've finally done this. :P https://lore.kernel.org/lkml/20210723221933.3431999-1-keescook@chromium.org -- Kees Cook