From patchwork Wed Oct 18 11:13:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea della Porta X-Patchwork-Id: 13426882 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 CF976CDB47E for ; Wed, 18 Oct 2023 11:13:56 +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:References:In-Reply-To: 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: List-Owner; bh=kczD3deOnsRxpR3wIR1XwweFpsc5m42ZMgvA1GFesyE=; b=yomqYN9XrlXyAq cy7YarTIJCMakC1ds3WODwwk92UnMKgFsEz8S4IU7Rb0BCVu1/Sbz6PHO1PbE4ILpaPP8oNoqXkrI PCo8nirY8Fe0lVf8p5XM9hjhB1vevB4FAkve3X8666qzBet+VEkr5iivHdVArGYuM+h1ut+vz4rs/ Ul9fcywdSLVOBThnlxmxr7bgU127Q80vXLWl2+ad5Pu/jU7okzpjE6C/BDIu/e4AZ5DCobD8JT83T LALQ4UuRftDJZYGmIQuQ1A65PUz3myg65jQmwUdY0d7EJOWXOgt/20+XG360zrcEa3c5ANu/vWA1i 4CG7Xia/+722SJ/nXDSA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qt4UZ-00EWVf-2g; Wed, 18 Oct 2023 11:13:35 +0000 Received: from smtp-out1.suse.de ([2001:67c:2178:6::1c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qt4UX-00EWU9-0d for linux-arm-kernel@lists.infradead.org; Wed, 18 Oct 2023 11:13:34 +0000 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 876EC21B46; Wed, 18 Oct 2023 11:13:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1697627609; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wsR/3Y9czckKmpyD5dpakWYoef+ZcRQqjgka+TQ4G38=; b=kzK0A7Ah4wF9K5Iz3ITZDsOAS/SGjho+aaOpko47hOx+NTaRPXP0ZMtcHIMS2FReb2c2bs muBtEJKJTv8yMqE5ObWfV8BopGL73hobgywMYfmBZDwLdrINoEQRsDWhPxtwH3cYVxuGRP jBjEi4n36kW8I4tscrhT0TtVk/ZZBDA= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 694DE13915; Wed, 18 Oct 2023 11:13:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EpgfF9m9L2VRZwAAMHmgww (envelope-from ); Wed, 18 Oct 2023 11:13:29 +0000 From: Andrea della Porta To: Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: nik.borisov@suse.com, Andrea della Porta Subject: [PATCH 4/4] arm64: Make Aarch32 emulation boot time configurable Date: Wed, 18 Oct 2023 13:13:22 +0200 Message-ID: <1029761eb218702d4aafa58d83c4bf9d3a760264.1697614386.git.andrea.porta@suse.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [-5.70 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_HAM(-3.00)[100.00%]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[6]; NEURAL_HAM_LONG(-3.00)[-1.000]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; FORGED_SENDER(0.30)[andrea.porta@suse.com,aporta@suse.de]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_NEQ_ENVFROM(0.10)[andrea.porta@suse.com,aporta@suse.de]; RCVD_TLS_ALL(0.00)[] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231018_041333_410606_7A9406AF X-CRM114-Status: GOOD ( 13.48 ) 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 Distributions would like to reduce their attack surface as much as possible but at the same time they'd want to retain flexibility to cater to a variety of legacy software. This stems from the conjecture that compat layer is likely rarely tested and could have latent security bugs. Ideally distributions will set their default policy and also give users the ability to override it as appropriate. To enable this use case, introduce CONFIG_AARCH32_EMULATION_DEFAULT_DISABLED compile time option, which controls whether 32bit processes/syscalls should be allowed or not. This option is aimed mainly at distributions to set their preferred default behavior in their kernels. To allow users to override the distro's policy, introduce the 'aarch32_emulation' parameter which allows overriding CONFIG_AARCH32_EMULATION_DEFAULT_DISABLED state at boot time. Signed-off-by: Andrea della Porta --- Documentation/admin-guide/kernel-parameters.txt | 7 +++++++ arch/arm64/Kconfig | 9 +++++++++ arch/arm64/kernel/entry-common.c | 8 +++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 0a1731a0f0ef..a41c5e6f5d2e 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1,3 +1,10 @@ + aarch32_emulation= [ARM64] + Format: + When true, allows loading 32-bit programs and executing + 32-bit syscalls, essentially overriding + AARCH32_EMULATION_DEFAULT_DISABLED at boot time. when false, + unconditionally disables AARCH32 emulation. + acpi= [HW,ACPI,X86,ARM64,RISCV64] Advanced Configuration and Power Interface Format: { force | on | off | strict | noirq | rsdt | diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index b10515c0200b..66c4cb273550 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1725,6 +1725,15 @@ config SETEND_EMULATION If unsure, say Y endif # ARMV8_DEPRECATED +config AARCH32_EMULATION_DEFAULT_DISABLED + bool "Aarch32 emulation disabled by default" + default n + depends on COMPAT + help + Make Aarch32 emulation disabled by default. This prevents loading 32-bit + processes and access to 32-bit syscalls. + + If unsure, leave it to its default value. endif # COMPAT menu "ARMv8.1 architectural features" diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c index 32761760d9dd..07f2b4e632b8 100644 --- a/arch/arm64/kernel/entry-common.c +++ b/arch/arm64/kernel/entry-common.c @@ -897,7 +897,13 @@ asmlinkage void noinstr el0t_32_error_handler(struct pt_regs *regs) __el0_error_handler_common(regs); } -bool __aarch32_enabled __ro_after_init = true; +bool __aarch32_enabled __ro_after_init = !IS_ENABLED(CONFIG_AARCH32_EMULATION_DEFAULT_DISABLED); + +static int aarch32_emulation_override_cmdline(char *arg) +{ + return kstrtobool(arg, &__aarch32_enabled); +} +early_param("aarch32_emulation", aarch32_emulation_override_cmdline); #else /* CONFIG_COMPAT */ UNHANDLED(el0t, 32, sync) UNHANDLED(el0t, 32, irq)