Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1381358imm; Sat, 4 Aug 2018 02:13:48 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdQUi7sy3o+8vY2Dv8RcMPZdV2l6gu42xOly2z9TWSTuihB1xvW8gNUilHzsASHBdnMOqUU X-Received: by 2002:a17:902:bd44:: with SMTP id b4-v6mr6756288plx.144.1533374028268; Sat, 04 Aug 2018 02:13:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533374028; cv=none; d=google.com; s=arc-20160816; b=alWMGAw0qS5Qs1vdf3AY7LaI1zMAUaiwUtccVn1UYyccp0jeGM2ftTOHQKy2e1XlYX n0Spi5zCAFOo5qMenHcIlRVNIOypM+SbSJKFgYC3+xMX/ZuweNAe0pxU1ES2pGH2pT42 YYTfaE17H7lL8ymUvTvBpZHckUS9Li7IAz4KU7ygmD7BfZ0pOAThz2gIUYLBgO9Ozgp3 w2MT6wK37jW7spI0VxZvRQ8dTeZzv3td2v4Qm0cf5zOQY+S1b7cvdVqTIUqZ9v/tjeKa T0869k9iBkhe0+eFA/LTm8bjAYCpjtXOWyW6mirXJg/8/USM/up3VjtaxfSMKiiZlpq7 o2vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=rZ6Mh3SqkRA2EuUN4sSBfpx7HS+TJgZ/5QX7SGyX3yA=; b=nJeRPP/uXXlsw5r/rLoy8fLZpN2OOsv4ODraGqG2Qbna1KUEQvujpMQXsNCHNcywdk ew5MPOZY9YLrwsrztj6sEqDBqjNMZI0ewlI1ZT5CJRP97uink0zV5xV2GxADnzaWOj0Z /rwvAsmWzffmnFDRckxYgphrX17w2Rl7mHY7QoHvQS6RVnlzhQSZQWZ+Yrr64WECht7z I/TQ7U74aDrx8HIl8xTFLdCuKjsAI1DQdCwWediGiVe1ovzEdcjPxYE9fCK5xgT9HjW+ zvF3pFagN6vItpecDeLptaNMf1fVVoreZHjGKPBl2iHs/CvebFhJdNp+7v21hVDSVvmb iTfg== ARC-Authentication-Results: i=1; mx.google.com; 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 f2-v6si7599085pfk.97.2018.08.04.02.13.33; Sat, 04 Aug 2018 02:13:48 -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; 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 S2389478AbeHDLMj (ORCPT + 99 others); Sat, 4 Aug 2018 07:12:39 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50472 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388557AbeHDLMi (ORCPT ); Sat, 4 Aug 2018 07:12:38 -0400 Received: from localhost (D57E6652.static.ziggozakelijk.nl [213.126.102.82]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 88534BBF; Sat, 4 Aug 2018 09:12:37 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jamie Heilman , Herbert Xu Subject: [PATCH 4.4 123/124] crypto: padlock-aes - Fix Nano workaround data corruption Date: Sat, 4 Aug 2018 11:01:52 +0200 Message-Id: <20180804082707.056362975@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180804082702.434482435@linuxfoundation.org> References: <20180804082702.434482435@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Herbert Xu commit 46d8c4b28652d35dc6cfb5adf7f54e102fc04384 upstream. This was detected by the self-test thanks to Ard's chunking patch. I finally got around to testing this out on my ancient Via box. It turns out that the workaround got the assembly wrong and we end up doing count + initial cycles of the loop instead of just count. This obviously causes corruption, either by overwriting the source that is yet to be processed, or writing over the end of the buffer. On CPUs that don't require the workaround only ECB is affected. On Nano CPUs both ECB and CBC are affected. This patch fixes it by doing the subtraction prior to the assembly. Fixes: a76c1c23d0c3 ("crypto: padlock-aes - work around Nano CPU...") Cc: Reported-by: Jamie Heilman Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/padlock-aes.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/drivers/crypto/padlock-aes.c +++ b/drivers/crypto/padlock-aes.c @@ -266,6 +266,8 @@ static inline void padlock_xcrypt_ecb(co return; } + count -= initial; + if (initial) asm volatile (".byte 0xf3,0x0f,0xa7,0xc8" /* rep xcryptecb */ : "+S"(input), "+D"(output) @@ -273,7 +275,7 @@ static inline void padlock_xcrypt_ecb(co asm volatile (".byte 0xf3,0x0f,0xa7,0xc8" /* rep xcryptecb */ : "+S"(input), "+D"(output) - : "d"(control_word), "b"(key), "c"(count - initial)); + : "d"(control_word), "b"(key), "c"(count)); } static inline u8 *padlock_xcrypt_cbc(const u8 *input, u8 *output, void *key, @@ -284,6 +286,8 @@ static inline u8 *padlock_xcrypt_cbc(con if (count < cbc_fetch_blocks) return cbc_crypt(input, output, key, iv, control_word, count); + count -= initial; + if (initial) asm volatile (".byte 0xf3,0x0f,0xa7,0xd0" /* rep xcryptcbc */ : "+S" (input), "+D" (output), "+a" (iv) @@ -291,7 +295,7 @@ static inline u8 *padlock_xcrypt_cbc(con asm volatile (".byte 0xf3,0x0f,0xa7,0xd0" /* rep xcryptcbc */ : "+S" (input), "+D" (output), "+a" (iv) - : "d" (control_word), "b" (key), "c" (count-initial)); + : "d" (control_word), "b" (key), "c" (count)); return iv; }