From patchwork Mon Oct 24 11:31:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 10183 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp641437wru; Mon, 24 Oct 2022 13:35:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Re6jQ39Z6vxOrJ9GazWeFNb2VFvCaCddr2Oi7u4RrCk72NygER1gym5C0f5SYsNk26Z7V X-Received: by 2002:a17:907:72c5:b0:798:1c8f:5bc7 with SMTP id du5-20020a17090772c500b007981c8f5bc7mr21138931ejc.119.1666643721371; Mon, 24 Oct 2022 13:35:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666643721; cv=none; d=google.com; s=arc-20160816; b=L8v17WYkXLBSYMvMo7z+ZJyDsiJ3Nh9aPc4GqONzzPe14UF20inHUaxnqK53Q/CqIn 2HII4LerRynZA2qoVO7einDxiOxkbxaS0lm30VSRBqkt3DjIV0h1yDtwtqg0btmUNSfZ SrODJxNthw1yD0exVOpaTKQyfJzcclAnqKcxcNMeXiaLaFRS48b9U3W/LN7gubBtYG0y u0RhubofxJuq/70Zsrb7tWrrSDD2tTKv2cSxvpbJtmm82kqN1tsb7E20n7iSrqqwW/qm Fn+0jtOBh29rMZw3FfGPsBrp9eMYp6aPaIprw5qvfX9yAHotU5opA5JoO9s32TgTzF+J 0//Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=q45SsG4p94KSdzE65sNEZzG3xX7TVecEGbTAKmmOT4Q=; b=cKnNcK/7/1aV8UWjamo8H+mvxYPdSX9goAnNeoeKI04ag1yXoqgSobbXcaWpQCaOK/ VwyHwVHTDy5gCd+C1KKNUyE6c+oQ/t/+SbOzZdHSkLIgUHXj6deGSRIkI5u82XHHsZDi jHBFu6CUYSRdC3PNJJWUbuld87bfcdLCghVy5YYQGZGDm51DaC/THveIZpVTgXcklGJo FytCiXEaolC92ce0wDVuPUm0cT9yOTybKHt+aQJ3qwO0zVWM/z8vBHPbCCO3pmgN9v0E izRoZLJEKkqwp0LPcgYNIRibEKu5DcMsRg5XLr+YhACxZIlYH7EIcgK2N0FA0qMd+rWO 1C1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="n/H54K16"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l15-20020a170906794f00b0078d23ac6981si677965ejo.790.2022.10.24.13.34.56; Mon, 24 Oct 2022 13:35:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="n/H54K16"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234212AbiJXUXv (ORCPT + 99 others); Mon, 24 Oct 2022 16:23:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234243AbiJXUXB (ORCPT ); Mon, 24 Oct 2022 16:23:01 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8AE8AC4AE; Mon, 24 Oct 2022 11:38:22 -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 ams.source.kernel.org (Postfix) with ESMTPS id 67A07B815E6; Mon, 24 Oct 2022 12:12:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C39E1C433C1; Mon, 24 Oct 2022 12:12:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613550; bh=2HjTKxmeeRJf9SO8vt0eJKqSwURDpwCV1KyIQ4MKMTQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n/H54K16RPKpyppJljoHY38ghbRPd4YMIL7z+722W+JEkn2kYVuefDro9/V5DL359 bEEvIqinJkU6D8VAsKf5qzfShfDnnSpx/HtMV+FdTjIzVJn2i6UuoVihQDBCRSrNS4 2sIHG/goL/2DY3O/ZNrxxlwxTlGoNibruHLLpi6o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ignat Korchagin , Herbert Xu , Sasha Levin Subject: [PATCH 5.4 179/255] crypto: akcipher - default implementation for setting a private key Date: Mon, 24 Oct 2022 13:31:29 +0200 Message-Id: <20221024113008.816417193@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747602606805339608?= X-GMAIL-MSGID: =?utf-8?q?1747602606805339608?= From: Ignat Korchagin [ Upstream commit bc155c6c188c2f0c5749993b1405673d25a80389 ] Changes from v1: * removed the default implementation from set_pub_key: it is assumed that an implementation must always have this callback defined as there are no use case for an algorithm, which doesn't need a public key Many akcipher implementations (like ECDSA) support only signature verifications, so they don't have all callbacks defined. Commit 78a0324f4a53 ("crypto: akcipher - default implementations for request callbacks") introduced default callbacks for sign/verify operations, which just return an error code. However, these are not enough, because before calling sign the caller would likely call set_priv_key first on the instantiated transform (as the in-kernel testmgr does). This function does not have a default stub, so the kernel crashes, when trying to set a private key on an akcipher, which doesn't support signature generation. I've noticed this, when trying to add a KAT vector for ECDSA signature to the testmgr. With this patch the testmgr returns an error in dmesg (as it should) instead of crashing the kernel NULL ptr dereference. Fixes: 78a0324f4a53 ("crypto: akcipher - default implementations for request callbacks") Signed-off-by: Ignat Korchagin Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- crypto/akcipher.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crypto/akcipher.c b/crypto/akcipher.c index 7d5cf4939423..ceb0c2fb2b24 100644 --- a/crypto/akcipher.c +++ b/crypto/akcipher.c @@ -119,6 +119,12 @@ static int akcipher_default_op(struct akcipher_request *req) return -ENOSYS; } +static int akcipher_default_set_key(struct crypto_akcipher *tfm, + const void *key, unsigned int keylen) +{ + return -ENOSYS; +} + int crypto_register_akcipher(struct akcipher_alg *alg) { struct crypto_alg *base = &alg->base; @@ -131,6 +137,8 @@ int crypto_register_akcipher(struct akcipher_alg *alg) alg->encrypt = akcipher_default_op; if (!alg->decrypt) alg->decrypt = akcipher_default_op; + if (!alg->set_priv_key) + alg->set_priv_key = akcipher_default_set_key; akcipher_prepare_alg(alg); return crypto_register_alg(base);