Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3689868ybv; Mon, 10 Feb 2020 04:46:04 -0800 (PST) X-Google-Smtp-Source: APXvYqyu+qfczuGyOM3IYLe3eqqz6of+T3293CqUpJ0ikm1hXuh6txdV0azUBOz/Yd5uHeQRxO42 X-Received: by 2002:a05:6830:1049:: with SMTP id b9mr984426otp.100.1581338764799; Mon, 10 Feb 2020 04:46:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581338764; cv=none; d=google.com; s=arc-20160816; b=Ee0TQ5qjP2XEdS/Vjw5Q53hhp0MOiCmxrAl9nIqwLFmb96c5SMcj55oLPE2s31Dl8t hzR4pT+8MIvVYVVnl6LYIWX1NB9nK2mGuywHoGhTIX1af705Osm3F1a71OY9mLmSFwa3 KhztbvTuJc8zhTnFrVUiGAl2UiKkHmwiREMp7XPdaZzNzEynWbcavV91WiQLlrV+2x4b j+9vkGmr1QV8bsArx3NX6ht9bdkPAF88q3fr8mndJeeE+vlLB57KxTt7hprJQU1m5lH4 uQNUEgs9LGmoXlbIb4J5UkRcih9kqGCUWqeWTXgbTejDBz9Ji2cfHi0lGu7gUo/4rAXT kJxA== 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=ZKJjdIXpKb/flW2QUkEowzT4Yw/DobkViiU+UQOLVxA=; b=i/Sm/YfQ59wM1tMKMsLG9Bp8jfKEN+qppII2/j/fiCLtkK1ZFU5lI6FRG9kE+qOkNu U5Niq8hMtKE7jaH7o/ID+HOoenyMlsQoshu5zyo7YBJMbSYm3HsolVX3YrXc3JQcMD3q fjmwgH0bfQBbkEDBCpYLcMnfhnxwAJ+np8FugfM4HahTOIe7YqsZsPz81huMzJ+WQvO0 QRskd69YJHMalWj5nKwcMNd07RT/OicQ64b9U4J8pL96z5ADZmOeqiuyOKZaimDW5U5P RSoTiisP/mjbf0uUE5ClpbDeKmj2Lt40qzQ9CEAeLeHFnCgxnYcKSVnjMQSLh30tsRUw R9kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DPaZgdKL; 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 l6si141922otk.134.2020.02.10.04.45.52; Mon, 10 Feb 2020 04:46:04 -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=DPaZgdKL; 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 S1729994AbgBJMom (ORCPT + 99 others); Mon, 10 Feb 2020 07:44:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:41448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729788AbgBJMkp (ORCPT ); Mon, 10 Feb 2020 07:40:45 -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 144B92465D; Mon, 10 Feb 2020 12:40:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338444; bh=woxeyLAkwlgmJvJtTrHq6llJqKOshHaPE8L5XUAZeeM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DPaZgdKLePTyHElxVrMOqO4eUQhBiqmA52vhwt8XiHdVKNUz0kZat0F5DnX1GQ1e2 KCVHRKOGtmlF4cG5T1oddURXVIIVQUl+nBQqN/EQMc5VSyVMn5MhTEQv+evb8YTWIs dL98lFysEKX5t+KnIgVadLftzACbQUbu/InzBbdI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tudor Ambarus , Herbert Xu Subject: [PATCH 5.5 184/367] crypto: atmel-aes - Fix counter overflow in CTR mode Date: Mon, 10 Feb 2020 04:31:37 -0800 Message-Id: <20200210122441.685289605@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 commit 781a08d9740afa73357f1a60d45d7c93d7cca2dd upstream. 32 bit counter is not supported by neither of our AES IPs, all implement a 16 bit block counter. Drop the 32 bit block counter logic. Fixes: fcac83656a3e ("crypto: atmel-aes - fix the counter overflow in CTR mode") Signed-off-by: Tudor Ambarus Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/atmel-aes.c | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) --- a/drivers/crypto/atmel-aes.c +++ b/drivers/crypto/atmel-aes.c @@ -89,7 +89,6 @@ struct atmel_aes_caps { bool has_dualbuff; bool has_cfb64; - bool has_ctr32; bool has_gcm; bool has_xts; bool has_authenc; @@ -1015,8 +1014,9 @@ static int atmel_aes_ctr_transfer(struct struct atmel_aes_ctr_ctx *ctx = atmel_aes_ctr_ctx_cast(dd->ctx); struct skcipher_request *req = skcipher_request_cast(dd->areq); struct scatterlist *src, *dst; - u32 ctr, blocks; size_t datalen; + u32 ctr; + u16 blocks, start, end; bool use_dma, fragmented = false; /* Check for transfer completion. */ @@ -1028,27 +1028,17 @@ static int atmel_aes_ctr_transfer(struct datalen = req->cryptlen - ctx->offset; blocks = DIV_ROUND_UP(datalen, AES_BLOCK_SIZE); ctr = be32_to_cpu(ctx->iv[3]); - if (dd->caps.has_ctr32) { - /* Check 32bit counter overflow. */ - u32 start = ctr; - u32 end = start + blocks - 1; - - if (end < start) { - ctr |= 0xffffffff; - datalen = AES_BLOCK_SIZE * -start; - fragmented = true; - } - } else { - /* Check 16bit counter overflow. */ - u16 start = ctr & 0xffff; - u16 end = start + (u16)blocks - 1; - - if (blocks >> 16 || end < start) { - ctr |= 0xffff; - datalen = AES_BLOCK_SIZE * (0x10000-start); - fragmented = true; - } + + /* Check 16bit counter overflow. */ + start = ctr & 0xffff; + end = start + blocks - 1; + + if (blocks >> 16 || end < start) { + ctr |= 0xffff; + datalen = AES_BLOCK_SIZE * (0x10000 - start); + fragmented = true; } + use_dma = (datalen >= ATMEL_AES_DMA_THRESHOLD); /* Jump to offset. */ @@ -2533,7 +2523,6 @@ static void atmel_aes_get_cap(struct atm { dd->caps.has_dualbuff = 0; dd->caps.has_cfb64 = 0; - dd->caps.has_ctr32 = 0; dd->caps.has_gcm = 0; dd->caps.has_xts = 0; dd->caps.has_authenc = 0; @@ -2544,7 +2533,6 @@ static void atmel_aes_get_cap(struct atm case 0x500: dd->caps.has_dualbuff = 1; dd->caps.has_cfb64 = 1; - dd->caps.has_ctr32 = 1; dd->caps.has_gcm = 1; dd->caps.has_xts = 1; dd->caps.has_authenc = 1; @@ -2553,7 +2541,6 @@ static void atmel_aes_get_cap(struct atm case 0x200: dd->caps.has_dualbuff = 1; dd->caps.has_cfb64 = 1; - dd->caps.has_ctr32 = 1; dd->caps.has_gcm = 1; dd->caps.max_burst_size = 4; break;