From patchwork Tue Sep 26 16:09:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13399352 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9A7A5E7E644 for ; Tue, 26 Sep 2023 16:09:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=fVLKmgmxv7U4vOdc8t1QqmLmhEtjwNa+/X2eZEnS5kw=; b=MKBrC7myx3liwc TdmdeShBDVnCw5abpJBVK8uO0AIVKgvSJxeOQDuMUOt2om9AP6T3SYpBTwJewkr4wTNIyAX9zUGh4 2G5/456wxDnklPPFNSJEzNlOF3hBhpnSJo5KxQXZX1di+nWReBYSSFQAHaalFvVoZ06MitmvGpQKa QIijotvTWlIJQXB5wKzotC+Z7o9F66pUrgdppjPTtWIV+f+l4eyRvdmlcmPa/HdvCAHqMDKxP12db 9FwrVUKXx8Ev3mbcd3E1pQFG1A+Vh8Yq2useQMXqLLnwNj5F7h0WWWCGwLnnHWw1ksCsEpQzqoYy7 1QUcIsyqrGC5IAtkgaEA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qlAcf-00GgyH-1G; Tue, 26 Sep 2023 16:09:17 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qlAcd-00Ggx0-0R for linux-arm-kernel@lists.infradead.org; Tue, 26 Sep 2023 16:09:16 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id CCC01B810BC; Tue, 26 Sep 2023 16:09:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04F55C433C7; Tue, 26 Sep 2023 16:09:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695744553; bh=KIbC1Ui2Ufy2ZZPQgUs1RBN/CWpdIljaKe9AGeuEHZU=; h=From:To:Cc:Subject:Date:From; b=nGT4zamObMbcyTm3cidGJPErWADcslA/S4HeodBErtmexNAHIo1FGdXIQbP1ZafTo dkUvTtPBLsSVezV3W4gOd73sZ9woyU0lEjWIZh0ZaLtSymgRZeQfa1mRx653HJgFKq eaDRjYsSRzOepbxCElSDxojz99v30Rz/xPk6rQhsEFeyqFNwF20T2VEZhOqF7H+eo+ RC4oNgF4oB94j3Ade3j9wHiRz2Z/XDOnE6tA4FY2WUshPSEgwUWJofrE+FFuOFp86P Xm9UPJxXmiPdScr6z9pi9FML9rp0XgDJhSNGCx9Oc8H0zNLjX+d19P3D53EZFYK9Tj 5lW5WrmgKUoiQ== From: Masahiro Yamada To: patches@armlinux.org.uk Cc: linux-kernel@vger.kernel.org, Russell King , Masahiro Yamada , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Subject: [PATCH] ARM: fix get_user() broken with veneer Date: Wed, 27 Sep 2023 01:09:03 +0900 Message-Id: <20230926160903.62924-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230926_090915_307804_AA23E64D X-CRM114-Status: GOOD ( 10.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The 32-bit ARM kernel stops working if the kernel grows to the point where veneers for __get_user_* are created. AAPCS32 [1] states, "Register r12 (IP) may be used by a linker as a scratch register between a routine and any subroutine it calls. It can also be used within a routine to hold intermediate values between subroutine calls." However, bl instructions buried within the inline asm are unpredictable for compilers; hence, "ip" must be added to the clobber list. This becomes critical when veneers for __get_user_* are created because veneers use the ip register since commit 02e541db0540 ("ARM: 8323/1: force linker to use PIC veneers"). [1]: https://github.com/ARM-software/abi-aa/blob/2023Q1/aapcs32/aapcs32.rst Signed-off-by: Masahiro Yamada Reviewed-by: Ard Biesheuvel --- KernelVersion: v6.6-rc1 arch/arm/include/asm/uaccess.h | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h index bb5c81823117..c28f5ec21e41 100644 --- a/arch/arm/include/asm/uaccess.h +++ b/arch/arm/include/asm/uaccess.h @@ -109,16 +109,6 @@ extern int __get_user_64t_1(void *); extern int __get_user_64t_2(void *); extern int __get_user_64t_4(void *); -#define __GUP_CLOBBER_1 "lr", "cc" -#ifdef CONFIG_CPU_USE_DOMAINS -#define __GUP_CLOBBER_2 "ip", "lr", "cc" -#else -#define __GUP_CLOBBER_2 "lr", "cc" -#endif -#define __GUP_CLOBBER_4 "lr", "cc" -#define __GUP_CLOBBER_32t_8 "lr", "cc" -#define __GUP_CLOBBER_8 "lr", "cc" - #define __get_user_x(__r2, __p, __e, __l, __s) \ __asm__ __volatile__ ( \ __asmeq("%0", "r0") __asmeq("%1", "r2") \ @@ -126,7 +116,7 @@ extern int __get_user_64t_4(void *); "bl __get_user_" #__s \ : "=&r" (__e), "=r" (__r2) \ : "0" (__p), "r" (__l) \ - : __GUP_CLOBBER_##__s) + : "ip", "lr", "cc") /* narrowing a double-word get into a single 32bit word register: */ #ifdef __ARMEB__ @@ -148,7 +138,7 @@ extern int __get_user_64t_4(void *); "bl __get_user_64t_" #__s \ : "=&r" (__e), "=r" (__r2) \ : "0" (__p), "r" (__l) \ - : __GUP_CLOBBER_##__s) + : "ip", "lr", "cc") #else #define __get_user_x_64t __get_user_x #endif