CONFIG_UBSAN_TRAP #UD error message on x86 [was: Re: [CRASH][BISECTED] 6.4.1 crash in boot]

Jann Horn
2023-07-05T15:17:14Z

On Wed, Jul 5, 2023 at 4:10 AM Kees Cook <kees@kernel.org> wrote:
> On July 4, 2023 4:15:20 PM PDT, Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr> wrote:
> >On 7/4/23 23:36, Kees Cook wrote:
> >> On July 4, 2023 10:20:11 AM PDT, Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr> wrote:
> >>> all Wayland and X11.org GUI applications fail to start, with errors like this one:
> >>>
> >>> Jul 4 19:09:07 defiant kernel: [ 40.529719] invalid opcode: 0000 [#1] PREEMPT SMP NOPTI
> >>
> >> Hmm, is CONFIG_UBSAN_TRAP set?
> >
> >marvin@defiant:~/linux/kernel/linux_torvalds$ grep CONFIG_UBSAN_TRAP .config
> >CONFIG_UBSAN_TRAP=y
>
> Ah-ha! Turn that off please. With it off you will get much more useful reports from USBAN.

It might be useful if the x86 code under handle_invalid_op() at least
printed a warning about this when the kernel crashes with #UD on a
system with CONFIG_UBSAN_TRAP=y? It seems pretty unintuitive and
unhelpful that the kernel just crashes itself with a #UD and no
further information in this configuration.

Even just a "WARNING: CONFIG_UBSAN_TRAP active, #UD might be caused by
that" on every #UD that does not come from a known BUG() location or
such might be better than nothing...

And maybe the Kconfig help text could be clearer on this, too.
Currently it does say that this turns warnings into "full exceptions
that abort the running kernel code" but it does not say that the
exception reporting will become pretty unhelpful, so it's probably not
really what you'd want for debugging.