Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1044345pxu; Fri, 16 Oct 2020 02:19:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfgbg6DbgTMbTkOlsOTBp1Ppod5aLXDV4UN+sENY0vQ7qkF7EmrRH/nscdz/trhTM9MD80 X-Received: by 2002:a05:6402:d06:: with SMTP id eb6mr2674729edb.289.1602839989034; Fri, 16 Oct 2020 02:19:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602839989; cv=none; d=google.com; s=arc-20160816; b=WtDn9JYmQoCnJKD35+eW8u5oERlHQ6Amzfo3ta0vZUQz4TZgmaDg54pLUcwWI4ekbe vc0EDqyAYhp7ZuzMJaIhJDxYbh6Gqa+hVSGsS4V/OG829w8cjvPHtDGcXdEMPQ7nNanB 3QrKZriEW3zsDVGxebt+uZ4GzCZHrhSlWJcL3LDngnt9nkN+/W0bnGB5J2tYjVy4iA6C hx0WDADTRdhjieEj4wgFA6VoT4GWjNm6xeaZxvgt4WMytIswWkbSEVXHob3Cppoj/VYx O0gRjidEc9GPmxxph8jP3sIu+QXTSdtPUuOTLZe7rSH9TvR5lAo0uwEe9FSMQuca9jOa 1brw== 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=rwjE8/jTsaDWCiKC+f3twOwnJKGIqDhIxc9I2COwOJo=; b=PiAFxRqZCVNIu3EjeK2mMMbAPlJQ80JkxlD7mf8JFLzzP46z0A715BzW6Pn8NCQHNX +3CnxL8bcYMTDnArVq6RTexWBWvfJ8fVaa0qXeCuNIU4ZnCFApHQN+XhbRM8VDBB1O3d ccI7ejvniceHealhp/IOExlYOj9in5kxejQJePgDz5aMEaJQZZlxpCFQbL/DU258ihFj VU1fUooX5EkoF54qzXstNSqgbHDLrJWx+8qU7QFJPxn6bH+jOcE5kYg33MVpn41x9UDK 4QD7RXD3sA9VF2baI4gQwwXWJp9G0zMWi61w1X4gqLObDJQBBHJjWMh713UNUXd5rZwi I9Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Sf6TqRcQ; 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 bs2si1175451edb.384.2020.10.16.02.19.26; Fri, 16 Oct 2020 02:19:49 -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=Sf6TqRcQ; 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 S2405645AbgJPJPd (ORCPT + 99 others); Fri, 16 Oct 2020 05:15:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:37900 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394995AbgJPJJM (ORCPT ); Fri, 16 Oct 2020 05:09:12 -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 2946721655; Fri, 16 Oct 2020 09:08:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602839335; bh=COM/Te4iqO9NnMy2quCcA/pdUoQRtqVWkBeyU9fWHT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sf6TqRcQBGeSK59QeAau5+2XkD5UuWvNBWyRmWbNCSn8Dp4UqiAKCAhuwyf5vhkev N/AwEyWKPBLQP+6k69mJmOcCZ8gO3tKsInLJ6HsrNzGV5KfGXwhUP7n55mLsI1hi2L 7YSh1Z0ydpvQ6SN2pZJKSEUvRbSIyg258ifyvu9g= 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.14 18/18] crypto: qat - check cipher length for aead AES-CBC-HMAC-SHA Date: Fri, 16 Oct 2020 11:07:28 +0200 Message-Id: <20201016090438.182380361@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201016090437.265805669@linuxfoundation.org> References: <20201016090437.265805669@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 @@ -825,6 +825,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)) @@ -839,7 +844,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)); @@ -868,6 +873,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;