Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp601159img; Fri, 22 Mar 2019 04:57:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqyafLxvtoU+TVXJzgOwbYVOiv5k+VFhhS6N2AMbJtl8UTgFgkVNF2uw4y4NsbIOY5viTQv6 X-Received: by 2002:a63:408:: with SMTP id 8mr2858777pge.334.1553255853786; Fri, 22 Mar 2019 04:57:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553255853; cv=none; d=google.com; s=arc-20160816; b=TI3esirCcegohkML3HEvgYqQV3kNmFthU/4HTAt+EZBoJ4IQr/7xtmMdCjCplTE9ip 6u5cf41W1ebCi0A2bH9p1fnsHVxYr3BQN6CKunvLPrD3EjSXN5vu7eCrhsUzZaS0kZaI ibvywEDPUpW1dO3VhXsPke0mhAKJeASVkjiA3hIlDmTAAgaxmDPihRBlfqlFGQWYhd0G NO6UN9lwWiX+6mVof7zBW4GVlQ1BgLcyYLh2XEF1JYj+XPvAB0Wlu0DLtgfCNSGY64p+ Im3LyaW5cHKHcKdeLOviz3whog32vEnsOMFE6p4BHRgf97vl6ubyxC9jAYvor2iAcFsE MjkA== 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=FAlF4jZ7apaEsn5YYJLaQkuz5DKUZz3lkPj6wi0bZTg=; b=EKnDpO4B4uvHxcuy0+9JXIOu7Lo+hNFlA1pcckzT6IkGUyDIxqKMizcH7XPjzg9RBl 3s/AYuDoS1OwjfiFFilN8kgNiTGF89f9pRCSbCRK+2RSZ9Hqw1tZufy5ddAcfxD+XfXB kxqoNPW9tJxlJb2uDBay3FlGzDCpM66B2psXQe8GQRX7iBRkPh6UPHbGZPeHMlQYupg3 Hb+XBEpuF/zzSOexuZBBx2heqTe56TRRPksPJS/Pm1X2ql9jwNbZEFWx0Oz+nG0L8g6C iH9+jGwI+xHibltDpIflTGCcfRhhIrdlbUUEkgMEEKwb8kR0dT5lZQ0wOi56spzQCbbv IEJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UUr2pNst; 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 p65si6529219pfa.27.2019.03.22.04.57.18; Fri, 22 Mar 2019 04:57:33 -0700 (PDT) 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=UUr2pNst; 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 S2387563AbfCVL4o (ORCPT + 99 others); Fri, 22 Mar 2019 07:56:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:33164 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733132AbfCVL4m (ORCPT ); Fri, 22 Mar 2019 07:56:42 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 3FBDC2082C; Fri, 22 Mar 2019 11:56:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553255801; bh=55zJjsNJZMLBtFVBBuk/dGlmVNkhL0j6qxhIMw1KMGQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UUr2pNsttnG9cYeBbGfoDs32tgcwC3MwNFq3VrG3u/pjMMMdhq7kU2aj32xIdwMNY NJeEnMOe1Bm5A/Wgrt/1P1H+GELn5Rg+S/wRE0Ho5KE2MDgwcuXocJC8fV437mq1VP +JjL2JHr1Qli7BSi5HWAyiBp3fZChhWxcgeoa7WQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, James Bottomley , Eric Biggers , Herbert Xu Subject: [PATCH 4.19 019/280] crypto: cfb - remove bogus memcpy() with src == dest Date: Fri, 22 Mar 2019 12:12:52 +0100 Message-Id: <20190322111307.383697661@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111306.356185024@linuxfoundation.org> References: <20190322111306.356185024@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers commit 6c2e322b3621dc8be72e5c86d4fdb587434ba625 upstream. 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 Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- crypto/cfb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/crypto/cfb.c +++ b/crypto/cfb.c @@ -77,12 +77,14 @@ static int crypto_cfb_encrypt_segment(st 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(st 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(st src += bsize; } while ((nbytes -= bsize) >= bsize); - memcpy(walk->iv, iv, bsize); - return nbytes; }