Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp283197pxf; Tue, 6 Apr 2021 22:27:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/DDs+5AjHfecb9DZXPNFKqQJQlS+fAy8aJLn3IUj63VYXzCnvw8w2bg0JqKSm/3L/Mjga X-Received: by 2002:a17:907:7684:: with SMTP id jv4mr1739730ejc.231.1617773235354; Tue, 06 Apr 2021 22:27:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617773235; cv=none; d=google.com; s=arc-20160816; b=buowPp/VPYPwpFhYHAe9rtXilL/Fsh6WW0dF9+Zt9WazlAE7GzoThh5dSGHQfiXiSl 7mxjT2dnWrguhHYGay7D3b6nFujBUq5lTLB9qWAagfQbY2LRFV5rpP11vMtGK1pm9t9C BVYeXAARKHT+rldCBSuQL/lHvKtbn4jmYKq/tj4YG8ZrEc5K7VCb2uVHkKb0J6u5Ymuw rUXjAGnpK1PQS7qCceDYSZm5OToH9LVIAtedpu26xRn8tVytgxTQHPxrDJFDosnTZi3L PLLHNTmJbMpQFfSdAluwzugdmyWogp6dxLSA7tY7JUjqnciHqNGZRE0+7qELrEYBjEOL eNLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ebprtwauhxmrolVtAT6g30AcvRmCpzmGEQ/Ooeyg/jU=; b=QkiILf/EFtUEyM2q7t0k49GnkXpud3IWNnjrBBVoD4amXsnIP30IKn9jWncmIdAyTc BCCN30LGKj46BNu2NAuZnGqcijK60Oj4yEQ9ovhA6U/rbZbOJD7UNZjs8HGCVWyhvohi TCb7HrrNbYl4B158meTxaKyRYFcNljjF2YCahCWojUivkLK3opU1VYgb/d7YN9qFOW5E Ub09W/LU0hP68xJDbsY9Aw/vi82mK7wWEUQW5ea653tw4unlfpauMD07sdRyJwC+qllp QTxE8AOErR8NsFfsU8UnYrXYl+OSR+zrXZsxDqffdcX/t1k++ERBBeyTXEQ7KkEW1kU+ +VKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fPEL+PrN; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k16si9307093ejs.79.2021.04.06.22.26.43; Tue, 06 Apr 2021 22:27:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fPEL+PrN; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240673AbhDFOZg (ORCPT + 99 others); Tue, 6 Apr 2021 10:25:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:44818 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230032AbhDFOZg (ORCPT ); Tue, 6 Apr 2021 10:25:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DCB3C613B3; Tue, 6 Apr 2021 14:25:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617719128; bh=vNtEwGcZISehAqNRkZmr9T8agA6B1FBpji1ztURbj9c=; h=From:To:Cc:Subject:Date:From; b=fPEL+PrNq2Wo+kYIIz6T6zMJsLUuM0TNd1mTNhczorVRv/aBiuzw6a14Bx6XvaC78 xSSPcQD06GHTLq6PBybPWnzlNRSms/MtZPniIb9iwqfD6S15CK4PnODlxS51ZZ+tpd LP5uStXqLWHG6tbYBIfJcvRr256xlEzXYA6u+iU2ltOKjcFQs+Aa840yS0JJkVNQoW vc3gWUtcz374LgQ2Me/Iw/FYubwmbrv1foN0gRctguQa3G7WPRxUz8lfaRA83u9mHe EyDg+eTwK+Ijh+/K8jdVuKw60CGrBRb6C2qNuOi9SGBV1IucF6Ypmc5R4Y7KC7Vg9b XHTQwKulvnqww== From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH] crypto: arm64/aes-ce - deal with oversight in new CTR carry code Date: Tue, 6 Apr 2021 16:25:23 +0200 Message-Id: <20210406142523.1101817-1-ardb@kernel.org> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The new carry handling code in the CTR driver can deal with a carry occurring in the 4x/5x parallel code path, by using a computed goto to jump into the carry sequence at the right place as to only apply the carry to a subset of the blocks being processed. If the lower half of the counter wraps and ends up at exactly 0x0, a carry needs to be applied to the counter, but not to the counter values taken for the 4x/5x parallel sequence. In this case, the computed goto skips all register assignments, and branches straight to the jump instruction that gets us back to the fast path. This produces the correct result, but due to the fact that this branch target does not carry the correct BTI annotation, this fails when BTI is enabled. Let's omit the computed goto entirely in this case, and jump straight back to the fast path after applying the carry to the main counter. Fixes: 5318d3db465d ("crypto: arm64/aes-ctr - improve tail handling") Signed-off-by: Ard Biesheuvel --- arch/arm64/crypto/aes-modes.S | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/crypto/aes-modes.S b/arch/arm64/crypto/aes-modes.S index ab6c14ef9f4e..6d1a120c533d 100644 --- a/arch/arm64/crypto/aes-modes.S +++ b/arch/arm64/crypto/aes-modes.S @@ -359,6 +359,7 @@ ST5( mov v4.16b, vctr.16b ) ins vctr.d[0], x8 /* apply carry to N counter blocks for N := x12 */ + cbz x12, 2f adr x16, 1f sub x16, x16, x12, lsl #3 br x16 -- 2.31.0.208.g409f899ff0-goog