Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp2084649ybb; Fri, 29 Mar 2019 18:39:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqzkM9v+GfyC/LTV+ww0iqrchb7DscprYz5jptTEdT6lfXDG4ce9D2hT9wM1La8lKCxfOxEG X-Received: by 2002:aa7:8092:: with SMTP id v18mr34461076pff.35.1553909982560; Fri, 29 Mar 2019 18:39:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553909982; cv=none; d=google.com; s=arc-20160816; b=071xzwjx0DsNJQtm4FUZGIOyVZ9vg2ivwxyjCedRiXrGwahIN9uTNb408G+9LDqixb 6gKZLQmFrFQ6ceCiWMKIhOL5DLhb2+LnlFUgRSJbHOcL2HanZ8IsiWhmfbnJoCsnHl1u vKChGZef2RR+jR6cBy7D2ulZPoJ71Yit0o5ZQU8UmxadoKXPV6kSZcSAwQRDlRoEaUc/ ocuJ+k8/2hGUXEC8BXM6tJiO1v7EFOlFfAbRSMhRWe75MXf+4k6a1y1uo+IrKU51WiF6 gRPpA0fQ0i22qTCK/1jWJXWMKg9j1hXeXRp6CYBnK6gxcdBf+p8ahanYwFvE/CpDUBOZ 9kRw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bYYFUOEvPjrskPUlEspAsdLT83T4tg9X8PIax51Tt+I=; b=vAyHP0zKkHa5qW8jZXCz3UJ5LNCjUQnCR24dcPghz3IP/YFVohgEBW+GZv0NhHQunQ 9za5lPqmH01VjoVVhO2zomWQLXGo+iGNlLv+ICwPduEGsTYkxIipR4ziakdjZW0yAPLd Vk+fLVEF9BYuDUgtMGvwKViRNwFAs7e1nAfG4MQ4g3v/jfG4RTPxmpTBT2eOFxB+nAFN XfIQn0x3SosW5JLrfW+YToSiCnWTunOvMK2MTuqnCUdQjbkvRYUkEw+aRq48FYx/PBrx oFgkwvGaituP478mV2hU/P6KKmjA5vBoEL7WymYLw4dJKwXBepc9Kt0hx4EsNZu76FTE Uvwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Fh4XpgAM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m10si3168292pgk.386.2019.03.29.18.39.26; Fri, 29 Mar 2019 18:39:42 -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=Fh4XpgAM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731360AbfC3BaL (ORCPT + 99 others); Fri, 29 Mar 2019 21:30:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:37180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731327AbfC3BaI (ORCPT ); Fri, 29 Mar 2019 21:30:08 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EFA3621773; Sat, 30 Mar 2019 01:30:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553909407; bh=a8CQwWBNAjrS4TGdu/OOSPN3ezFGsYexYg1Gq0r3XSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fh4XpgAMVPq92/FCtRvUx6haYk78fsjwXzX4xnxMTCRxRD0t18wtcOESoFcCZuk0C ldWyK/XLQdXFYtncO9TpWpMVzG9vCnKNWB/1c1EIwKleFL1O4Y2uoFD88SNQQ6swXH hT0AChK5IKwjomWDanDi8txz2SpNwdIGovJ7sWKo= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ard Biesheuvel , Herbert Xu , Sasha Levin , linux-crypto@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 35/57] crypto: sha256/arm - fix crash bug in Thumb2 build Date: Fri, 29 Mar 2019 21:28:28 -0400 Message-Id: <20190330012854.32212-35-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190330012854.32212-1-sashal@kernel.org> References: <20190330012854.32212-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel [ Upstream commit 69216a545cf81b2b32d01948f7039315abaf75a0 ] The SHA256 code we adopted from the OpenSSL project uses a rather peculiar way to take the address of the round constant table: it takes the address of the sha256_block_data_order() routine, and substracts a constant known quantity to arrive at the base of the table, which is emitted by the same assembler code right before the routine's entry point. However, recent versions of binutils have helpfully changed the behavior of references emitted via an ADR instruction when running in Thumb2 mode: it now takes the Thumb execution mode bit into account, which is bit 0 af the address. This means the produced table address also has bit 0 set, and so we end up with an address value pointing 1 byte past the start of the table, which results in crashes such as Unable to handle kernel paging request at virtual address bf825000 pgd = 42f44b11 [bf825000] *pgd=80000040206003, *pmd=5f1bd003, *pte=00000000 Internal error: Oops: 207 [#1] PREEMPT SMP THUMB2 Modules linked in: sha256_arm(+) sha1_arm_ce sha1_arm ... CPU: 7 PID: 396 Comm: cryptomgr_test Not tainted 5.0.0-rc6+ #144 Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015 PC is at sha256_block_data_order+0xaaa/0xb30 [sha256_arm] LR is at __this_module+0x17fd/0xffffe800 [sha256_arm] pc : [] lr : [] psr: 800b0033 sp : ebc8bbe8 ip : faaabe1c fp : 2fdd3433 r10: 4c5f1692 r9 : e43037df r8 : b04b0a5a r7 : c369d722 r6 : 39c3693e r5 : 7a013189 r4 : 1580d26b r3 : 8762a9b0 r2 : eea9c2cd r1 : 3e9ab536 r0 : 1dea4ae7 Flags: Nzcv IRQs on FIQs on Mode SVC_32 ISA Thumb Segment user Control: 70c5383d Table: 6b8467c0 DAC: dbadc0de Process cryptomgr_test (pid: 396, stack limit = 0x69e1fe23) Stack: (0xebc8bbe8 to 0xebc8c000) ... unwind: Unknown symbol address bf820bca unwind: Index not found bf820bca Code: 441a ea80 40f9 440a (f85e) 3b04 ---[ end trace e560cce92700ef8a ]--- Given that this affects older kernels as well, in case they are built with a recent toolchain, apply a minimal backportable fix, which is to emit another non-code label at the start of the routine, and reference that instead. (This is similar to the current upstream state of this file in OpenSSL) Signed-off-by: Ard Biesheuvel Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- arch/arm/crypto/sha256-armv4.pl | 3 ++- arch/arm/crypto/sha256-core.S_shipped | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/arm/crypto/sha256-armv4.pl b/arch/arm/crypto/sha256-armv4.pl index b9ec44060ed3..a03cf4dfb781 100644 --- a/arch/arm/crypto/sha256-armv4.pl +++ b/arch/arm/crypto/sha256-armv4.pl @@ -212,10 +212,11 @@ K256: .global sha256_block_data_order .type sha256_block_data_order,%function sha256_block_data_order: +.Lsha256_block_data_order: #if __ARM_ARCH__<7 sub r3,pc,#8 @ sha256_block_data_order #else - adr r3,sha256_block_data_order + adr r3,.Lsha256_block_data_order #endif #if __ARM_MAX_ARCH__>=7 && !defined(__KERNEL__) ldr r12,.LOPENSSL_armcap diff --git a/arch/arm/crypto/sha256-core.S_shipped b/arch/arm/crypto/sha256-core.S_shipped index 3b58300d611c..054aae0edfce 100644 --- a/arch/arm/crypto/sha256-core.S_shipped +++ b/arch/arm/crypto/sha256-core.S_shipped @@ -93,10 +93,11 @@ K256: .global sha256_block_data_order .type sha256_block_data_order,%function sha256_block_data_order: +.Lsha256_block_data_order: #if __ARM_ARCH__<7 sub r3,pc,#8 @ sha256_block_data_order #else - adr r3,sha256_block_data_order + adr r3,.Lsha256_block_data_order #endif #if __ARM_MAX_ARCH__>=7 && !defined(__KERNEL__) ldr r12,.LOPENSSL_armcap -- 2.19.1