Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "John Ogness" <john.ogness@linutronix.de>,
	"Petr Mladek" <pmladek@suse.com>
Cc: "Sergey Senozhatsky" <senozhatsky@chromium.org>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Ryan Roberts" <ryan.roberts@arm.com>,
	"Breno Leitao" <leitao@debian.org>,
	printk@lists.linux.dev,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Baoquan He" <baoquan.he@linux.dev>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Pasha Tatashin" <pasha.tatashin@soleen.com>,
	"Pratyush Yadav" <pratyush@kernel.org>,
	"Dave Young" <ruirui.yang@linux.dev>,
	"Bradley Morgan" <include@grrlz.net>,
	"Oleg Nesterov" <oleg@redhat.com>,
	"Pavel Tikhomirov" <ptikhomirov@virtuozzo.com>,
	"Petr Pavlu" <petr.pavlu@suse.com>,
	"Cen Zhang (Microsoft)" <blbllhy@gmail.com>,
	kexec@lists.infradead.org
Subject: Re: [PATCH printk v3 6/7] printk: Add unsafe flush points for panic+kexec and emergency_restart
Date: Thu, 19 Nov 2026 23:03:58 +0000	[thread overview]
Message-ID: <sashiko-outbox-224169@kernel.org> (raw)
In-Reply-To: <20261118230345.808560-7-john.ogness@linutronix.de>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] printk: nbcon: con->pbufs corruption on hostile takeover in
  emergency_restart()
--

commit bc98e7fe84227c1b12eaff8bf1021023be510742
Author: John Ogness <john.ogness@linutronix.de>

printk: Add unsafe flush points for panic+kexec and emergency_restart

This commit adds nbcon_atomic_flush_unsafe(PR_FLUSH_RESTART) calls to
__crash_kexec() and emergency_restart() so that CON_NBCON_ATOMIC_UNSAFE
consoles can flush when permitted by their unsafe policy.

> diff --git a/kernel/reboot.c b/kernel/reboot.c
> index a93c23b9e1948..b26d131c54151 100644
> --- a/kernel/reboot.c
> +++ b/kernel/reboot.c
> @@ -102,6 +102,7 @@ void emergency_restart(void)
>  	 */
>  	nbcon_cpu_emergency_enter();
>  	printk_trigger_flush();
> +	nbcon_atomic_flush_unsafe(PR_FLUSH_RESTART);
>  
>  	machine_emergency_restart();
>  }

[Severity: Medium]
Can this corrupt con->pbufs when emergency_restart() performs a hostile
takeover outside of panic()?

When emergency_restart() is invoked directly (for example via SysRq-b)
rather than from panic(), panic_on_this_cpu() is false and other CPUs remain
active.  If a console permits unsafe takeover on PR_FLUSH_RESTART (such as
netconsole with NBCON_EMERGENCY_RESTART_FLUSH) while an NBCON_PRIO_NORMAL
context holds it inside an unsafe section, nbcon_context_try_acquire()
performs an unsafe hostile takeover at NBCON_PRIO_EMERGENCY but still
assigns con->pbufs instead of panic_nbcon_pbufs:

kernel/printk/nbcon.c:nbcon_context_try_acquire() {
	...
	/* Assign the appropriate buffer for this context. */
	if (panic_on_this_cpu())
		ctxt->pbufs = &panic_nbcon_pbufs;
	else
		ctxt->pbufs = con->pbufs;
	...
}

CPU0 (NBCON_PRIO_NORMAL)          CPU1 (emergency_restart)
nbcon_emit_next_record()
  nbcon_context_enter_unsafe()
  printk_get_next_message()
    // writes con->pbufs->outbuf
                                  nbcon_atomic_flush_unsafe(PR_FLUSH_RESTART)
                                    ...
                                    nbcon_context_try_acquire_hostile()
                                    ctxt->pbufs = con->pbufs
                                    nbcon_emit_next_record()
                                      printk_get_next_message()
                                        // overwrites con->pbufs->outbuf
  con->write_thread()
    // reads corrupted con->pbufs->outbuf  <-- buffer corruption

Both contexts then concurrently read and write con->pbufs->outbuf and
con->pbufs->scratchbuf.  For netconsole_ext, overwriting the formatted
message while send_msg_fragmented() is scanning wctxt->outbuf for the ';'
header delimiter can trigger WARN_ON_ONCE(!msgbody) or match a ';' past
MAX_PRINT_CHUNK, overflowing nt->buf[].

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118230345.808560-1-john.ogness@linutronix.de?part=6


      reply	other threads:[~2026-11-19 23:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 23:03 [PATCH printk v3 0/7] Introduce policies for unsafe flushing John Ogness
2026-11-18 23:03 ` [PATCH printk v3 6/7] printk: Add unsafe flush points for panic+kexec and emergency_restart John Ogness
2026-11-19 23:03   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-224169@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=baoquan.he@linux.dev \
    --cc=blbllhy@gmail.com \
    --cc=include@grrlz.net \
    --cc=john.ogness@linutronix.de \
    --cc=kexec@lists.infradead.org \
    --cc=leitao@debian.org \
    --cc=oleg@redhat.com \
    --cc=pasha.tatashin@soleen.com \
    --cc=petr.pavlu@suse.com \
    --cc=pmladek@suse.com \
    --cc=pratyush@kernel.org \
    --cc=printk@lists.linux.dev \
    --cc=ptikhomirov@virtuozzo.com \
    --cc=rostedt@goodmis.org \
    --cc=rppt@kernel.org \
    --cc=ruirui.yang@linux.dev \
    --cc=ryan.roberts@arm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=senozhatsky@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox