lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAM5zL5okN67bsTs6ZodcJd45zQ_BP+ruUwOkPMY97Snma0ugzQ@mail.gmail.com>
Date: Thu, 10 Apr 2025 15:12:54 +0200
From: Paweł Anikiel <panikiel@...gle.com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Sami Tolvanen <samitolvanen@...gle.com>, Kees Cook <kees@...nel.org>, 
	Alex Gaynor <alex.gaynor@...il.com>, Borislav Petkov <bp@...en8.de>, 
	Dave Hansen <dave.hansen@...ux.intel.com>, Ingo Molnar <mingo@...hat.com>, 
	Josh Poimboeuf <jpoimboe@...nel.org>, Masahiro Yamada <masahiroy@...nel.org>, 
	Miguel Ojeda <ojeda@...nel.org>, Thomas Gleixner <tglx@...utronix.de>, Alice Ryhl <aliceryhl@...gle.com>, 
	Nathan Chancellor <nathan@...nel.org>, x86@...nel.org, linux-kernel@...r.kernel.org, 
	rust-for-linux@...r.kernel.org
Subject: Re: [PATCH] x86/Kconfig: make CFI_AUTO_DEFAULT depend on !RUST

On Thu, Apr 10, 2025 at 2:45 PM Peter Zijlstra <peterz@...radead.org> wrote:
>
> On Thu, Apr 10, 2025 at 02:36:02PM +0200, Peter Zijlstra wrote:
> > On Thu, Apr 10, 2025 at 11:54:20AM +0000, Paweł Anikiel wrote:
> > > Calling core::fmt::write() from rust code while FineIBT is enabled
> > > results in a kernel panic:
> > >
> > > [ 4614.199779] kernel BUG at arch/x86/kernel/cet.c:132!
> > > [ 4614.205343] Oops: invalid opcode: 0000 [#1] PREEMPT SMP NOPTI
> > > [ 4614.211781] CPU: 2 UID: 0 PID: 6057 Comm: dmabuf_dump Tainted: G     U     O       6.12.17-android16-0-g6ab38c534a43 #1 9da040f27673ec3945e23b998a0f8bd64c846599
> > > [ 4614.227832] Tainted: [U]=USER, [O]=OOT_MODULE
> > > [ 4614.241247] RIP: 0010:do_kernel_cp_fault+0xea/0xf0
> > > [ 4614.246621] Code: c6 15 8d ad ac 48 0f 44 f1 48 8d 04 80 48 8d 14 45 d0 37 42 ac 48 c7 c7 22 99 bb ac e8 9f 7a 05 00 0f 0b eb 9a 67 0f b9 40 12 <0f> 0b cc cc cc cc 66 0f 1f 00 41 81 ea 00 00 00 00 74 03 0f 0b 90
> > > [ 4614.267606] RSP: 0018:ffffb95acfa4b978 EFLAGS: 00010097
> > > [ 4614.273464] RAX: 0000000000000057 RBX: ffffb95acfa4b9b8 RCX: 3ff1c813cb576300
> > > [ 4614.281426] RDX: ffff9a50b792b8d0 RSI: ffff9a50b791d548 RDI: ffff9a50b791d548
> > > [ 4614.289408] RBP: ffffb95acfa4b980 R08: 0000000000000d7c R09: ffffffffad45d500
> > > [ 4614.297399] R10: 0000000000002874 R11: 0000000000000004 R12: 0000000000000000
> > > [ 4614.305369] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000003
> > > [ 4614.313345] FS:  000076fa106dcfe8(0000) GS:ffff9a50b7900000(0000) knlGS:0000000000000000
> > > [ 4614.322386] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> > > [ 4614.328806] CR2: 000076f8fc207bd0 CR3: 0000000227242000 CR4: 0000000000f52eb0
> > > [ 4614.336777] PKRU: 55555554
> > > [ 4614.339786] Call Trace:
> > > [ 4614.342524]  <TASK>
> > > [ 4614.344867]  ? __die_body+0x69/0xb0
> > > [ 4614.348786]  ? die+0xa9/0xd0
> > > [ 4614.352000]  ? do_trap+0x89/0x160
> > > [ 4614.355721]  ? do_kernel_cp_fault+0xea/0xf0
> > > [ 4614.360413]  ? handle_invalid_op+0x69/0x90
> > > [ 4614.364985]  ? do_kernel_cp_fault+0xea/0xf0
> > > [ 4614.369654]  ? exc_invalid_op+0x36/0x60
> > > [ 4614.373959]  ? asm_exc_invalid_op+0x1f/0x30
> > > [ 4614.378643]  ? do_kernel_cp_fault+0xea/0xf0
> > > [ 4614.383335]  ? do_kernel_cp_fault+0x31/0xf0
> > > [ 4614.388005]  exc_control_protection+0x49/0x70
> > > [ 4614.392871]  asm_exc_control_protection+0x2b/0x60
> > > [ 4614.398144] RIP: 0010:_RNvXs5_NtNtNtCs3o2tGsuHyou_4core3fmt3num3impyNtB9_7Display3fmt+0x0/0x20
> > > [ 4614.407792] Code: 48 f7 df 48 0f 48 f9 48 89 f2 89 c6 5d e9 18 fd ff ff 0f 1f 84 00 00 00 00 00 f3 0f 1e fa 41 81 ea 14 61 af 2c 74 03 0f 0b 90 <66> 0f 1f 00 55 48 89 e5 48 89 f2 48 8b 3f be 01 00 00 00 5d e9 e7
> > > [ 4614.428775] RSP: 0018:ffffb95acfa4ba68 EFLAGS: 00010246
> > > [ 4614.434609] RAX: 0000000000000000 RBX: 0000000000000010 RCX: 0000000000000000
> > > [ 4614.442587] RDX: 0000000000000007 RSI: ffffb95acfa4ba70 RDI: ffffb95acfa4bc88
> > > [ 4614.450557] RBP: ffffb95acfa4bae0 R08: ffff0a00ffffff05 R09: 0000000000000070
> > > [ 4614.458527] R10: 0000000000000000 R11: ffffffffab67eaf0 R12: ffffb95acfa4bcc8
> > > [ 4614.466493] R13: ffffffffac5d50f0 R14: 0000000000000000 R15: 0000000000000000
> > > [ 4614.474473]  ? __cfi__RNvXs5_NtNtNtCs3o2tGsuHyou_4core3fmt3num3impyNtB9_7Display3fmt+0x10/0x10
> > > [ 4614.484118]  ? _RNvNtCs3o2tGsuHyou_4core3fmt5write+0x1d2/0x250
> > >
> > > This happens because core::fmt::write() calls
> > > core::fmt::rt::Argument::fmt(), which currently has CFI disabled:
> > >
> > > library/core/src/fmt/rt.rs:
> > > 171     // FIXME: Transmuting formatter in new and indirectly branching to/calling
> > > 172     // it here is an explicit CFI violation.
> > > 173     #[allow(inline_no_sanitize)]
> > > 174     #[no_sanitize(cfi, kcfi)]
> > > 175     #[inline]
> > > 176     pub(super) unsafe fn fmt(&self, f: &mut Formatter<'_>) -> Result {
> > >
> > > This causes a Control Protection exception, because FineIBT has sealed
> > > off the original function's endbr64.
> > >
> > > This makes rust currently incompatible with FineIBT. Add a Kconfig
> > > dependency that prevents FineIBT from getting turned on by default
> > > if rust is enabled.
> >
> > Why ?!, what's wrong with removing that no_sanitize() instead?

I'll let the rust maintainers answer this one.

> >
> > How is it still compatible with kCFI and not with FineIBT?

kCFI keeps the original function's endbr64. If a callsite disables
CFI, it simply jumps to that function (without any magic value
checks), the endbr64 is there, so no #CP.

With FineIBT, the original function's endbr64 gets replaced with a
nop, and the callsite is supposed to be modified to jump to the CFI
preamble. With CFI disabled, that modification doesn't happen
(cfi_rewrite_callers() quietly ignores that callsite), so we jump to
the nop, and we get a #CP.

>
> FWIW, CFI violations of any kind are a no-no. They're not accepted in C
> and they're not accepted in Rust. This is clearly a Rust bug that needs
> to be fixed ASAP. Disabling CFI is not an option.

This is a known issue, but it doesn't seem to have high priority:
https://github.com/rust-lang/rust/issues/115199

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ