Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3962856rwi; Sat, 22 Oct 2022 03:00:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6mLbQlnZHNTjPB1X2R/4ruGog33IaJ8ynNBKfGhQECINCSkEiTacdXqXbiulIn1aEJYLPv X-Received: by 2002:a17:90b:4f4b:b0:20d:1fe8:dce5 with SMTP id pj11-20020a17090b4f4b00b0020d1fe8dce5mr61378917pjb.224.1666432825167; Sat, 22 Oct 2022 03:00:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666432825; cv=none; d=google.com; s=arc-20160816; b=n/Lx0c9srzgiJw/2Nja+cavL5oSWAbXDuKB4KY0QykSr9bzl63qE15kPZYlx9VraZx rU/MmdvcoBceWzIgjzjL+8yeqbRryNAzEHj2y7xtUWXL2cx7MODfFUQ7zTucp2O6DVFr G/bIUMJ/0TtA83S1Xuj9kvWeYpEoEk9xzhbmuPBWIisRMnvGJLrOIyKgK67KtHXOx9W6 r/RBZyppYP6QWf5ZhmRdWLmW+o/o/46mCCbKipiNPfRfHO8Bvhp4AET+wKh/MuFWXyeJ AmNDRdECB39xUBjShA6S2rpxNEl7yc61bA17NhE5aWng6UmOXcS8toQ6JkUorVm0HGMU gwMw== 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=q7rxh89/R13OJ1BsAA3PTPm9n69tAYSWrBJtFGNPGwYx27UAqJastYggXdYn97fu3w ALTorw+vw73Ujoo5mjw5igj3u2UOnZI+eJzPjcFEuqUwzLB3cOB30oW9H/8DiQgoFktj mXGJA3fkY0HALXox+bELzYxn4cjJ4t8Lssa2e7uGPv9+YemHMNS3qpsizozlZ8Ku2syq b2+vbWOHFk0tkSXuq/wjkXTcLbu914Fpzb0eg9HNomjfgBpCpjHqlyuuBYhEf9mVczbI EgqEo0M9B1DDSM2+Qyk+0GTUshnXRRkOr69rcDCKA+qnRLg7pwox72en5jim8OdWgoIP nDSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Q48ZTopR; 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 s8-20020a170902ea0800b0018688bde666si2479666plg.520.2022.10.22.03.00.12; Sat, 22 Oct 2022 03:00:25 -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=Q48ZTopR; 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 S233808AbiJVI0U (ORCPT + 99 others); Sat, 22 Oct 2022 04:26:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234069AbiJVIYl (ORCPT ); Sat, 22 Oct 2022 04:24:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 260F35D894; Sat, 22 Oct 2022 01:00:11 -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 B0DAA60B40; Sat, 22 Oct 2022 07:58:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4598C433C1; Sat, 22 Oct 2022 07:58:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425488; bh=NI1fBXPVYlDZ4B6j6GMBIhhEi5k4CLiLesxDmWTMZN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q48ZTopRp9I5z4OnjJqvBCuB+HbLzOsxSkgHiMOLlH8alBh5jnqkeKG6ef98tAJzW jdvViRoeCE8SzMlU/1OfDykjp6ISuaW3bSs5grrdq3YKcPhCvEehrumbbX3A9yXPRF JcLCNz33JGanPAZ0llXIoRHTzzzUXIs2KnTF2GCY= 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.19 517/717] crypto: akcipher - default implementation for setting a private key Date: Sat, 22 Oct 2022 09:26:36 +0200 Message-Id: <20221022072521.161399308@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@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.3 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