Received: by 2002:a05:622a:251a:b0:39a:b4a2:e86 with SMTP id cm26csp316370qtb; Wed, 19 Oct 2022 02:43:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5m+Klbx20fie07iDInnEzKEvOiDEJSt3z9QVT/40nvvoRUOGjbwq9ZomDymRU1H0FJzkxI X-Received: by 2002:a05:6402:35d1:b0:45d:3661:567e with SMTP id z17-20020a05640235d100b0045d3661567emr6689401edc.343.1666172606655; Wed, 19 Oct 2022 02:43:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666172606; cv=none; d=google.com; s=arc-20160816; b=dM5brQDVph/EL5s5eKzDb4nQIod2AJmtpsIpPb7MwjGJW2zXfGLE8oDp/rCGvERph8 YxcOrdG3meLDzjAxS18N5QEZwUZbMiRMO/SWhLsmRAcxLJVxVXeUcu5V9gAAVz1BtzFt 2xsQRo66JQAYdUAF2UC/Dhb1DyGEclSnwPePLvFH4me3608GcjctduYUZ0WXE1zkorUt UA4Sz0K4mKQ57BtvrumRem2ZqUWUTRjqQyYkjb5Yr/YcDkwNh8B7xEKXOxPp7o/PMElD 72UppZWJ7+xaVJud29jWteKMhrX+UPszQ3tcZqM3Nl9Ul6bIf/5cpItv4z6YIPw/bM3X 8G9A== 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=AzG+JhM/DqXXR8z7xyegEXQQCVg5rZuEq1iIVuFBdZZhokVis5Pc8iskc914VgeAF8 pODoP710frNNxdqYuqGZv7XbkrlscccnLHMNxA7tHIOcDXz/DzBHR9ENVvn6yGGq7/kB WSVcPyTovTCP6DHVsN5ttZEcRu3LppcNPDQx6YW9L1x2X6IshDLiDUaQykkbckcfeTAy pQd9iP8dL/PaHdf6NRpfBEBVE+XPWFrXEG7SccaacGo8bfmK4r9H/p5HlCkQBqq+UEVW J4vtx5iWawShH2BmD6DAp1jCf5O1ZVyOslvdJ00nIt6y3CAf9cg+jz+gZ+dRMo4OfjFs diUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="g/9IqxyF"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gg20-20020a170906e29400b0073d6c0facdcsi11868889ejb.259.2022.10.19.02.43.00; Wed, 19 Oct 2022 02:43:26 -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="g/9IqxyF"; 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 S233092AbiJSJSx (ORCPT + 99 others); Wed, 19 Oct 2022 05:18:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233218AbiJSJQ5 (ORCPT ); Wed, 19 Oct 2022 05:16:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBB795FAE7; Wed, 19 Oct 2022 02:07:07 -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 7CFDC61868; Wed, 19 Oct 2022 09:06:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8AE79C433D7; Wed, 19 Oct 2022 09:06:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170387; bh=NI1fBXPVYlDZ4B6j6GMBIhhEi5k4CLiLesxDmWTMZN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g/9IqxyFPdEk3n2rhwQIJvPRSNDFkXFPpkM6dwWdhaO/e60kQmwhIm//QcA+LeI20 gxOxgswR/pTyliRExviYmqZyG27qMtDHg9w/3zmv2M3yfnHXBQZeOcnYDtYM9k9ZiT G7Gizxd0v8NKxkomjWbv5qTgsmZBquhv9qy2YcG8= 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 6.0 635/862] crypto: akcipher - default implementation for setting a private key Date: Wed, 19 Oct 2022 10:32:02 +0200 Message-Id: <20221019083317.996776853@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 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 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); -- 2.35.1