[PATCH] x86/traps: Enable UBSAN traps on x86

2024-05-28 Thread Gatlin Newhouse
sanitizer caused the trap, via the encoded data in the trap instruction. Clang on x86 currently encodes the same data in ud1 instructions but the x86 handle_bug() and is_valid_bugaddr() functions currently only look at ud2s. Signed-off-by: Gatlin Newhouse --- MAINTAINERS | 2 ++

Re: [PATCH] x86/traps: Enable UBSAN traps on x86

2024-05-29 Thread Gatlin Newhouse
On Wed, May 29, 2024 at 09:25:21AM UTC, Marco Elver wrote: > On Wed, 29 May 2024 at 04:20, Gatlin Newhouse > wrote: > [...] > > if (regs->flags & X86_EFLAGS_IF) > > raw_local_irq_enable(); > > - if (report_bug(reg

Re: [PATCH] x86/traps: Enable UBSAN traps on x86

2024-05-29 Thread Gatlin Newhouse
On Wed, May 29, 2024 at 08:30:20PM UTC, Marco Elver wrote: > On Wed, 29 May 2024 at 20:17, Gatlin Newhouse > wrote: > > > > On Wed, May 29, 2024 at 09:25:21AM UTC, Marco Elver wrote: > > > On Wed, 29 May 2024 at 04:20, Gatlin Newhouse > > > wrote: > &g

Re: [PATCH] x86/traps: Enable UBSAN traps on x86

2024-05-31 Thread Gatlin Newhouse
On Thu, May 30, 2024 at 01:24:56AM UTC, Andrew Cooper wrote: > On 29/05/2024 3:20 am, Gatlin Newhouse wrote: > > diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h > > index a3ec87d198ac..e3fbed9073f8 100644 > > --- a/arch/x86/include/asm/bug.h > >

[PATCH v2] x86/traps: Enable UBSAN traps on x86

2024-05-31 Thread Gatlin Newhouse
sanitizer caused the trap, via the encoded data in the trap instruction. Clang on x86 currently encodes the same data in ud1 instructions but the x86 handle_bug() and is_valid_bugaddr() functions currently only look at ud2s. Signed-off-by: Gatlin Newhouse --- Changes in v2: - Name the new

Re: [PATCH v2] x86/traps: Enable UBSAN traps on x86

2024-06-11 Thread Gatlin Newhouse
On Mon, Jun 03, 2024 at 06:13:53PM UTC, Thomas Gleixner wrote: > On Sat, Jun 01 2024 at 03:10, Gatlin Newhouse wrote: > > > Bring x86 to parity with arm64, similar to commit 25b84002afb9 > > ("arm64: Support Clang UBSAN trap codes for better reporting"). > &g

[PATCH v3] x86/traps: Enable UBSAN traps on x86

2024-06-24 Thread Gatlin Newhouse
with arm64, similar to commit 25b84002afb9 ("arm64: Support Clang UBSAN trap codes for better reporting"). Enable the output of UBSAN type information on x86 architectures compiled with clang when CONFIG_UBSAN_TRAP=y. Signed-off-by: Gatlin Newhouse --- Changes in v3: - Address Thomas

[PATCH v4] x86/traps: Enable UBSAN traps on x86

2024-07-10 Thread Gatlin Newhouse
arm64, similar to commit 25b84002afb9 ("arm64: Support Clang UBSAN trap codes for better reporting"). Enable the reporting of UBSAN sanitizer detail on x86 architectures compiled with clang when CONFIG_UBSAN_TRAP=y. Signed-off-by: Gatlin Newhouse --- Changes in v4: - Impleme

[PATCH v5] x86/traps: Enable UBSAN traps on x86

2024-07-23 Thread Gatlin Newhouse
ned-off-by: Gatlin Newhouse --- Changes in v5: - Added references to the LLVM commits in the commit message from Kees and Marco's feedback - Renamed incorrect defines, and removed handle_ubsan_failure()'s duplicated work per Peter's feedback Changes in v4: - Implemen

[RFC v1 00/17] Add Safefetch double-fetch protection

2025-07-12 Thread Gatlin Newhouse
] https://www.usenix.org/conference/usenixsecurity24/presentation/duta [2] https://github.com/vusec/safefetch [3] https://github.com/vusec/safefetch-ae [4] https://github.com/gatlinnewhouse/linux Gatlin Newhouse (17): Add SafeFetch double-fetch protection to the kernel x86: syscall: support caching

[RFC v1 08/17] init: add caching startup and initialization to start_kernel()

2025-07-12 Thread Gatlin Newhouse
--- init/main.c | 7 +++ 1 file changed, 7 insertions(+) diff --git a/init/main.c b/init/main.c index 225a58279acd..72e55704ce2f 100644 --- a/init/main.c +++ b/init/main.c @@ -958,6 +958,10 @@ void start_kernel(void) trap_init(); mm_core_init(); poking_init(); +#ifdef

[RFC v1 11/17] kernel: add SafeFetch cache handling to dup_task_struct()

2025-07-12 Thread Gatlin Newhouse
--- kernel/fork.c | 17 + 1 file changed, 17 insertions(+) diff --git a/kernel/fork.c b/kernel/fork.c index 1ee8eb11f38b..379dcf5626e9 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -122,6 +122,12 @@ #include +#ifdef CONFIG_SAFEFETCH +#include +#include +#include +#end

[RFC v1 10/17] iov_iter: add SafeFetch pinning call to copy_from_user_iter()

2025-07-12 Thread Gatlin Newhouse
--- lib/iov_iter.c | 12 1 file changed, 12 insertions(+) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index f9193f952f49..8997272481c3 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -41,6 +41,10 @@ size_t copy_to_user_iter_nofault(void __user *iter_to, size_t progress,

[RFC v1 09/17] exit: add destruction of SafeFetch caches and debug info to do_exit()

2025-07-12 Thread Gatlin Newhouse
--- kernel/exit.c | 16 1 file changed, 16 insertions(+) diff --git a/kernel/exit.c b/kernel/exit.c index bb184a67ac73..c712cd11a2c7 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -951,6 +951,22 @@ void __noreturn do_exit(long code) exit_mm(); +#ifdef CONFIG_SAFEFE

[RFC v1 12/17] bug: add SafeFetch statistics tracking to __report_bug() calls

2025-07-12 Thread Gatlin Newhouse
--- lib/bug.c | 10 ++ 1 file changed, 10 insertions(+) diff --git a/lib/bug.c b/lib/bug.c index b1f07459c2ee..d1007c1b3dda 100644 --- a/lib/bug.c +++ b/lib/bug.c @@ -155,6 +155,9 @@ static enum bug_trap_type __report_bug(unsigned long bugaddr, struct pt_regs *re struct bug_entry

[RFC v1 07/17] gup: add non-caching get_user call to fault_in_readable()

2025-07-12 Thread Gatlin Newhouse
Adds non-caching call to fault_in_readable() for configurations with SafeFetch enabled and disabled readable pages. --- mm/gup.c | 4 1 file changed, 4 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index 3c39cbbeebef..69d2d110da3f 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2224,7 +2224,11 @@

[RFC v1 02/17] x86: syscall: support caching in do_syscall_64()

2025-07-12 Thread Gatlin Newhouse
Include safefetch and support caching strategy in syscalls to protect against time of check to time of use bugs. --- arch/x86/entry/syscall_64.c | 76 + 1 file changed, 76 insertions(+) diff --git a/arch/x86/entry/syscall_64.c b/arch/x86/entry/syscall_64.c inde

[RFC v1 05/17] uaccess: add non-caching copy_from_user functions

2025-07-12 Thread Gatlin Newhouse
--- include/linux/uaccess.h | 30 ++ 1 file changed, 30 insertions(+) diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index 7c06f4795670..d6d80bb9e0fa 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -186,6 +186,26 @@ _inline_copy_fr

[RFC v1 04/17] sched: add protection to task_struct

2025-07-12 Thread Gatlin Newhouse
Adds caching data structure for every task structure and optionally adds a statistics structure to each as well. --- include/linux/sched.h | 11 +++ init/init_task.c | 11 +++ 2 files changed, 22 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index 4

[RFC v1 15/17] kconfig: debug: add SafeFetch to debug kconfig

2025-07-12 Thread Gatlin Newhouse
--- lib/Kconfig.debug | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index ebe33181b6e6..d4b4214164a5 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1040,6 +1040,7 @@ config MEM_ALLOC_PROFILING_DEBUG source "lib/Kconfig.kasan" source "lib/Kc

[RFC v1 17/17] vfs: ioctl: add logging to ioctl_file_dedupe_range() for testing

2025-07-12 Thread Gatlin Newhouse
This adds a message indicating a double-fetch bug trigger for testing the SafeFetch patchset. It add the message right before the fix for CVE-2016-6516 [1][2] introduced by Scott Bauer [3]. Which can be tested by first compiling the double-fetch program from [4], and running a shell script similar

[RFC v1 13/17] softirq: add SafeFetch statistics to irq_enter_rc() and irq_exit()

2025-07-12 Thread Gatlin Newhouse
--- kernel/softirq.c | 8 1 file changed, 8 insertions(+) diff --git a/kernel/softirq.c b/kernel/softirq.c index 513b1945987c..cfed8419b6c5 100644 --- a/kernel/softirq.c +++ b/kernel/softirq.c @@ -632,6 +632,10 @@ void irq_enter_rcu(void) */ void irq_enter(void) { +#ifdef SAFEFETCH_D

[RFC v1 14/17] makefile: add SafeFetch support to makefiles

2025-07-12 Thread Gatlin Newhouse
Also update version string for differentiating testing kernels from host kernels. --- Makefile | 3 ++- mm/Makefile | 1 + scripts/Makefile.lib | 4 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7eea2a41c905..6a3bf5849270 100644 -

[RFC v1 06/17] futex: add get_user_no_dfcache() functions

2025-07-12 Thread Gatlin Newhouse
Add disabled cache get_user function calls to futex functions to disable using the SafeFetch cache on any fast userspace mutexes. --- kernel/futex/core.c | 5 + kernel/futex/futex.h| 4 kernel/futex/pi.c | 5 + kernel/futex/requeue.c | 5 - kernel/futex/waitwake.c |

[RFC v1 16/17] x86: enable SafeFetch on x86_64 builds

2025-07-12 Thread Gatlin Newhouse
Disable HAVE_ARCH_AUDITSYSCALL and HAVE_ARCH_SOFT_DIRTY. Both options are untested with SafeFetch enabled as of right now. --- arch/x86/Kconfig | 5 +++-- init/Kconfig | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 71019b3b54ea.

[RFC v1 03/17] x86: asm: support caching in do_get_user_call()

2025-07-12 Thread Gatlin Newhouse
Adds various caching functions with different sizes alongside a macro to select the smallest possible caching function to enable caching of user calls to protect against time-of-check to time-of-use bugs. --- arch/x86/include/asm/uaccess.h| 211 -- arch/x86/include/