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: 154821 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4713051vqb; Wed, 18 Oct 2023 04:14:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFPyCNbvtl3DuEb0UK/1gY4AmfxHWULOFcEGc4KX9bg4bUFBpanE9nQoXYkOHkwSc93fVLN X-Received: by 2002:a17:902:f154:b0:1bf:349f:b85c with SMTP id d20-20020a170902f15400b001bf349fb85cmr4923422plb.1.1697627646535; Wed, 18 Oct 2023 04:14:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697627646; cv=none; d=google.com; s=arc-20160816; b=gI2oz9Jfhyq+W/30B5+jwzut1wDr3CLzInSxwN6olfvTztpnXZjLQhVh3kQ1/S1Rso 6FvqTQBADzEY2HyxPt+acbBq7yBp6sa/eUkaqy1gupbyNJNV4rodkhuzjoK/dlPVCYXG y7GOwzj5F8829DHUkB/8389KQxHNZP+CXOYBYuCoH+iQr1+EsPeq0gzkme7Ujxc0q3nE 3F6ZHzHbLG7odcXtHDTtidcFcbOP6uM3P9bZwtCC/eHY9rR7XQaUAb88DY++S9QsVz8+ oD1tzJPRHahrvL1siEUS0I8U0/2glxxnUK8B/B6CH7ImlM1+zlQParPpxFYSCINUb94p JuQg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wsR/3Y9czckKmpyD5dpakWYoef+ZcRQqjgka+TQ4G38=; fh=Fmfa0t6QgnUIyzgsSgnN1cYWfnFwLN+1Ba+VDm5h09M=; b=UHY4cVXY9kkQRq8DKBOwtwXYtBSC3ZyzPinJTu7VF97liv2E4doJw5CS6u3lQFRuHZ d21UES21HWPEirW7x5tiQG0jnlhw5sMs4XTzsfgy6cAWKafbHxjlJy/U6L9vF9piJe8z cFnpxmkyEqZ9ge9o6hcXzQYiv+xCmvl+pQsbFKnaqQmCWcoWi+KhWb6UVUcvdWxbRQnl NZ7oRlvtIWTgpKN0P7xTHyFsPi/p52E8IwhuBu0PrpawpyHz8eD5yNk4BirNbTdzlDBl OCFf+aW8TMdCuQjlo6FJeH/YDfvWk/OqttgqpkH3qkQ3SzXLj5/CUl7CJkkalM6SCISc nI+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=kzK0A7Ah; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id z4-20020a170902708400b001bb3bcd05bbsi3655393plk.471.2023.10.18.04.14.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 04:14:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=kzK0A7Ah; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 2EC598025895; Wed, 18 Oct 2023 04:14:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229690AbjJRLNn (ORCPT + 24 others); Wed, 18 Oct 2023 07:13:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230115AbjJRLNc (ORCPT ); Wed, 18 Oct 2023 07:13:32 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6BDBFE for ; Wed, 18 Oct 2023 04:13:30 -0700 (PDT) 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-Spam-Level: X-Spam-Score: -5.70 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-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 18 Oct 2023 04:14:03 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780091607388791985 X-GMAIL-MSGID: 1780091607388791985 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)