Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp634656img; Fri, 22 Mar 2019 05:36:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqweHx8sMSWyDpkVq05Nt7PKwd6fS2+NpBMGQ+rh61jhFQP/8SdHGVGeHEp3dqABoXOsNCyE X-Received: by 2002:aa7:8144:: with SMTP id d4mr6538149pfn.88.1553258167955; Fri, 22 Mar 2019 05:36:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553258167; cv=none; d=google.com; s=arc-20160816; b=h/69GXLUEZDP724LMLFW4qzw7D60u9esm8+ArlcqTVZeW3vvZqtpGzJSnv6Q8163SZ g/99uh/nGAKg1m6eKCCaHLWyGAtiWCPHfxOso0/EvsradUnwi8ytR1huGdpa+ObEtpyx NnYEG42l1tDQQBVh9jYVnIR/SZyYVgbz2A+6goMukAeNboteVcj9N1zFHCyJCvQ/MRJ9 CERLB1E5+Qw7rpoaL8SHgi07UpJzRhyj4DJcR3cDY39N9aR/7SyGacnidUSNs7m7KEzU joT5eumGdUDGVxXvvqd4mRYYSfAPnu3nRL84iuqy9l7DoHdMnMz3UPaqh0iV5OKGilyb uNIw== 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=KEV9s7Tj/adKzO0esRTdcn8whSqJAGG/wxi/E7RYWs8=; b=OYJCI3GkZt5Y+xSila35u8ECA830TrJ+5R4aoUSacguCWkn00h7TzzIIMxG/XqbSxq le7SXsk4+lD1FCkz/4I/2Rrfd6zOe+hYqG+H05n6d2375BLvozcsI6LHlOB+xbe60DJr aEWZL887xUOoRM1tWySCxhPN/guo5DeAZlWTgEai6W+Ku85zf8m653fU+8/unRAKfqpi c5KPYJwoe5bUO7y7C2MOLaaE4j6P5E82Jy1ga/7o6Y/yD9NPFUm7xKNBrP3Q5uRXeFUT 38t1EOpdmNU2JQWoC/EJDr7DKQDg4tNwH3rJ8s4Q/zERls6+JpCP89Ozx2gQenDBL6co MwVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z7g9yY0A; 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 q12si7147835pli.428.2019.03.22.05.35.50; Fri, 22 Mar 2019 05:36:07 -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=z7g9yY0A; 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 S2389641AbfCVMMm (ORCPT + 99 others); Fri, 22 Mar 2019 08:12:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:50796 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389635AbfCVMMg (ORCPT ); Fri, 22 Mar 2019 08:12:36 -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 BA4922082C; Fri, 22 Mar 2019 12:12:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553256756; bh=0V0c+/1w+jRKUyNBBFtpMgr5s6ZlfKq8NnweGIyQW04=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z7g9yY0AEEhHPVrbYjQ0QKmgQ7MZHKmy3Nykly39Y9Q+YKhbEtumqhDvhr9HVIbd4 UYzgn7XG+qs+eIa7mlGZHHkKwh8BzgtrVHwjAiDlbK+oyvesCMT6DEVqQ/SA4kWJ+E RaJXuh193RaYdAXt3bkbwkkATL2lMxd0YwkYJG3c= 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 5.0 020/238] crypto: cfb - remove bogus memcpy() with src == dest Date: Fri, 22 Mar 2019 12:13:59 +0100 Message-Id: <20190322111259.357936764@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111258.383569278@linuxfoundation.org> References: <20190322111258.383569278@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 5.0-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; }