Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp640965pxu; Fri, 23 Oct 2020 09:35:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziN3Pqc+64TEeW2bWYrs5UVZsFpWb07C9eD7iqyrUi7R6SHJgGCyFEDkSRlWRcfykWpbKC X-Received: by 2002:a05:6402:143:: with SMTP id s3mr2876779edu.267.1603470937991; Fri, 23 Oct 2020 09:35:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603470937; cv=none; d=google.com; s=arc-20160816; b=fCoiza5+kg4+vpaCAfLGrIx0nklI1KYE7hPUQ5lWKIVYqdCmezL4dXnQyMRFmrzvdo epPnoKZ/dsTTOD/geyHYoDw1aQH8WhmGd+KhokrXhDuu215o2bLlwhaD0b0f/TPyYXJo rRY8g4Z+kg+TAZQbrWJTEw5Ksm5+Pd0aC4qy8czlWfeJpHSA35hrdES5ia/NEUsRLsNp r70750MehqkILqXPe5BIOyC3NVuAVsdHPut/zeud0fB2xQpDkVEVmAh/LwJluDTKp/Yb UAq65IU/7dBiNgmEHLL693R17Ve0rOWZ0QRHS0GbURwUvPcYKlS6vs7P98pzh4xOateC 60tQ== 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=8Ow7tZj+FFSEjQN6y9FLVT3OmUx9f1wN87JwLsc0Yrg=; b=ubnqqelPacbJ7EzKX8dUeSctCZJEirv/p3mbCE3cHCLkf6Gag1xBTAk5L3KIkBZC6o F5yXaKtLpmtToHGmGHG4AI1oQKseueTMW4iUigf8xVWkEedjGZW48gmSW1mI8umSrisp +jsuTRVEHyPTEnbHFzEII/C679c4rXEUjbogSGhIKNItow8kbb0tF71u/dEc64iWKEQJ 3i5CxQoojnulUD7J49i/haYq9MbPeSdZXOs0FUZ0/JZ78bg2FyCUbS9r2VWEaAmqx4Tr z4eaM71gtKj8FA3xAQ7/VRv40CN6eoJONgCZbKIM7bihOkIDVnVoy05OUfs3mlF8NFVJ 3i3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U7A4lwhc; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u15si1168362eje.174.2020.10.23.09.35.13; Fri, 23 Oct 2020 09:35:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=U7A4lwhc; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S464361AbgJWP4H (ORCPT + 99 others); Fri, 23 Oct 2020 11:56:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:43646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S373640AbgJWP4H (ORCPT ); Fri, 23 Oct 2020 11:56:07 -0400 Received: from gmail.com (unknown [104.132.1.76]) (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 E7E2E20878; Fri, 23 Oct 2020 15:56:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603468566; bh=mGaS8wWdgjA4/u1RLqkRCcaeFZJUeOXQKmXulx07Tlo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=U7A4lwhcWJ1GQQ3YMv3Ky2grgIzKwvznwF5BfTalilVcl0UjuGynoNokjFWoY/WOe 4MZfwlY2ByZYq/w555eYJptk+UeCLkyB3a308uZk/SfEoNwMh/IQXQ8VEaUx84vQ/P xsBwZG2DPUdG7iewISoxpGF+L66KWZuu+HxJB85E= Date: Fri, 23 Oct 2020 08:56:04 -0700 From: Eric Biggers To: Arvind Sankar Cc: Herbert Xu , "David S. Miller" , "linux-crypto@vger.kernel.org" , David Laight , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/6] crypto: Use memzero_explicit() for clearing state Message-ID: <20201023155604.GA3908702@gmail.com> References: <20201020203957.3512851-1-nivedita@alum.mit.edu> <20201020203957.3512851-2-nivedita@alum.mit.edu> <20201022043633.GD857@sol.localdomain> <20201023153927.GA217686@rani.riverdale.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201023153927.GA217686@rani.riverdale.lan> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Fri, Oct 23, 2020 at 11:39:27AM -0400, Arvind Sankar wrote: > On Wed, Oct 21, 2020 at 09:36:33PM -0700, Eric Biggers wrote: > > On Tue, Oct 20, 2020 at 04:39:52PM -0400, Arvind Sankar wrote: > > > Without the barrier_data() inside memzero_explicit(), the compiler may > > > optimize away the state-clearing if it can tell that the state is not > > > used afterwards. At least in lib/crypto/sha256.c:__sha256_final(), the > > > function can get inlined into sha256(), in which case the memset is > > > optimized away. > > > > > > Signed-off-by: Arvind Sankar > > > > Reviewed-by: Eric Biggers > > > > Maybe get the one in arch/arm64/crypto/sha3-ce-glue.c too? > > > > - Eric > > Hm, there are a few more as well like that. But now I'm thinking it's > only the generic sha256.c that may be problematic. The rest of them are > in _final() functions which will be stored as function pointers in a > structure, so there should be no risk of them getting optimized away? When clearing memory because "it may be sensitive" rather than "it's needed for the code to behave correctly", I think it's best to use memzero_explicit() to make the intent clear, even if it seems that memset() is sufficient. Also keep in mind that support for compiling the kernel with LTO (link-time optimization) is being worked on (and some people already do it), which results in more code being optimized out. - Eric