From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02AADDDAB for ; Mon, 8 Dec 2025 15:02:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765206132; cv=none; b=MNNKhYzu+ZF3KGFXSpi60vqFOoWzkafEO9CJbIF2q6Ui0i4a2hYb2v22Dfm/mdAExCfLKJ/Vc9E40J3aETtLKNMyWLN4YKHY5VO/w8meQmgqPEJK8x1RK53kzZ5DvOUC4/W2z3FsILCR1jnaIN/9ZKhbfNo0AidZ0yJu7Kj3Mhw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765206132; c=relaxed/simple; bh=SQIR0qtu9AkGtRJa347wvaIy4xrnM0QqKcJuCZdvuUo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=H3nmmdBeZ/s1EfocfgdlDFahnh/yTEf4lXYQV5em8rG7nc9LDOdH41qQKhd/H8xiuPUnaG4iezTDoJ//paFYlH9imrpC9Poa6vTLzGeEgLs5BpUu3thGNMnXKIgU9SPErKC2rpZBTYAgsHNLpgNfrnt3kG2I8ZK00rKIDGQIwm8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=KK8dqPoI; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="KK8dqPoI" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=qkKusbEH2/jL/U+qaWfXBFEVd+yePRFPMOa6UBCJuJ0=; b=KK8dqPoIpA+7rw5qO9ajq6id/u ShmKZvvXlXNzdZRJl13FQf7GGKG0zg9VUe1P0s16xW+4ZCicw6gMtVp2YuoDf6yBZibGKRXZWikQL +EbbMnzYAy8z0HkSaa4cHy7ckO48bMNE1jLa2xJnh7v3jAo1zHBCoOPIb4WkalUSHVsfblK/kp9yZ ufI7LIh5zhQ3Cnjqs2Pw23mdRuTJJugnFt3WIq1dFM3veL9UzaLt0aNeimFeBCndqdhlDaZovur1y KO/y5Jq39jzNlY39LvcF8QYtocrBctsGS9GgiEYfd8ZtO5TXdvI1PMRctOVpMMTUCut+fpA0Fc38h VN2RxtCw==; Received: from 2001-1c00-8d85-5700-266e-96ff-fe07-7dcc.cable.dynamic.v6.ziggo.nl ([2001:1c00:8d85:5700:266e:96ff:fe07:7dcc] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vSckN-00000009vN3-1WFn; Mon, 08 Dec 2025 15:01:55 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 2F70330301A; Mon, 08 Dec 2025 16:01:54 +0100 (CET) Date: Mon, 8 Dec 2025 16:01:54 +0100 From: Peter Zijlstra To: ellyndra Cc: linux-kernel@vger.kernel.org, luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com Subject: Re: [PATCH RESEND] kprobes: Blacklist risky functions from being probed Message-ID: <20251208150154.GA3708021@noisy.programming.kicks-ass.net> References: <20251204144142.61936-1-ellyesparza8@gmail.com> <20251204145013.GN2528459@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251204145013.GN2528459@noisy.programming.kicks-ass.net> On Thu, Dec 04, 2025 at 03:50:13PM +0100, Peter Zijlstra wrote: > On Thu, Dec 04, 2025 at 11:41:41AM -0300, ellyndra wrote: > > From: Elly I Esparza > > > > Blacklist 'x64_sys_call()' from being kprobed to prevent syscall hooking > > techniques that overwrite the content of a 'case' block inside the main > > syscall dispatch switch statement. > > > > Also blacklist 'kallsyms_lookup_name()' to prevent a potential bypass > > of the blacklist, since this function can be used to discover and target > > arbitrary kernel symbols. > > > > Add a Kconfig option under security/ to enable or disable this feature. > > > > Signed-off-by: Elly I Esparza > > --- > > I'd be okay doing this unconditionally. Pretty much everything else > until that point lives in noinstr which is already excluded from probes. How about something like this (completely untested) instead? --- arch/x86/entry/syscall_32.c | 6 ++++-- arch/x86/entry/syscall_64.c | 10 ++++++---- arch/x86/include/asm/syscall.h | 8 -------- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/arch/x86/entry/syscall_32.c b/arch/x86/entry/syscall_32.c index a67a644d0cfe..6451550df027 100644 --- a/arch/x86/entry/syscall_32.c +++ b/arch/x86/entry/syscall_32.c @@ -41,7 +41,7 @@ const sys_call_ptr_t sys_call_table[] = { #endif #define __SYSCALL(nr, sym) case nr: return __ia32_##sym(regs); -long ia32_sys_call(const struct pt_regs *regs, unsigned int nr) +static __always_inline long ia32_sys_call(const struct pt_regs *regs, unsigned int nr) { switch (nr) { #include @@ -70,7 +70,7 @@ early_param("ia32_emulation", ia32_emulation_override_cmdline); /* * Invoke a 32-bit syscall. Called with IRQs on in CT_STATE_KERNEL. */ -static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs, int nr) +static noinstr void do_syscall_32_irqs_on(struct pt_regs *regs, int nr) { /* * Convert negative numbers to very high and thus out of range @@ -78,12 +78,14 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs, int nr) */ unsigned int unr = nr; + instrumentation_begin(); if (likely(unr < IA32_NR_syscalls)) { unr = array_index_nospec(unr, IA32_NR_syscalls); regs->ax = ia32_sys_call(regs, unr); } else if (nr != -1) { regs->ax = __ia32_sys_ni_syscall(regs); } + instrumentation_end(); } #ifdef CONFIG_IA32_EMULATION diff --git a/arch/x86/entry/syscall_64.c b/arch/x86/entry/syscall_64.c index b6e68ea98b83..ce9ded561354 100644 --- a/arch/x86/entry/syscall_64.c +++ b/arch/x86/entry/syscall_64.c @@ -32,7 +32,7 @@ const sys_call_ptr_t sys_call_table[] = { #undef __SYSCALL #define __SYSCALL(nr, sym) case nr: return __x64_##sym(regs); -long x64_sys_call(const struct pt_regs *regs, unsigned int nr) +static __always_inline long x64_sys_call(const struct pt_regs *regs, unsigned int nr) { switch (nr) { #include @@ -40,15 +40,17 @@ long x64_sys_call(const struct pt_regs *regs, unsigned int nr) } } -#ifdef CONFIG_X86_X32_ABI -long x32_sys_call(const struct pt_regs *regs, unsigned int nr) +static __always_inline long x32_sys_call(const struct pt_regs *regs, unsigned int nr) { +#ifdef CONFIG_X86_X32_ABI switch (nr) { #include default: return __x64_sys_ni_syscall(regs); } -} +#else + return __x64_sys_ni_syscall(regs); #endif +} static __always_inline bool do_syscall_x64(struct pt_regs *regs, int nr) { diff --git a/arch/x86/include/asm/syscall.h b/arch/x86/include/asm/syscall.h index c10dbb74cd00..59a406074dc0 100644 --- a/arch/x86/include/asm/syscall.h +++ b/arch/x86/include/asm/syscall.h @@ -20,14 +20,6 @@ typedef long (*sys_call_ptr_t)(const struct pt_regs *); extern const sys_call_ptr_t sys_call_table[]; -/* - * These may not exist, but still put the prototypes in so we - * can use IS_ENABLED(). - */ -extern long ia32_sys_call(const struct pt_regs *, unsigned int nr); -extern long x32_sys_call(const struct pt_regs *, unsigned int nr); -extern long x64_sys_call(const struct pt_regs *, unsigned int nr); - /* * Only the low 32 bits of orig_ax are meaningful, so we return int. * This importantly ignores the high bits on 64-bit, so comparisons