From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C929E2DC334 for ; Sat, 27 Jun 2026 20:56:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782593766; cv=none; b=c2iiyU4vSzV8IqIEG1o3kQ7uul7hOTkkxe5H7UdiS3R7EDxbHvq8gxPMSC6tvysBfXcQBNS/NN4eviK4r6qQPD0qLylvYBU0R/JzQPJfYropQ2dd0g23+MjKXugaomwgedkVq646TZsMPhq/8l6zEfRue1ZZtZ/aMRV2E1BumDo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782593766; c=relaxed/simple; bh=9i425v2OLf77/7490P0ZuAEgbCG/7SCUKbPj/W+6wOg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=JIXvIflVOLwdE1OVRW1uqrrh0jiyVoMkCUQ9KvMvgsJRIwOiV5HKm37YVeH0VvoYQBDhymDNKlq6ONDCxgeFa5VcUBoe4FXhVEJ/sqdHo+xsaal5AZdhJ2VK1MhaoF8uHKAsLarWcj8FkWTPWJJBPwP9GYHEolnHqnKRNcbfieE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=R+DB8i/y; arc=none smtp.client-ip=209.85.222.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="R+DB8i/y" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-92e45cfcc8aso16261985a.0 for ; Sat, 27 Jun 2026 13:56:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1782593763; x=1783198563; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nhsbipjzA5I+UfoW44RlcJRMPkJBr0UMfZzbOwMhg+U=; b=R+DB8i/yJbRBPA+kv7KrYOzmQTIRcRRO2CdA9hTJ1UHqahvnO4fvurJk7lSRWjYznp 8EXa6+HkPJ28YmN9JCrREVRXsYc/0zX766OpWw1x4vAhkJk6fZdM7DctT7Mj6nGvmLzJ r0hG6lAuEyu99JV8q4BdxLq29zx8FV4yOg3EIzB/EDfp6cwXz5oP3ObvA1oaPtIGd/5k LPxdGk0zL0d6UufxEjC4IliWkMO8LjhqtYq9YHoHu0VBvC6sJHsN4x6WdvjTKbKeeDV1 3BTYIuN9nTy+dKi769q8tN5P3de2g5hcwz2rvjGEheiMPWg3olVIzsc9cO/wrval/yjH VOjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782593763; x=1783198563; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=nhsbipjzA5I+UfoW44RlcJRMPkJBr0UMfZzbOwMhg+U=; b=kzLHtXLbpglO+19S+FGAQ9y1HF9rb+EvqxiQDiGQLsWUC0k3hk1dEGQ7FHWIfW+l5u 9OwNtOPtMza35C2q0J3cafyQb7pF3UqMfdHOGulOgebnVmf1vz/w2qTp79cnDAjMxiKn vJmxCWLR/fKgWUSFwwglRHUi8V3qKZyhWzoQ9nuQMovsU2N1E9N6AKwAMTrTZwiUHTon dWHW0Q2YS+PtjyvMTQASo0t550VJrg40mGgF/zzzXqvl8qgwQGJLTRCMhI02p3nMQugK xqll9JfKn0nfcL79uGhMo9l8ML4t7CzBT6UHKkyiqc+5u81EaqpV//pwdQ6by80MlVuo JusQ== X-Gm-Message-State: AOJu0Yz1xHCYH+iQe5UCydZYLJJ3xsK1UKerzw0YVLffja5m8I02Q0gw 26zt2sXvddXdDrzbK6E3E6XsGnNmI/1/oRB2jRuu9/gITVckm0VMQMjEeZGFm8b+Nf6G0RMtZjy ew0xv X-Gm-Gg: AfdE7cmt8bIMOsIUKbVRoApJphc/4rffz70GxME655HvijJnFYKMsRLQIt8r972oBAR wMZP4Jwf3xpsy2a4B91yNiTcF42kXnyr2AjJSwIQRmDaXXeVuN2TSJs+x/wnZ8+2/AuUJu3wq0n uQj8zfOl4BYyboKap4a3XhDpybPk1A9/8LyQUeXr1ILGUiuXioAyQgKFapZ4xIajj5hDV4X/4bL 5MQVytPMpSwTELTm/pAI9pWpSIJvmyHXAxmYbNF5OwLzvb2yqYIObSvdOkbqam7ccIwtxrW712d VkYO2l9njur0O3FDgXcM8wJomBKr2Iyo/weZ1pdBhlOd5LK9Hkbzas3M/xDcLyVeW0xvV5KA4GE pAxa+sdMGaZ3kcPVZmICuOenvGIczGEaT11vv0vBKIi0ic9G5wtTmOKo4kghn6b6NPP0TeF/19K BFNOH6bdz9MIgdrr33WHjL41bfP/iVgL4eAZaiZQbUdEgaMS8uIWK+862wEkBydQt2sWNfVaqJc A== X-Received: by 2002:a05:6214:4983:b0:8de:1754:f793 with SMTP id 6a1803df08f44-8e6df1da882mr171865996d6.20.1782593762480; Sat, 27 Jun 2026 13:56:02 -0700 (PDT) Received: from gourry-fedora-PF4VCD3F.lan (pool-173-79-60-52.washdc.fios.verizon.net. [173.79.60.52]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8df81cdec56sm265460836d6.32.2026.06.27.13.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jun 2026 13:56:01 -0700 (PDT) From: Gregory Price To: linux-kernel@vger.kernel.org Cc: linux-doc@vger.kernel.org, kernel-team@meta.com, corbet@lwn.net, skhan@linuxfoundation.org, tglx@kernel.org, peterz@infradead.org, luto@kernel.org, akpm@linux-foundation.org, feng.tang@linux.alibaba.com, pmladek@suse.com, mhiramat@kernel.org, marc.herbert@linux.intel.com, joel.granados@kernel.org, gourry@gourry.net, lirongqing@baidu.com, kees@kernel.org, nathan@kernel.org, linusw@kernel.org, arnd@arndb.de, deller@gmx.de, jpoimboe@kernel.org, ruanjinjie@huawei.com, lukas.bulwahn@redhat.com, ryan.roberts@arm.com, ojeda@kernel.org Subject: [PATCH 1/2] kernel/entry: add CONFIG_SYSCALL_USER_DISPATCH to compile SUD out Date: Sat, 27 Jun 2026 16:55:50 -0400 Message-ID: <20260627205551.769684-1-gourry@gourry.net> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Syscall User Dispatch is built under CONFIG_GENERIC_SYSCALL and cannot be disabled independent of the core syscall-entry machinery. Native foreign-binary emulators (Wine/Proton) need it, but it should be an optional for minimal/high security systems. Add CONFIG_SYSCALL_USER_DISPATCH to make it optional. Signed-off-by: Gregory Price --- arch/Kconfig | 11 ++++++++ include/linux/entry-common.h | 6 ++--- include/linux/syscall_user_dispatch.h | 28 +++++++++++++++++++-- include/linux/syscall_user_dispatch_types.h | 2 +- kernel/entry/Makefile | 3 ++- 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index e86880045158..a40686e2ad5b 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -114,6 +114,17 @@ config GENERIC_ENTRY select GENERIC_IRQ_ENTRY select GENERIC_SYSCALL +config SYSCALL_USER_DISPATCH + bool "Syscall User Dispatch (SUD)" + depends on GENERIC_ENTRY + default y + help + Syscall User Dispatch (SUD) lets a thread have its own system calls + redirected to a userspace handler. It is used by emulators that run + foreign binaries which issue system calls directly. + + If unsure, say Y. + config KPROBES bool "Kprobes" depends on HAVE_KPROBES diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h index 416a3352261f..9336516430a1 100644 --- a/include/linux/entry-common.h +++ b/include/linux/entry-common.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -55,7 +56,6 @@ static __always_inline int arch_ptrace_report_syscall_entry(struct pt_regs *regs } #endif -bool syscall_user_dispatch(struct pt_regs *regs); long trace_syscall_enter(struct pt_regs *regs, long syscall); void trace_syscall_exit(struct pt_regs *regs, long ret); @@ -232,10 +232,8 @@ static __always_inline void syscall_exit_work(struct pt_regs *regs, unsigned lon * of these syscalls is unknown. */ if (work & SYSCALL_WORK_SYSCALL_USER_DISPATCH) { - if (unlikely(current->syscall_dispatch.on_dispatch)) { - current->syscall_dispatch.on_dispatch = false; + if (syscall_user_dispatch_clear_on_dispatch()) return; - } } audit_syscall_exit(regs); diff --git a/include/linux/syscall_user_dispatch.h b/include/linux/syscall_user_dispatch.h index 3858a6ffdd5c..3dcb4c2dc544 100644 --- a/include/linux/syscall_user_dispatch.h +++ b/include/linux/syscall_user_dispatch.h @@ -7,8 +7,22 @@ #include #include +#include -#ifdef CONFIG_GENERIC_ENTRY +struct pt_regs; + +#ifdef CONFIG_SYSCALL_USER_DISPATCH + +bool syscall_user_dispatch(struct pt_regs *regs); + +static inline bool syscall_user_dispatch_clear_on_dispatch(void) +{ + if (likely(!current->syscall_dispatch.on_dispatch)) + return false; + + current->syscall_dispatch.on_dispatch = false; + return true; +} int set_syscall_user_dispatch(unsigned long mode, unsigned long offset, unsigned long len, char __user *selector); @@ -24,6 +38,16 @@ int syscall_user_dispatch_set_config(struct task_struct *task, unsigned long siz #else +static inline bool syscall_user_dispatch(struct pt_regs *regs) +{ + return false; +} + +static inline bool syscall_user_dispatch_clear_on_dispatch(void) +{ + return false; +} + static inline int set_syscall_user_dispatch(unsigned long mode, unsigned long offset, unsigned long len, char __user *selector) { @@ -46,6 +70,6 @@ static inline int syscall_user_dispatch_set_config(struct task_struct *task, return -EINVAL; } -#endif /* CONFIG_GENERIC_ENTRY */ +#endif /* CONFIG_SYSCALL_USER_DISPATCH */ #endif /* _SYSCALL_USER_DISPATCH_H */ diff --git a/include/linux/syscall_user_dispatch_types.h b/include/linux/syscall_user_dispatch_types.h index 3be36b06c7d7..c0bdd4f760d3 100644 --- a/include/linux/syscall_user_dispatch_types.h +++ b/include/linux/syscall_user_dispatch_types.h @@ -4,7 +4,7 @@ #include -#ifdef CONFIG_GENERIC_ENTRY +#ifdef CONFIG_SYSCALL_USER_DISPATCH struct syscall_user_dispatch { char __user *selector; diff --git a/kernel/entry/Makefile b/kernel/entry/Makefile index 2333d70802e4..f220bae86b12 100644 --- a/kernel/entry/Makefile +++ b/kernel/entry/Makefile @@ -13,5 +13,6 @@ CFLAGS_REMOVE_common.o = -fstack-protector -fstack-protector-strong CFLAGS_common.o += -fno-stack-protector obj-$(CONFIG_GENERIC_IRQ_ENTRY) += common.o -obj-$(CONFIG_GENERIC_SYSCALL) += syscall-common.o syscall_user_dispatch.o +obj-$(CONFIG_GENERIC_SYSCALL) += syscall-common.o +obj-$(CONFIG_SYSCALL_USER_DISPATCH) += syscall_user_dispatch.o obj-$(CONFIG_VIRT_XFER_TO_GUEST_WORK) += virt.o -- 2.54.0