Re: [PATCH] of: unittest: Require BUG_ON_DATA_CORRUPTION to be disabled
From: Rob Herring
Date: Fri Oct 30 2026 - 12:26:50 EST
On Thu, Oct 29, 2026 at 5:48 PM Danilo Krummrich <dakr@xxxxxxxxxx> wrote:
>
> With CONFIG_OF_UNITTEST=y and CONFIG_BUG_ON_DATA_CORRUPTION=y, the
> machine no longer boots after commit 5b5224220747 ("refcount: Use
> CONFIG_BUG_ON_DATA_CORRUPTION for UAF-related errors").
>
> of_unittest_lifecycle() deliberately calls of_node_put() after the
> node's reference count has reached zero. The test expects a warning and
> continues to check that a subsequent put does not produce another
> warning. With BUG_ON_DATA_CORRUPTION enabled, refcount underflow now
> triggers BUG() instead. This panics the kernel during boot:
>
> kernel BUG at lib/refcount.c:37!
> Oops: invalid opcode: 0000 [#1] SMP NOPTI
> CPU: 1 UID: 0 PID: 1 Comm: swapper/0 Tainted: G N 7.3.0+ #14 PREEMPT(full)
> RIP: 0010:refcount_warn_saturate+0x89/0x90
> Call Trace:
> of_unittest_lifecycle+0x158/0x310
> of_unittest+0x105/0x130
> do_one_initcall+0x127/0x350
> do_initcall_level+0x7c/0xe0
> do_initcalls+0x59/0xa0
> kernel_init_freeable+0x118/0x1a0
> kernel_init+0x1f/0x140
> Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
>
> Make OF_UNITTEST depend on !BUG_ON_DATA_CORRUPTION and explain the
> restriction in its help text.
>
> Fixes: 5b5224220747 ("refcount: Use CONFIG_BUG_ON_DATA_CORRUPTION for UAF-related errors")
> Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx>
> ---
> Alternatively, we could also just remove the refcount underflow tests. It seems
> they are not really testing anything OF specific, but rather test the refcount
> implementation.
I'm fine with that. I think we should keep just the first part with
of_node_release() error check.
Rob