Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5006596iob; Mon, 9 May 2022 06:47:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhdHHOJMmt7pbYeBEyswL7Q/4aYvBh7ISt3GAB+PCMG06rDv86I6i2tTMC4phQAWlmtWIC X-Received: by 2002:a62:e80d:0:b0:50d:8f8e:ffb8 with SMTP id c13-20020a62e80d000000b0050d8f8effb8mr16305340pfi.37.1652104051119; Mon, 09 May 2022 06:47:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652104051; cv=none; d=google.com; s=arc-20160816; b=VGcA4Oo0WshPOcYXQ0yFgDnjOgWw/+Yb6C41katDQheDfhY277OGMvziuLKxr40nU8 zjHzuqMIR7gPQGYn5IYFHF9dk4uzKidg6CvwgERzxAIRajX2M1r5Lua4v22bR4cwWyoB XBdF8/TeXGCH15mz3v7Cb4Vrbl3cRREhuHUCzm3aQigRa2Z2E5Yle1g36S5Htzb4VXic w2NN2NlwjVjJA/OQRLuEk7ib6GU+rHZykmry/N7k0YgOk/lFv1vOwgDf5dLtWuzkOXpC Z+rLGECSefzxSP8fMYMfabFv8vHffQmWAh/7icKGZeA7Bw2oLT11w/Gd44SiACKRq9Kc i2Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:organization :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eIQJDgog19+zlB57Mz3DtY9St+deNCz5jXmalhE2BVQ=; b=UXADSQnXKWPYlKy0yT3xJddxi3JYa9WvIfZV9rGMafhwtZ73y6jygCuH8PvWifPid1 Rv6GCZYxGxX9cY4bJjCePs9g5YnVVjSUf/hwmwEP9apKb7Niigj76YwrgxXsfz7SBqiD PdgvZClev3z+FZb4FPkgWlraZKzVKwwaKEt/b8N8rQIku1ZVeoFETYz1uvidIbvmOyRb V0NQydQihfT4cvNdKBKIwM0khYkWkSwqnfYmzqocprV8DB6yvU5MuXCPj5Wl0Y4u+vZx EQCim4sO70f5+6E3iB+nQHR8lar2UMwymgx9QNqTsMGReqK7xkBLH9AiePW6THJk5Akd cCeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UJKwbDsg; spf=softfail (google.com: domain of transitioning linux-crypto-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id u191-20020a6385c8000000b003c260491a1esi14013479pgd.172.2022.05.09.06.47.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 06:47:31 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-crypto-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UJKwbDsg; spf=softfail (google.com: domain of transitioning linux-crypto-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3D63322291; Mon, 9 May 2022 06:35:41 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235899AbiEINja (ORCPT + 99 others); Mon, 9 May 2022 09:39:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235839AbiEINj3 (ORCPT ); Mon, 9 May 2022 09:39:29 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E800924D62A; Mon, 9 May 2022 06:35:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652103335; x=1683639335; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DyfWIgo2v92FeS25yt2Fm6CFdJ2n1oBzonkJ0Ac0ttg=; b=UJKwbDsgq7a8g4KmwmmLg8tXY+G+oKcREi/+0rmuyNeDAa1JWgCt3gWq beDZSU/JOJvsaNvuOJjeK3B4+lwdhbDne69mDNTHCfwxtuUGBpKkCXcLk zJOE6Vcw7TJFUY9R0Tl6jKNcjD0VOGwxc35pvi+vT13VQANMkU2cIYJ6D N6XiJVj8n1aSKXsHiWRWV0JdzgOP5untHnf7uyIdVLXZ0qGBpe3pbz61X BBb82yijj0f5ji8vBZTu1E2uPDke7hy8dqZ6NW4bzVRZd5GY7RBcg2FFS csJfiveB6J0qpQDvEqz3guYa6VPeWAQ8Re9KY7yY55Kw3hwQy6x0xgzo+ A==; X-IronPort-AV: E=McAfee;i="6400,9594,10341"; a="248952356" X-IronPort-AV: E=Sophos;i="5.91,211,1647327600"; d="scan'208";a="248952356" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 May 2022 06:34:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,211,1647327600"; d="scan'208";a="622967404" Received: from silpixa00400314.ir.intel.com (HELO silpixa00400314.ger.corp.intel.com) ([10.237.222.76]) by fmsmga008.fm.intel.com with ESMTP; 09 May 2022 06:34:37 -0700 From: Giovanni Cabiddu To: herbert@gondor.apana.org.au Cc: linux-crypto@vger.kernel.org, qat-linux@intel.com, Vlad Dronov , Giovanni Cabiddu , stable@vger.kernel.org, Adam Guerin , Wojciech Ziemba Subject: [PATCH v3 04/10] crypto: qat - fix memory leak in RSA Date: Mon, 9 May 2022 14:34:11 +0100 Message-Id: <20220509133417.56043-5-giovanni.cabiddu@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220509133417.56043-1-giovanni.cabiddu@intel.com> References: <20220509133417.56043-1-giovanni.cabiddu@intel.com> MIME-Version: 1.0 Organization: Intel Research and Development Ireland Ltd - Co. Reg. #308263 - Collinstown Industrial Park, Leixlip, County Kildare - Ireland Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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-crypto@vger.kernel.org When an RSA key represented in form 2 (as defined in PKCS #1 V2.1) is used, some components of the private key persist even after the TFM is released. Replace the explicit calls to free the buffers in qat_rsa_exit_tfm() with a call to qat_rsa_clear_ctx() which frees all buffers referenced in the TFM context. Cc: stable@vger.kernel.org Fixes: 879f77e9071f ("crypto: qat - Add RSA CRT mode") Signed-off-by: Giovanni Cabiddu Reviewed-by: Adam Guerin Reviewed-by: Wojciech Ziemba --- drivers/crypto/qat/qat_common/qat_asym_algs.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/drivers/crypto/qat/qat_common/qat_asym_algs.c b/drivers/crypto/qat/qat_common/qat_asym_algs.c index 306219a4b00e..9be972430f11 100644 --- a/drivers/crypto/qat/qat_common/qat_asym_algs.c +++ b/drivers/crypto/qat/qat_common/qat_asym_algs.c @@ -1254,18 +1254,8 @@ static void qat_rsa_exit_tfm(struct crypto_akcipher *tfm) struct qat_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct device *dev = &GET_DEV(ctx->inst->accel_dev); - if (ctx->n) - dma_free_coherent(dev, ctx->key_sz, ctx->n, ctx->dma_n); - if (ctx->e) - dma_free_coherent(dev, ctx->key_sz, ctx->e, ctx->dma_e); - if (ctx->d) { - memset(ctx->d, '\0', ctx->key_sz); - dma_free_coherent(dev, ctx->key_sz, ctx->d, ctx->dma_d); - } + qat_rsa_clear_ctx(dev, ctx); qat_crypto_put_instance(ctx->inst); - ctx->n = NULL; - ctx->e = NULL; - ctx->d = NULL; } static struct akcipher_alg rsa = { -- 2.35.1