Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4360450ybp; Mon, 7 Oct 2019 07:23:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqwIX9ZNfLdmVJKYUt91kfCOpm+l3UbXZsmwjtTby6UYIGy+nkmxsXLDmm9KBHQ75Qm+Rffa X-Received: by 2002:a17:906:1c05:: with SMTP id k5mr24259093ejg.286.1570458191882; Mon, 07 Oct 2019 07:23:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570458191; cv=none; d=google.com; s=arc-20160816; b=dwTfq2vC0/ghvAwMZkn7ntkHL5B2qw+PlAvE0djtYh8ZvY6Tu9eK8xw4GNb6JGorUO z0Y+AZgj/WDVByi+xUXt5OgcQs1Px+r6QH4aT1a0FrPmyV+ZZ/FV/BYou9x5NWLChW0N shGbwKLwqgrs3B25fD13enq3XezBMp/roJcQZ9KsZQ8cRgk0f9DP2uXsEWucAtGNmAYU mzRoZDkODHZuehCWWELXX+wbR8gbWoLKdyuAo+Ql7CiX4jY0cF4kSdFzxmfgT2vRNkJn Xha1j7sLV7gp+YqwiOCs/fsNxfDyzUUmayAUDJK7bgxGXGLczCADTDpLLti1/S1A+tMG QmTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=i1iPOPDObUtdkhKgZivRBgqCEbtyqjoATFmtKPXDvrY=; b=V7RR37oQquAAwrWRmYnBCj5d+BEVp9nmn3tOzcTc6q91QfCn+aicpsuQfjbkPii4eC F4Ulj46rNBOkjtYZi8reZyY+bjuLfziM/Bkecm8WpDN8knLJSPuawPzunV9rhPBWILKw 2hm6rHMmNZGQGr7m9nQvyyzg5n8M7MVbKwGPw2YAw3tVyGRC4fMU9eePSa3lxFb4aCNM 0+T0qdGLCGrhgCTTYHeSVSGQwq6MdU8kXIP3l2NVzpIjNM4DEhByHKp/3XjjI4FAguz2 mD3KiIsjNXaJqmTrBfzlMoquQ3zbVjV280CVorng0TFBK/5wxwitvMH+zf9GP+hRO/nK ERKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=nQCgj9ez; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n19si6992827ejk.264.2019.10.07.07.22.43; Mon, 07 Oct 2019 07:23:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=nQCgj9ez; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727715AbfJGOWf (ORCPT + 99 others); Mon, 7 Oct 2019 10:22:35 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43310 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727324AbfJGOWf (ORCPT ); Mon, 7 Oct 2019 10:22:35 -0400 Received: by mail-wr1-f68.google.com with SMTP id j18so14747309wrq.10; Mon, 07 Oct 2019 07:22:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=i1iPOPDObUtdkhKgZivRBgqCEbtyqjoATFmtKPXDvrY=; b=nQCgj9ezS8bgXT68Ws3T6ySHVujFbONhMj58nzGhkVdDy8geNmzawspB2tJ8FbqJov 0A3fiaZlET5vRM+HNzKvJBInDIygqZ8MkBX4gpTFJPIimpzxPhUzBaWCmgpLSH+/0GTC +YVUibZFJgCyv10iP5EvuDceyJftRPLgdP6CTASGO4W8aTEnMFInSs/1dcT75HiIkg31 AhW6yxZkMH6F0FaGVJCyNtq7NN4KYDFGAdnrVfyn1hBABVJU26Ppq6xQpK8yAHubfpi9 AtgzMWOviPkQFAQ/Flyi7n8p/FmWuN1VONOzrSbrYsXlFyscVQ2MvC/ho6TxYq3x3VkW F4Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=i1iPOPDObUtdkhKgZivRBgqCEbtyqjoATFmtKPXDvrY=; b=JJKQR78HQc+ph2ex51UB2GCNZ2Moow/QiXEww+99cyw4Cb9dqNI91TOf+VKShnIRU3 3/jjtD2TunsJmr4Bcr53SRsax60f4zsJbm5oC2fLQZ2fpMmnUT39TTLt7HOxnJWJOXSR iEwtgJY4lK2EZ1G1VUwp7byzJFInleqCQbAVI5DKOkRNfFGz4I4ir7pUGxHk8K17Or7M YhV0x4vJY3jmiT2uNDg9ewJH2PlxRgNr77as1GTMS4aDXfu003HgN3TyvKBr0Dn90SeL 7l0POXSppT2U6/0V58Ba0rlZaxq/hcOrsj+cM/FwGmHAYoI0kG+rtgQ++koaVvQvbGV5 HLnQ== X-Gm-Message-State: APjAAAUgESCRrEqoZLKQxFMtjhMmW6QfLfcWrGahfPpT0HVbzrCxpbsK +NjenSog89trAVqf8z/hejQ= X-Received: by 2002:a5d:6a90:: with SMTP id s16mr22733932wru.284.1570458153175; Mon, 07 Oct 2019 07:22:33 -0700 (PDT) Received: from gmail.com (2E8B0CD5.catv.pool.telekom.hu. [46.139.12.213]) by smtp.gmail.com with ESMTPSA id a18sm24455478wrs.27.2019.10.07.07.22.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 07:22:32 -0700 (PDT) Date: Mon, 7 Oct 2019 16:22:30 +0200 From: Ingo Molnar To: Hans de Goede Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Herbert Xu , Ard Biesheuvel , linux-crypto@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Arvind Sankar , Stephan Mueller Subject: Re: [PATCH v2 5.4 regression fix] x86/boot: Provide memzero_explicit Message-ID: <20191007142230.GA117630@gmail.com> References: <20191007134724.4019-1-hdegoede@redhat.com> <20191007140022.GA29008@gmail.com> <1dc3c53d-785e-f9a4-1b4c-3374c94ae0a7@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1dc3c53d-785e-f9a4-1b4c-3374c94ae0a7@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org * Hans de Goede wrote: > Hi, > > On 07-10-2019 16:00, Ingo Molnar wrote: > > > > * Hans de Goede wrote: > > > > > The purgatory code now uses the shared lib/crypto/sha256.c sha256 > > > implementation. This needs memzero_explicit, implement this. > > > > > > Reported-by: Arvind Sankar > > > Fixes: 906a4bb97f5d ("crypto: sha256 - Use get/put_unaligned_be32 to get input, memzero_explicit") > > > Signed-off-by: Hans de Goede > > > --- > > > Changes in v2: > > > - Add barrier_data() call after the memset, making the function really > > > explicit. Using barrier_data() works fine in the purgatory (build) > > > environment. > > > --- > > > arch/x86/boot/compressed/string.c | 6 ++++++ > > > 1 file changed, 6 insertions(+) > > > > > > diff --git a/arch/x86/boot/compressed/string.c b/arch/x86/boot/compressed/string.c > > > index 81fc1eaa3229..654a7164a702 100644 > > > --- a/arch/x86/boot/compressed/string.c > > > +++ b/arch/x86/boot/compressed/string.c > > > @@ -50,6 +50,12 @@ void *memset(void *s, int c, size_t n) > > > return s; > > > } > > > +void memzero_explicit(void *s, size_t count) > > > +{ > > > + memset(s, 0, count); > > > + barrier_data(s); > > > +} > > > > So the barrier_data() is only there to keep LTO from optimizing out the > > seemingly unused function? > > I believe that Stephan Mueller (who suggested adding the barrier) > was also worried about people using this as an example for other > "explicit" functions which actually might get inlined. > > This is not so much about protecting against LTO as it is against > protecting against inlining, which in this case boils down to the > same thing. Also this change makes the arch/x86/boot/compressed/string.c > and lib/string.c versions identical which seems like a good thing to me > (except for the code duplication part of it). > > But I agree a comment would be good, how about: > > void memzero_explicit(void *s, size_t count) > { > memset(s, 0, count); > /* Avoid the memset getting optimized away if we ever get inlined */ > barrier_data(s); > } Well, the standard construct for preventing inlining would be 'noinline', right? Any reason that wouldn't work? Thanks, Ingo