From patchwork Thu Sep 14 11:27:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 139514 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp279114vqi; Thu, 14 Sep 2023 04:32:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9jkaYxfAkeZzd5/VB3XN9itXOGwAo6aYjm6w6k8lA9Bu2iMdRRbRiEC7sE4ajYZRmtIq3 X-Received: by 2002:a17:902:e744:b0:1c3:e9b0:baf7 with SMTP id p4-20020a170902e74400b001c3e9b0baf7mr4798493plf.64.1694691152779; Thu, 14 Sep 2023 04:32:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694691152; cv=none; d=google.com; s=arc-20160816; b=zwMV/CRIuEqLgg/S12lab1jqkydNQDzkZ70YbXTXwhDvlMNJaBbGDtS+1hMWtqnw1/ NbBYrpE00KgM+uzMaMNUJvGAS53kJFcJE/0o+/SiAm24I5a2Fs1CexZXp76q41WoKhQk TaAVhQmDErBpOnAEjdiyJMzq4U4QSXGCyZKAtrLH7bzoNc+oY2QYgunGx39qE6yqTWOg SBspB+kaxv1ZpZCeGDvJ4Yt9OwUdELLdpV0U8N6MvYFKZ98aCe/A1bgNB5hix+tXiesj IFax1imo1V78CdSEA4pkxYlT3TBYqbZVa5L1AlHArHFC4LNCojMW3fb7eWOMKewMj5M0 9gfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=zmZehBGumWU33PaAzE7WjuGvYBCGLX0/2JNBi7w45LE=; fh=n7fF7QC0RNRn6F3FQu0v+CrFD4hMTQOXYoV2ln8SMUQ=; b=0fIvd++QuS/J9uBYHvLmGjBhgg2CcFSL3bKZTdBnbc+YUyViQswtuUlgp9fOpHRRi0 VrsDsaU3X8Ymfk3N+nO2aG/dvu+f0uJ32+pSOLTv5OFHCDtjAZJvjMS9TylmmWarUWx5 nBlRYJcNOLjIIvsHIOQcFwBbXA/Dae9bYluYJYjqBpCA+c5boh1PpNi75vReSE7cW/QE uOLSb8ZYCnVYAR84NcVMQQoYXZ3e9FbtiRHdC4J2gOJ4MmTqFg+ZCLPU+yx1pU3DZ9tV L5c4RUfKx056LuAiRSRAov155WOicAFrureUZJWhS5qaZrdb47beqpKxa+lTU+gRthIT QI4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZAzOahBQ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id lh3-20020a170903290300b001bdb8f2f5a8si1405631plb.327.2023.09.14.04.32.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 04:32:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZAzOahBQ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 8315781A73C0; Thu, 14 Sep 2023 04:27:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234742AbjINL1K (ORCPT + 35 others); Thu, 14 Sep 2023 07:27:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233218AbjINL1J (ORCPT ); Thu, 14 Sep 2023 07:27:09 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C43321A5; Thu, 14 Sep 2023 04:27:04 -0700 (PDT) Date: Thu, 14 Sep 2023 11:27:02 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694690822; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zmZehBGumWU33PaAzE7WjuGvYBCGLX0/2JNBi7w45LE=; b=ZAzOahBQ+toQEjwcNs6/beWjCTrGxXKA+JdjiQjUb6wUcSj4NuCSsK31d+6MUGua5knDKJ jjQoWYd5cTi8l7ALcJ171TLK7PPXl9LuMqxZAX+HhfQ4RleSQ2WNjAR5rPVgN5ffDOnLVj h0ip3WgJDikMtbQeMKqy2IReQ1WJ5UwlRo+kI8AhG/FIWnf61VnOrUk/na8mCRhhTZOJnR VqiCNkkhp8pgzriXPnjULp8ZDYGKfwZpX3tCg5lKUtKR8KEJZOo5JphZf5dHAS1quPb8Ps ZMfwgNew9IBAHmIqwH7hS3qhY9X6mv1R+ufPH1I+r5pLQ0em9Dl4fwMCYVfMUw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694690822; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zmZehBGumWU33PaAzE7WjuGvYBCGLX0/2JNBi7w45LE=; b=8SDh91sBC922LdVauVh5sYMK+Refw68zEwupPACMSePEcw6oqnrqAzSWbazminFdeXmauq Xd8WSyE7vThMYsDA== From: "tip-bot2 for Nikolay Borisov" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/entry] x86: Make IA32_EMULATION boot time configurable Cc: Nikolay Borisov , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230623111409.3047467-7-nik.borisov@suse.com> References: <20230623111409.3047467-7-nik.borisov@suse.com> MIME-Version: 1.0 Message-ID: <169469082201.27769.12035132996797296127.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails 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 (pete.vger.email [0.0.0.0]); Thu, 14 Sep 2023 04:27:24 -0700 (PDT) X-Spam-Status: No, score=-0.9 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 pete.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1769493812171543781 X-GMAIL-MSGID: 1777012469967266707 The following commit has been merged into the x86/entry branch of tip: Commit-ID: a11e097504ac1889b35b6858f495565838325f88 Gitweb: https://git.kernel.org/tip/a11e097504ac1889b35b6858f495565838325f88 Author: Nikolay Borisov AuthorDate: Fri, 23 Jun 2023 14:14:09 +03:00 Committer: Thomas Gleixner CommitterDate: Thu, 14 Sep 2023 13:19:53 +02:00 x86: Make IA32_EMULATION boot time configurable 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_IA32_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 'ia32_emulation' parameter which allows overriding CONFIG_IA32_EMULATION_DEFAULT_DISABLED state at boot time. Signed-off-by: Nikolay Borisov Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/20230623111409.3047467-7-nik.borisov@suse.com --- Documentation/admin-guide/kernel-parameters.txt | 6 ++++++ arch/x86/Kconfig | 9 +++++++++ arch/x86/entry/common.c | 9 ++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 0a1731a..45e34be 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1893,6 +1893,12 @@ 0 -- machine default 1 -- force brightness inversion + ia32_emulation= [X86-64] + Format: + When true, allows loading 32-bit programs and executing 32-bit + syscalls, essentially overriding IA32_EMULATION_DEFAULT_DISABLED at + boot time. When false, unconditionally disables IA32 emulation. + icn= [HW,ISDN] Format: [,[,[,]]] diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 982b777..c130bf3 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -2954,6 +2954,15 @@ config IA32_EMULATION 64-bit kernel. You should likely turn this on, unless you're 100% sure that you don't have any 32-bit programs left. +config IA32_EMULATION_DEFAULT_DISABLED + bool "IA32 emulation disabled by default" + default n + depends on IA32_EMULATION + help + Make IA32 emulation disabled by default. This prevents loading 32-bit + processes and access to 32-bit syscalls. If unsure, leave it to its + default value. + config X86_X32_ABI bool "x32 ABI for 64-bit mode" depends on X86_64 diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index cfbd3ae..a34e1a1 100644 --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -19,6 +19,7 @@ #include #include #include +#include #ifdef CONFIG_XEN_PV #include @@ -97,7 +98,13 @@ static __always_inline int syscall_32_enter(struct pt_regs *regs) } #ifdef CONFIG_IA32_EMULATION -bool __ia32_enabled __ro_after_init = true; +bool __ia32_enabled __ro_after_init = !IS_ENABLED(CONFIG_IA32_EMULATION_DEFAULT_DISABLED); + +static int ia32_emulation_override_cmdline(char *arg) +{ + return kstrtobool(arg, &__ia32_enabled); +} +early_param("ia32_emulation", ia32_emulation_override_cmdline); #endif /*