From patchwork Mon Oct 24 11:32:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9536 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp484062wru; Mon, 24 Oct 2022 07:28:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5CCuePbyR0JhVZZ/z853cvd26MhKGF84iQHEvULtStubZlpgMDeDqfE6oNmp2G4H8XdvLi X-Received: by 2002:a05:6a00:e1b:b0:537:7c74:c405 with SMTP id bq27-20020a056a000e1b00b005377c74c405mr33846868pfb.43.1666621736468; Mon, 24 Oct 2022 07:28:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666621736; cv=none; d=google.com; s=arc-20160816; b=LvKBWQvoCD52eCLJki6r6LLl1h6Ud48uZUY0xXsVeJZ871qnk6l9jCdNso4Hv7+OCW 3zkxBpW8faD/nlOLZ60ba0mcpDiZXFGhwFSolu7djfAXOSEpaX2uz3LpfUNbahyWEv2j SAvIHUPTbesmVh8VEgJENOYFssvOVsJ09zHAWfTFj+SIYZPFIMAdh3oibXNKgF/slBKt etxaZuFIpfVGdtrpU9Rgz6cv0yy+33HxOaQdmDRwLNDE4Xqwu7BgiF9zQEnxzUr5AJa1 cvCFK8eq7oRa+WxtqSQZsS2e/AinN0vIblE6Pdn43AzStYAn0AH9aU4v9tARSMcYD7EZ WVLQ== 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=s4TDZAiNiYSUYVklnJSXPar7Ef7VYkLcVSdzRuKqZDE=; b=fcM2ydA4qtPOGO8SJb1L29xj2QYzsYjzWpWjOHYU2298ywQPLYNxEjmrY3/6PDm716 qHgFIAN13pZ6AwKWViy4Evl8FZtBjf17Vktsif8HkvSrdxhmv8aYp4bqw4xq1g6lPuBm zx31pEGekKjadXl2xUS1ouzQIiSgtznls7ssALVYZMvUrOftvIEe4iS8A4jQnimRNK+5 oTw08jL5pq8vZnogXfCCA3MhswbRcXeMtDmR9owUMEoa32C5y5pCru/sgq0MObbhfgH2 witlwJF1w080Eba70OD/+CK2UO+OjAKEKMorfsLv59HsEhM8r//N6Bf20u4EPWzrL7Xa 2AGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kTnV2rr2; 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 i7-20020a17090aee8700b0020d67aeb299si8409508pjz.53.2022.10.24.07.28.43; Mon, 24 Oct 2022 07:28:56 -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=kTnV2rr2; 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 S235199AbiJXO1k (ORCPT + 99 others); Mon, 24 Oct 2022 10:27:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237033AbiJXO1R (ORCPT ); Mon, 24 Oct 2022 10:27:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B23A19A9C3; Mon, 24 Oct 2022 06:00:52 -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 1491061313; Mon, 24 Oct 2022 12:49:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27CDCC43141; Mon, 24 Oct 2022 12:49:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666615785; bh=NI1fBXPVYlDZ4B6j6GMBIhhEi5k4CLiLesxDmWTMZN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kTnV2rr2PPGYZfMh+uWU/rZKXaVUXXt6Vc85MsmD16sOo1AbEaqs+EcmEB/aNBP65 NR+23hXiN/T9jH0/lgcD57wm/ByndXAjSGFekL1WKTfLjFypD2c7/BswkWocavQtIr nm3aY75AUXfpx9nBB43+264F5R3mB6DuxJ7GMOaQ= 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.15 382/530] crypto: akcipher - default implementation for setting a private key Date: Mon, 24 Oct 2022 13:32:06 +0200 Message-Id: <20221024113102.352280119@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@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?1747579554425858637?= X-GMAIL-MSGID: =?utf-8?q?1747579554425858637?= 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 f866085c8a4a..ab975a420e1e 100644 --- a/crypto/akcipher.c +++ b/crypto/akcipher.c @@ -120,6 +120,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; @@ -132,6 +138,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);