Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3306826imu; Sun, 11 Nov 2018 12:03:11 -0800 (PST) X-Google-Smtp-Source: AJdET5dtgA38uK01loJpJYLrqJxdPgy32DMAOA/t89n3qCNPkKrOE0kx9S0N/IoWKuXPp5Vzsn8Q X-Received: by 2002:a63:d52:: with SMTP id 18-v6mr15153601pgn.107.1541966591293; Sun, 11 Nov 2018 12:03:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541966591; cv=none; d=google.com; s=arc-20160816; b=jKwq2FtZZ1VP2tA7Qj6Gl5+7QoFhLV0g37osZUJ4Z6rNT7OyN32R024NbgdpqMjmyD 0vcbe5MNRk38SuXf8t+SQCQ6diDz0GeVFM8RHUc6sCl/yGNz0GhyqjYRwyKZIdGfbRYD AjTpycFqzIKilbzDYunAFaD+GvEdURDPKQ6f4bzGUNBTEyGp8JZoV07IMi+iqm7uoHFl qfYMHvnM+v6mPLKGlzAueTGXJcJm3VqjVaS6AuUlvsAvxUbekXB8ugnz4i9lbVmipuuv Tep2gEA9LOW2Yr1rAeAXM4IHXJVemqGDfe106ly9N2myHWP0vTOvGimL3ya4oy8D7lTu 7IEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=PmW5RbbYWpknTfNQ/zihVk1tM1KOh6XpvdWmeiRWHBo=; b=wyJ9txDi6Z0TXC1rxK719EunF+M5tlL5pXzok4hQ5nmiATM6I8xJFIMlpSlJnQ460v LORw3lg++0V9bdVSg0hEJ451edKsPxhscMGmYCds39J61ukz9kZCGix5KpxsE7AP9Fq6 PTF34nb9yZ+Gs7mJq7zPYliCy5bDhm9YIkFHXeauZAOoszRICnfaoP5gW4otdmfus63q fJuSpzWBNpMChPOdA5G7xNbuQfeQEEe/brniS+ioEcdXoFT0vUhepfYkRS2zsfCEgW+B 2iWESMtnBDyDbRxatLCbAf5SYIaWGmkj7yz+zkpiune4rYuJMNgqhwsmequl4Y0q0QqW 75cw== 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 a61-v6si16932984pla.430.2018.11.11.12.02.56; Sun, 11 Nov 2018 12:03:11 -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; 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 S1730757AbeKLFsc (ORCPT + 99 others); Mon, 12 Nov 2018 00:48:32 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:51022 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730688AbeKLFs3 (ORCPT ); Mon, 12 Nov 2018 00:48:29 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsp-0000lG-0O; Sun, 11 Nov 2018 19:58:59 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsX-0001kk-DW; Sun, 11 Nov 2018 19:58:41 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Jamie Heilman" , "Herbert Xu" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 272/366] crypto: padlock-aes - Fix Nano workaround data corruption In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 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...") Reported-by: Jamie Heilman Signed-off-by: Herbert Xu Signed-off-by: Ben Hutchings --- 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; }