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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 964FEC77B73 for ; Sat, 3 Jun 2023 16:02:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229471AbjFCQCZ (ORCPT ); Sat, 3 Jun 2023 12:02:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjFCQCW (ORCPT ); Sat, 3 Jun 2023 12:02:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81FBECA; Sat, 3 Jun 2023 09:02:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1DE3860B55; Sat, 3 Jun 2023 16:02:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C41EC433D2; Sat, 3 Jun 2023 16:02:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685808140; bh=hbhcJ5+vvPHCu2gKyrTxiCQZ7fSTFNJM9grhrnn5tuI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DGnhST4IJztKxzCVRT90P4/F0w+b4KpmpzWT+8PmL3azyMo9KMAcM3qttHI/2JxyZ uWO6SIr3pVSl5fjgOssogoh6q/RYvyTkI7aTXeOPN6VnzOAHimQ2ZUNlCJ0G3E7BqA pQHUtEV9SqQb+fA+Fc+8+NTEaZzoVPlHFwgMHgvpUhDrD3gDTX9D4lxigkZMiwa8BO vntotnnwUDV3UAxJUAo6yipuuSU6HHbY97rXjt5+5CqrzFTsdIomunihWepHhe/GBx qynxR5Q4FVVPsvxStI1w31ZLlGH7KyySdkH95V4NQwhQakbx1S7ZkijGRy6Y0WlVxh XGtdCPnQfE10Q== Date: Sat, 3 Jun 2023 09:02:08 -0700 From: Eric Biggers To: Roberto Sassu Cc: Linus Torvalds , David Howells , Herbert Xu , Andrew Morton , Stefan Berger , davem@davemloft.net, zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, Jarkko Sakkinen , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [GIT PULL] Asymmetric keys fix for v6.4-rc5 Message-ID: <20230603160208.GA677@quark.localdomain> References: <4d7e38ff5bbc496cb794b50e1c5c83bcd2317e69.camel@huaweicloud.com> <97fd9066-9afc-9faa-a604-46110ed1268c@huaweicloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <97fd9066-9afc-9faa-a604-46110ed1268c@huaweicloud.com> Precedence: bulk List-ID: On Sat, Jun 03, 2023 at 12:41:00PM +0200, Roberto Sassu wrote: > On 6/3/2023 2:02 AM, Linus Torvalds wrote: > > On Fri, Jun 2, 2023 at 1:38 PM Linus Torvalds > > wrote: > > > > > > The patch re-uses the allocation it already does for the key data, and > > > it seems sane. > > > > Ugh. I had to check that it was ok to re-use the key buffer, but it > > does seem to be the case that you can just re-use the buffer after > > you've done that crypto_akcipher_set_priv/pub_key() call, and the > > crypto layer has to copy it into its own data structures. > > Yes, we could not do it if the set_pub_key/set_priv_key methods use > internally the passed pointer. I guess it depends on the methods, for RSA > and ECDSA it seems fine (they copy to a different location). > > The doubt comes because the buffer is freed after crypto_wait_req() and not > after crypto_akcipher_set_*_key(), suggesting that it could be actually used > during the crypto operation. > > Rechecked the thread, and the suggestion to reuse the buffer and not append > the signature and digest at the end was by Eric Biggers. > > Eric, in light of this finding, should we still reuse the buffer? > I don't think there was any "finding" here. The setkey methods in the crypto API aren't allowed to reuse the buffer they are passed, so the patch is fine. - Eric