Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3695944ybv; Mon, 10 Feb 2020 04:53:21 -0800 (PST) X-Google-Smtp-Source: APXvYqydbSqImlH1u1JAfPaFfjYDjn2l2tPDtB3Ift/vVnXEnN2yqLasZb91m0MKraqFWsXeZgoQ X-Received: by 2002:a05:6830:18f1:: with SMTP id d17mr913664otf.303.1581339201393; Mon, 10 Feb 2020 04:53:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581339201; cv=none; d=google.com; s=arc-20160816; b=RVtm/x2uMi7s1cop+tUpZskfxeX9O5bJqJhWOSlkNAIXN5WceuMFDvPnwqAy/By67S grXTtdFllv2qwC3aW8NljZG3jRY2uYWLZq7+okyNk6lIyWiuhLo9W9Mcw+OgF/d3Jmv4 gclQ5N9S322g03ZJvHsquQy4fui6N9Az0z0KZZT4QuIzdNsLtzWLJ2qBGrRzd3ovcngN kr72hbneCQbZjuC7aAITRjQsCasNV8JkOkWuiQGyunr1ee2gULBEbenOegFtFIplkdUK RyIz1JCldLx64j3eYdB2V4tk74XLkoJdM8jcDWay5hP7tQcCrI72rO9j3d+RJZJjBqAk KZdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ie7yEB+oJbazZfa/+WVu2oZq7HIAt6JSojt24Qej0yg=; b=0Z0M5fTykXYTej+H7VRP9fa4LNd1azgaCgE8mc0TvOUww3j5rhTtyQ5oy2Y0MpcNmU 1u9vXNfAt57muzTZH4RI7v2TuH6PuXoVKmBd0LSfla02bBYDLvEaon0iHtADVjT//Mmf wSChlKbzHVCZOfHWSV44K3DOp6rkYtCd6tClJmwWPX4qirb4AMYZJIANBMMqG3oU6inc RPWoqSqbBtDOG0zSN9oZb0keD+lM97ntjZMZY4XwzuWYAJtoJZo0JIwZYIVAvI+VLIO0 M7iymATlRtfmNfpIfZicP4MOxeF3swI+LdRZPxlYcAiW2niJzQn+sgz+KRBTSdpPbqAb Ai7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BIcJTY5T; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i6si170881otp.5.2020.02.10.04.53.09; Mon, 10 Feb 2020 04:53:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BIcJTY5T; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729341AbgBJMw7 (ORCPT + 99 others); Mon, 10 Feb 2020 07:52:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:46368 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729933AbgBJMmQ (ORCPT ); Mon, 10 Feb 2020 07:42:16 -0500 Received: from localhost (unknown [209.37.97.194]) (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 3457720733; Mon, 10 Feb 2020 12:42:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338536; bh=eORnYaaVgk1tB4klU3Jhd6OSbnxmgAiQcJcl2bSQH78=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BIcJTY5TmJDekrRLA2CvYS7gX1qTRrn+rEl/fnmnHcBBDAcjT/Hi7CKcJ3iD5Oh2Q URornUJpooMKvNMsu1mo4bRwUkIGaSxDlJ6KMvuf2d1KVjk5LKXJLBo7nrHSCrklV0 wcF2hljy5pdidcd5iF3mzz/FOIeYA2ZIVN1Y4wsg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Tudor Ambarus , Herbert Xu , Sasha Levin Subject: [PATCH 5.5 364/367] crypto: atmel-aes - Fix CTR counter overflow when multiple fragments Date: Mon, 10 Feb 2020 04:34:37 -0800 Message-Id: <20200210122455.932626656@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tudor Ambarus [ Upstream commit 3907ccfaec5d9965e306729936fc732c94d2c1e7 ] The CTR transfer works in fragments of data of maximum 1 MByte because of the 16 bit CTR counter embedded in the IP. Fix the CTR counter overflow handling for messages larger than 1 MByte. Reported-by: Dan Carpenter Fixes: 781a08d9740a ("crypto: atmel-aes - Fix counter overflow in CTR mode") Signed-off-by: Tudor Ambarus Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/atmel-aes.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/atmel-aes.c b/drivers/crypto/atmel-aes.c index ea9dcd7ce799b..b4dee726b2530 100644 --- a/drivers/crypto/atmel-aes.c +++ b/drivers/crypto/atmel-aes.c @@ -121,7 +121,7 @@ struct atmel_aes_ctr_ctx { size_t offset; struct scatterlist src[2]; struct scatterlist dst[2]; - u16 blocks; + u32 blocks; }; struct atmel_aes_gcm_ctx { @@ -528,6 +528,12 @@ static void atmel_aes_ctr_update_req_iv(struct atmel_aes_dev *dd) unsigned int ivsize = crypto_skcipher_ivsize(skcipher); int i; + /* + * The CTR transfer works in fragments of data of maximum 1 MByte + * because of the 16 bit CTR counter embedded in the IP. When reaching + * here, ctx->blocks contains the number of blocks of the last fragment + * processed, there is no need to explicit cast it to u16. + */ for (i = 0; i < ctx->blocks; i++) crypto_inc((u8 *)ctx->iv, AES_BLOCK_SIZE); -- 2.20.1