From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18B55C43387 for ; Fri, 4 Jan 2019 04:20:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D3211218E0 for ; Fri, 4 Jan 2019 04:20:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546575655; bh=VsEMTpilzeFzM7vW6x9V6YpkX4XK/EWEuH3g+1vqzBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=yjUj7yla5fTA7kj3gfbtR154DUTYMH1MtcoLnjEksizWooKcFZ78/w4QzQ/mrr5qR Y5K9C3N3J1ZIigtkomnByb4M6PsJS7TeT8fUaq6pAmO8lhrg0YS3PoAaeTXqslPQ9t BoRMF0efHl2VS6B9k+HV7VlBd328PWM8pCxyNs9s= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727713AbfADEUz (ORCPT ); Thu, 3 Jan 2019 23:20:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:56358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726041AbfADEUy (ORCPT ); Thu, 3 Jan 2019 23:20:54 -0500 Received: from sol.localdomain (c-24-23-143-129.hsd1.ca.comcast.net [24.23.143.129]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E368321872; Fri, 4 Jan 2019 04:20:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546575654; bh=VsEMTpilzeFzM7vW6x9V6YpkX4XK/EWEuH3g+1vqzBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TWVetJ7K0UVM8njTPLJKuuBY1IfEI4w+cosQ22BJogvNNexkGN6J4G0Mk0h4+UDv3 w7eIm7MlKrt9BPL6aMyZollF5NC+80OsPJ0/f7z7q5W6QDivgFlWVGaTOccp17+MBd IyGrWgVgW+aSrE5h57RZZvA2JdgCSqSSxFDpI7kY= From: Eric Biggers To: linux-crypto@vger.kernel.org, Herbert Xu Cc: stable@vger.kernel.org, James Bottomley Subject: [PATCH 02/16] crypto: cfb - remove bogus memcpy() with src == dest Date: Thu, 3 Jan 2019 20:16:11 -0800 Message-Id: <20190104041625.3259-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190104041625.3259-1-ebiggers@kernel.org> References: <20190104041625.3259-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Eric Biggers The memcpy() in crypto_cfb_decrypt_inplace() uses walk->iv as both the source and destination, which has undefined behavior. It is unneeded because walk->iv is already used to hold the previous ciphertext block; thus, walk->iv is already updated to its final value. So, remove it. Also, note that in-place decryption is the only case where the previous ciphertext block is not directly available. Therefore, as a related cleanup I also updated crypto_cfb_encrypt_segment() to directly use the previous ciphertext block rather than save it into walk->iv. This makes it consistent with in-place encryption and out-of-place decryption; now only in-place decryption is different, because it has to be. Fixes: a7d85e06ed80 ("crypto: cfb - add support for Cipher FeedBack mode") Cc: # v4.17+ Cc: James Bottomley Signed-off-by: Eric Biggers --- crypto/cfb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crypto/cfb.c b/crypto/cfb.c index 183e8a9c33128..4abfe32ff8451 100644 --- a/crypto/cfb.c +++ b/crypto/cfb.c @@ -77,12 +77,14 @@ static int crypto_cfb_encrypt_segment(struct skcipher_walk *walk, do { crypto_cfb_encrypt_one(tfm, iv, dst); crypto_xor(dst, src, bsize); - memcpy(iv, dst, bsize); + iv = dst; src += bsize; dst += bsize; } while ((nbytes -= bsize) >= bsize); + memcpy(walk->iv, iv, bsize); + return nbytes; } @@ -162,7 +164,7 @@ static int crypto_cfb_decrypt_inplace(struct skcipher_walk *walk, const unsigned int bsize = crypto_cfb_bsize(tfm); unsigned int nbytes = walk->nbytes; u8 *src = walk->src.virt.addr; - u8 *iv = walk->iv; + u8 * const iv = walk->iv; u8 tmp[MAX_CIPHER_BLOCKSIZE]; do { @@ -172,8 +174,6 @@ static int crypto_cfb_decrypt_inplace(struct skcipher_walk *walk, src += bsize; } while ((nbytes -= bsize) >= bsize); - memcpy(walk->iv, iv, bsize); - return nbytes; } -- 2.20.1