Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5006656iob; Mon, 9 May 2022 06:47:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDzkUALmYUOPN+h6GxIDK41Ut07UvVJFkaMll0v/abQW78GHPJA9cmcXiiYmwoEvfuQHOl X-Received: by 2002:a63:6b42:0:b0:3c1:9a7b:cb5a with SMTP id g63-20020a636b42000000b003c19a7bcb5amr13518310pgc.563.1652104055452; Mon, 09 May 2022 06:47:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652104055; cv=none; d=google.com; s=arc-20160816; b=MMqfT2FgYaiJFJuCmKRRN1O97z4IUGyiq7snnNWOjwy+TrfHhnZ4ELr6O31FPkTXNX Ru3BdTX7z7e0P78IR3m64+FMdkuC7gZHetb82QBRlnNKaTF+IYYHKY77eMLnr/AIqb4a QpgfRv5RL8ebTlP1wP7xW9U0jUVTJJSMzgcCHrbOJDnzjpgcadqshFOtxlZJE37bVBow ghyPVntq+tzaKJHSh9Ugia4/vjHVD4lEet8y7FfglFxRsoxWzpO5OuHfgN+y8uayYyUR YIHHBpkM/nJzo8Mz/acZ44t0hsQqCG564xtskObadIkcB06p89ANeuMy2Jtiv5BgcLm5 Kv8A== 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=0AFtTh0fEIBFh/7xF9T+DlMIG9SSQn8+HGm3s6iKqxk=; b=t6ev1sObG4/Icbq2C8aI0sQ+VVTHt9NRdnLV9SVJWGuEeoYThj8bvZY4r9tr3yE+6F W+7sj6s22OJPMx12YsBsS8/VDHXmL42yMxA3Pa9Jvup/PjyLFFX4PuBXmYIm62vFoNYe 8zSK1PEChGtxvRfMgKW0t05XeUSMs0FmKxK8inVp7PD83HXr7/tVk9sshZMpSfLrBd+0 7p+52iAh1vGGZfnT1CTuND6+MLQPpGjAyl+NUZAmhkohMKCLfXtc+vtVhjFU5fhVzzCb qWQgeO9nXmG3cM6FAVV1Xkj8Dpt761N4B4Nt8Y1/+AjDjxWgKE7NhBTLGPIw7k6ax8kL toUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mALzJDjK; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i7-20020a654847000000b003c142fc5ca4si14031682pgs.336.2022.05.09.06.47.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 06:47:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mALzJDjK; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:18 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 E4EF81A801; Mon, 9 May 2022 06:35:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235943AbiEINje (ORCPT + 99 others); Mon, 9 May 2022 09:39:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235923AbiEINjc (ORCPT ); Mon, 9 May 2022 09:39:32 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 701D018E3D; Mon, 9 May 2022 06:35:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652103337; x=1683639337; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=t33e2+YegF4zf+48NI5mEFHSMTe/Pq6JDytbBpEJKfY=; b=mALzJDjK1zLqGApNP6OfuY8TPQ0wZV1/vKJ4eG0eoL3Esp39qhNM+qo3 rZbjiD+LL7BpQSJ9XsqcEJjRWM3IVRSZIoYq42jHEMYb6JNjn3FNjQL7p 2vn/O3Q+7ABaE7JfcpHJtHzLcpilrs5c+yJixp2psxxAMQ+6bEz6WDxOz DDYDVg6nrwy9BPJb++bSkE/Nd+vKGaqFEZYjp+nzD5Sx5LeR6edxC9K1b kkEMjx3rrSVFZ17yIIK7nBQzBaeC/IB0x4kdl6moZeOTc9UupSL70xpZs Xq2nz5ZorMzYp6kc07xh+ZuYv0HQcV+FpFxEgNhUcPqf60YNiONr19+xA A==; X-IronPort-AV: E=McAfee;i="6400,9594,10341"; a="248952390" X-IronPort-AV: E=Sophos;i="5.91,211,1647327600"; d="scan'208";a="248952390" 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:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,211,1647327600"; d="scan'208";a="622967553" 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:44 -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 07/10] crypto: qat - add param check for RSA Date: Mon, 9 May 2022 14:34:14 +0100 Message-Id: <20220509133417.56043-8-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 Reject requests with a source buffer that is bigger than the size of the key. This is to prevent a possible integer underflow that might happen when copying the source scatterlist into a linear buffer. Cc: stable@vger.kernel.org Signed-off-by: Giovanni Cabiddu Reviewed-by: Adam Guerin Reviewed-by: Wojciech Ziemba --- drivers/crypto/qat/qat_common/qat_asym_algs.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/crypto/qat/qat_common/qat_asym_algs.c b/drivers/crypto/qat/qat_common/qat_asym_algs.c index d75eb77c9fb9..1021202b2fbd 100644 --- a/drivers/crypto/qat/qat_common/qat_asym_algs.c +++ b/drivers/crypto/qat/qat_common/qat_asym_algs.c @@ -653,6 +653,10 @@ static int qat_rsa_enc(struct akcipher_request *req) req->dst_len = ctx->key_sz; return -EOVERFLOW; } + + if (req->src_len > ctx->key_sz) + return -EINVAL; + memset(msg, '\0', sizeof(*msg)); ICP_QAT_FW_PKE_HDR_VALID_FLAG_SET(msg->pke_hdr, ICP_QAT_FW_COMN_REQ_FLAG_SET); @@ -782,6 +786,10 @@ static int qat_rsa_dec(struct akcipher_request *req) req->dst_len = ctx->key_sz; return -EOVERFLOW; } + + if (req->src_len > ctx->key_sz) + return -EINVAL; + memset(msg, '\0', sizeof(*msg)); ICP_QAT_FW_PKE_HDR_VALID_FLAG_SET(msg->pke_hdr, ICP_QAT_FW_COMN_REQ_FLAG_SET); -- 2.35.1