Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1154315pxk; Fri, 4 Sep 2020 01:56:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySUjddWymQYzLH0OxoH7qGtcoL5Tnl/3EAAMzc4bDVVAYeRrLdihLfQTNl5/V55jQPAAwx X-Received: by 2002:aa7:d785:: with SMTP id s5mr7246752edq.154.1599209768721; Fri, 04 Sep 2020 01:56:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599209768; cv=none; d=google.com; s=arc-20160816; b=wVWVLXwBgy1qrifwvrfSnBeu11rcmg/mrGDMB0URg98ct+3PDcOwUV/sHcsmkxF5AI Nxx2ZCwXQFZwq943IIwaEFp6bdpKvyUSXNbmzLPnuy+2kb5oE8f0OBnRpHE3+R3Kbymx VXxAJmpnVv5+aYz67Q4Ive+5Mvd7eo1U/64/wu0cmH502tYNPwJhexOr6+evNVixDcNm ohw/Dhk83GBIwL3h0NwLy6rDgbW06OxJKJLapnMNyOeFE44OHAwAKAm3GKBVkn7izzyL bEyl2d/pCX8bxrtpZD5cm+0zRxASUyNrETZaIxbfQomHC04zuIvlu1E3iuYVaqGQh2cx RI7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:subject:autocrypt:from:references:cc:to:reply-to; bh=nu8oE74z5YBqiFxodPe/uvx/vJbyX2uHL0xvWWab5to=; b=W2t7uwkkr4tv5SEzb/BPLS3PAUnm+aX844E/nzi7/wJbT+D1XBWNb+mQG6RP3xgrIQ XyRGsQF77e8KvwDkrFj5yzFIWR9dGf9UkF4lqIecgdHm8zIRPwtQ7d6aUwex83+9P3no iahskEmO/pGeU+jejcxqKYaSS+fNtZTT4NDlSR0an6hXV9b5CqCZCLysyZ5PH6+BGBx+ lrThBZqWpiupg7yjjOBLiYgYp3bXcGa+0Tb+ez9Cz1Ob4RaaeIZ89pwArlLLk6E4mHNr c7ADdbn0Kec5HHfyciBkenYB83ZJEl5qcB350S+WYnvbbSvm+NH62u8CjCdcH4xrepxR UvIA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h2si2848845ejy.315.2020.09.04.01.55.37; Fri, 04 Sep 2020 01:56:08 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729824AbgIDIzc (ORCPT + 99 others); Fri, 4 Sep 2020 04:55:32 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:45276 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726575AbgIDIzb (ORCPT ); Fri, 4 Sep 2020 04:55:31 -0400 Received: by mail-lj1-f195.google.com with SMTP id c2so6980316ljj.12; Fri, 04 Sep 2020 01:55:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:to:cc:references:from:autocrypt:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=nu8oE74z5YBqiFxodPe/uvx/vJbyX2uHL0xvWWab5to=; b=WX2C0bogxKF21ZGgpTKj5IiAbFMGfVOOSudtGTt9NR+J1Gw1vuJKsYfCmlXxdQcFGJ PI4r+PwwzZsCUSvupspmBPazkULA+ngHWpvaRV+3+6PmNIdcMYPnB3gQlQYfac4BRDpi Mpgs092vKbFixwuiGQN09UAvQmQ7gIJzS7pfEXCCU6wcVaXVfBnDsR5cR86POoc01FrG XLwlORV+N5y+p2TNHZS+D6E9r3lwg7R6eyiiOMEmLbc2WDt7hemVftFBlHE1x51bZwrD kpo9RlaikiCV2kaai0KwvXxrmveYK3sn84zLcMAasaCvnNZ0vBfNM1zBPLaxGKIECWvc 56Qg== X-Gm-Message-State: AOAM533jRkZlX28toJGYUq+5+ZNInZZmbZxbPtpWHCrhOZWXjnDW72ue orOOgIAqgp2pQ2EN1sJlI6BEYxqz1x8= X-Received: by 2002:a2e:9794:: with SMTP id y20mr3192952lji.269.1599209727867; Fri, 04 Sep 2020 01:55:27 -0700 (PDT) Received: from [10.68.32.147] (broadband-37-110-38-130.ip.moscow.rt.ru. [37.110.38.130]) by smtp.gmail.com with ESMTPSA id m13sm1175032lfl.30.2020.09.04.01.55.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Sep 2020 01:55:27 -0700 (PDT) Reply-To: efremov@linux.com To: "Van Leeuwen, Pascal" , "linux-crypto@vger.kernel.org" Cc: Corentin Labbe , Herbert Xu , "linux-kernel@vger.kernel.org" References: <20200827064402.7130-1-efremov@linux.com> <20200827064402.7130-2-efremov@linux.com> From: Denis Efremov Autocrypt: addr=efremov@linux.com; keydata= mQINBFsJUXwBEADDnzbOGE/X5ZdHqpK/kNmR7AY39b/rR+2Wm/VbQHV+jpGk8ZL07iOWnVe1 ZInSp3Ze+scB4ZK+y48z0YDvKUU3L85Nb31UASB2bgWIV+8tmW4kV8a2PosqIc4wp4/Qa2A/ Ip6q+bWurxOOjyJkfzt51p6Th4FTUsuoxINKRMjHrs/0y5oEc7Wt/1qk2ljmnSocg3fMxo8+ y6IxmXt5tYvt+FfBqx/1XwXuOSd0WOku+/jscYmBPwyrLdk/pMSnnld6a2Fp1zxWIKz+4VJm QEIlCTe5SO3h5sozpXeWS916VwwCuf8oov6706yC4MlmAqsQpBdoihQEA7zgh+pk10s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mHAroFcqCFUlfAqUDO T30gV5bQ8BHqvfWyEhJT+CS3JJyP8BmmSgPa0Adlp6Do+pRsOO1YNNO78SYABhMi3fEa7X37 WxL31TrNCPnIauTgZtf/KCFQJpKaakC3ffEkPhyTjEl7oOE9xccNjccZraadi+2uHV0ULA1m ycHhb817A03n1I00QwLf2wOkckdqTqRbFFI/ik69hF9hemK/BmAHpShI+z1JsYT9cSs8D7wb aF/jQVy4URensgAPkgXsRiboqOj/rTz9F5mpd/gPU/IOUPFEMoo4TInt/+dEVECHioU3RRrW EahrGMfRngbdp/mKs9aBR56ECMfFFUPyI3VJsNbgpcIJjV/0N+JdJKQpJ/4uQ2zNm0wH/RU8 CRJvEwtKemX6fp/zLI36Gvz8zJIjSBIEqCb7vdgvWarksrhmi6/Jay5zRZ03+k6YwiqgX8t7 ANwvYa1h1dQ36OiTqm1cIxRCGl4wrypOVGx3OjCar7sBLD+NkwO4RaqFvdv0xuuy4x01VnOF Subject: Re: [PATCH v2 1/4] crypto: inside-secure - use kfree_sensitive() Message-ID: <8ac5cb88-7df5-1060-2fac-510541fca48b@linux.com> Date: Fri, 4 Sep 2020 11:55:26 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Hi, On 9/2/20 4:10 PM, Van Leeuwen, Pascal wrote: >> -----Original Message----- >> From: linux-crypto-owner@vger.kernel.org On Behalf Of Denis Efremov >> Sent: Thursday, August 27, 2020 8:44 AM >> To: linux-crypto@vger.kernel.org >> Cc: Denis Efremov ; Corentin Labbe ; Herbert Xu >> ; linux-kernel@vger.kernel.org >> Subject: [PATCH v2 1/4] crypto: inside-secure - use kfree_sensitive() >> >> <<< External Email >>> >> Use kfree_sensitive() instead of open-coding it. >> >> Signed-off-by: Denis Efremov >> --- >> drivers/crypto/inside-secure/safexcel_hash.c | 3 +-- >> 1 file changed, 1 insertion(+), 2 deletions(-) >> >> diff --git a/drivers/crypto/inside-secure/safexcel_hash.c b/drivers/crypto/inside-secure/safexcel_hash.c >> index 16a467969d8e..5ffdc1cd5847 100644 >> --- a/drivers/crypto/inside-secure/safexcel_hash.c >> +++ b/drivers/crypto/inside-secure/safexcel_hash.c >> @@ -1082,8 +1082,7 @@ static int safexcel_hmac_init_pad(struct ahash_request *areq, >> } >> >> /* Avoid leaking */ >> -memzero_explicit(keydup, keylen); >> -kfree(keydup); >> +kfree_sensitive(keydup); >> > I'm not sure here ... I verified it does not break the driver (not a big surprise), but ... > > memzero_explicit guarantees that it will not get optimized away and the keydata _always_ > gets overwritten. Does kfree_sensitive also come with such a guarantee? I could not find a > hard statement on that in its documentation. Although the "sensitive" part surely suggests > it. kfree_sensitive() uses memzero_explicit() internally. > Additionally, this remark is made in the documentation for kfree_sensitive: "this function > zeroes the whole allocated buffer which can be a good deal bigger than the requested buffer > size passed to kmalloc(). So be careful when using this function in performance sensitive > code" > > While the memzero_explicit does not zeroize anything beyond keylen. > Which is all you really need here, so why would you want to zeroize potentially a lot more? > In any case the two are not fully equivalent. There are a number of predefined allocation sizes (power of 2) for faster alloc, i.e. https://elixir.bootlin.com/linux/latest/source/include/linux/slab.h#L349 and it looks like that keys we free in this patches are in bounds of these sizes. As far as I understand, if a key is not a power of 2 len, the buffer will be zeroed to the closest power of 2 size. For small sizes like these, performance difference should be unnoticeable because of cache lines and how arch-optimized memzero() works. Key freeing doesn't look like a frequent event. Thanks, Denis