Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1141124pxu; Fri, 16 Oct 2020 05:06:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKpZVXQBhbEKeWJJzODJxqgWgOlOjv9K/Lv6CQfK7PElIUF4M4zajjwCXpgSzlZyjbLzTE X-Received: by 2002:a50:d0d0:: with SMTP id g16mr3441960edf.18.1602849987980; Fri, 16 Oct 2020 05:06:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602849987; cv=none; d=google.com; s=arc-20160816; b=U9VA6KzJM1QDPNfClvpmqfCcDx5XKkCGhInR4kJzd6GvJ9Ximyjux4H/44QU6zCarM UaelzWJJ2xPStRFyitL+XDeMcFpmxq6TIonblBFPNmwHjYHlCr70Ht0STwMJol2j5ido Xj9bECi4J23s+5NBEQGmm0TT8vrNDYcFSVd/6TEBiyiPxZN5w6wBKvcSiivyZ/P/sjd4 3xZ7VpIa+s8gpi/zlblG8FbkRgkY9p0cBR4nTSe4XfTpydmpHS8wxIJ1b1+i7fkSC90E a8fBHkyLryKY/WsEjTNclsIiCBLjquPz6iqHD/fykZOGEiOZH174I4EcoL86+8Y/IVm5 Od1w== 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=vmFdj6wTJ+c773Kt6G5cSZM++uS16FMFRWMBM20HGFM=; b=u8iNWuNssFVJrPbh5USEiJgC7U5clRHB1qclzFFloBHWTBCMMC1gSSmSZePJMWwwID 73B/P7NeSVQAmDbZAvpS14wYV5noQngAQnxyVkbaRlDOs7S9RcGmfT9nTDivsit6mVDQ B2EpcvnYQnh7Rwlu/lBmv+bTEXztbdVOumPF6GineJRRue0mKWzgKXpAFSX6G3lNiFyW ODZObobHGrzPUqZgtfg3Gxt45rXSo/E8Rib8v791/qakSYL/A2lSb3PJvHvNH6Sg0T3b q3IoMxW8VRW4YJSLknrFH+/k3wwaLxRHWl4zrlr3Z6SxR98cjyZK+wNXMVWWxz1vvBdD ZO5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yq0Ddy8I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i20si1430520ejx.686.2020.10.16.05.06.03; Fri, 16 Oct 2020 05:06:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yq0Ddy8I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405029AbgJPJIG (ORCPT + 99 others); Fri, 16 Oct 2020 05:08:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:36134 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394923AbgJPJHt (ORCPT ); Fri, 16 Oct 2020 05:07:49 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EA9EF20872; Fri, 16 Oct 2020 09:07:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602839268; bh=OA9ojlJD5BvhFcZM4dGPho+S/jI+oo7Wg7S4ULiNr1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yq0Ddy8I9GxQYlSjIpi3hZpmg0Snl7nXH25deeQAqqTB3hc7So1uWTFeMhLB/U0ek fTMlgR8RqYN1+Eqbv9PLwABTx55MDRS7vA20d/43bXZOfgURs7fJe9F1r07nl/khtP p7QDU6kSHAUk2TMvv8d1m2MIcfNHxXRgUfL0ICz4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dominik Przychodni , Giovanni Cabiddu , Herbert Xu Subject: [PATCH 4.9 16/16] crypto: qat - check cipher length for aead AES-CBC-HMAC-SHA Date: Fri, 16 Oct 2020 11:07:20 +0200 Message-Id: <20201016090438.004719238@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201016090437.205626543@linuxfoundation.org> References: <20201016090437.205626543@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dominik Przychodni commit 45cb6653b0c355fc1445a8069ba78a4ce8720511 upstream. Return -EINVAL for authenc(hmac(sha1),cbc(aes)), authenc(hmac(sha256),cbc(aes)) and authenc(hmac(sha512),cbc(aes)) if the cipher length is not multiple of the AES block. This is to prevent an undefined device behaviour. Fixes: d370cec32194 ("crypto: qat - Intel(R) QAT crypto interface") Cc: Signed-off-by: Dominik Przychodni [giovanni.cabiddu@intel.com: reworded commit message] Signed-off-by: Giovanni Cabiddu Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/qat/qat_common/qat_algs.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/drivers/crypto/qat/qat_common/qat_algs.c +++ b/drivers/crypto/qat/qat_common/qat_algs.c @@ -822,6 +822,11 @@ static int qat_alg_aead_dec(struct aead_ struct icp_qat_fw_la_bulk_req *msg; int digst_size = crypto_aead_authsize(aead_tfm); int ret, ctr = 0; + u32 cipher_len; + + cipher_len = areq->cryptlen - digst_size; + if (cipher_len % AES_BLOCK_SIZE != 0) + return -EINVAL; ret = qat_alg_sgl_to_bufl(ctx->inst, areq->src, areq->dst, qat_req); if (unlikely(ret)) @@ -836,7 +841,7 @@ static int qat_alg_aead_dec(struct aead_ qat_req->req.comn_mid.src_data_addr = qat_req->buf.blp; qat_req->req.comn_mid.dest_data_addr = qat_req->buf.bloutp; cipher_param = (void *)&qat_req->req.serv_specif_rqpars; - cipher_param->cipher_length = areq->cryptlen - digst_size; + cipher_param->cipher_length = cipher_len; cipher_param->cipher_offset = areq->assoclen; memcpy(cipher_param->u.cipher_IV_array, areq->iv, AES_BLOCK_SIZE); auth_param = (void *)((uint8_t *)cipher_param + sizeof(*cipher_param)); @@ -865,6 +870,9 @@ static int qat_alg_aead_enc(struct aead_ uint8_t *iv = areq->iv; int ret, ctr = 0; + if (areq->cryptlen % AES_BLOCK_SIZE != 0) + return -EINVAL; + ret = qat_alg_sgl_to_bufl(ctx->inst, areq->src, areq->dst, qat_req); if (unlikely(ret)) return ret;