Re: [PATCH printk] printk: Fix possible console use-after-free

From: Petr Mladek

Date: Thu Jul 09 2026 - 10:25:46 EST


On Fri 2026-07-03 16:20:31, John Ogness wrote:
> When emitting a record via legacy printing, it is possible that a handover
> to another legacy printing context occurs. When a context has performed a
> handover, the console SRCU read lock is released and the pointer to the
> console struct might now be invalid. Therefore, after calling
> nbcon_legacy_emit_next_record() or console_emit_next_record(), it is
> necessary to check if a handover occurred _before_ further @con usage.
>
> Sashiko pointed out that console_flush_one_record() was not doing this.
>
> In console_flush_one_record(), after emitting a record, move the further
> usage of @con after the handover check.
>
> Fixes: c158834b223f ("printk: nbcon: Use nbcon consoles in console_flush_all()")
> Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
> Closes: https://lore.kernel.org/lkml/20260630170903.099D61F000E9@xxxxxxxxxxxxxxx
> Signed-off-by: John Ogness <john.ogness@xxxxxxxxxxxxx>

JFYI, the patch has been committed into printk/linux.git,
branch for-7.3-trivial.

Best Regards,
Petr