few printk fixups for 7.4

-----BEGIN PGP SIGNATURE-----
 
 iQJPBAABCAA5FiEESH4wyp42V4tXvYsjUqAMR0iAlPIFAmrtpuobFIAAAAAABAAO
 bWFudTIsMi41KzEuMTIsMiwyAAoJEFKgDEdIgJTy+HwP/jrbFz6NqGZ2ORjA+mLZ
 Hmu1sFK1IWX3aU938oxzqpiXktRo0uwYGPPuqyO+noL3AD25sRm4V5YtbSwt0zCa
 Dt0039vvDQwelfuSEvqJ5Pca3Ou5Y0kB8GfI7ooK6z0SWITDEOYPpRfab+PnVo7C
 wE2/u9rOnVPAb+bF+knSQ+1gu53qd5Y7IavKjoLshZ0NkxwgcgezZ5MgHQO8O01Y
 gaXQBHUe+jKccNIN+I1yyYUX+qA4zBpWgimEF9OgWtBVIEvyiUENNhZFyFfdaaPZ
 VxxyCmGqVl+CqR6Y4H3khCIIJsSGpoYRDhWYJz9dbkhbQ8D1Y0qKwuxP5g7LeO3o
 5thIg+p22DAS2h+AkxEvbL95bua0YqqGIFvokNuZFh1Jay4jVQ8VH58rCGvlz/Ci
 jMrHOeZE/hSulqKpNfDqaOYVcQyFbIO3oUIwCboLEFHTIh9qk9xcsF2oocJgFXD/
 ISDPyI6T3kAlUGRYVC7y63SzSmaILYKUTRDJg4wX7fniDv0On5a1NpAl3ww7qulk
 LHZsIIcoPrqF/dFo6b9DmBPy//snu1G37C0A8LX8LML5IRlmMBah3UN67LRQ7GJf
 /X+1RmPXQGBgxVZvvsd0lAZ99avUH5VCZ+tTtWG56W3GXBFYwApVjPotH3GXGLQL
 0kDrdJkKDx8kPI1HFEZQ0C9+
 =STIi
 -----END PGP SIGNATURE-----

Merge tag 'printk-for-7.4-fixups' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux

Pull printk fixes from Petr Mladek:

 - Prevent possible use-after-free when printk kthreads
   could not be created

 - Fix computation of the free space when allocating a
   bigger ring buffer

 - Add info about the new printk mailing list for
   printk-related subsystems

* tag 'printk-for-7.4-fixups' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux:
  printk: Avoid multiple unregistration in unregister_console_locked()
  MAINTAINERS: Add new "printk" mailing list for PRINTK, PRINTK INDEXING, and VSPRINTF
  printk_ringbuffer: Fix space_used() when blk_lpos->next overflows
This commit is contained in:
Linus Torvalds 2026-11-06 13:13:41 -08:00
commit bdeb84ed24
3 changed files with 36 additions and 9 deletions

View File

@ -22436,6 +22436,7 @@ M: Petr Mladek <pmladek@suse.com>
M: John Ogness <john.ogness@linutronix.de>
R: Steven Rostedt <rostedt@goodmis.org>
R: Sergey Senozhatsky <senozhatsky@chromium.org>
L: printk@lists.linux.dev
S: Maintained
T: git git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux.git
F: Documentation/core-api/printk-basics.rst
@ -22444,6 +22445,7 @@ F: kernel/printk/
PRINTK INDEXING
R: Chris Down <chris@chrisdown.name>
L: printk@lists.linux.dev
S: Maintained
F: Documentation/core-api/printk-index.rst
F: kernel/printk/index.c
@ -30062,6 +30064,7 @@ M: Steven Rostedt <rostedt@goodmis.org>
R: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
R: Rasmus Villemoes <linux@rasmusvillemoes.dk>
R: Sergey Senozhatsky <senozhatsky@chromium.org>
L: printk@lists.linux.dev
S: Maintained
T: git git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux.git
F: Documentation/core-api/printk-formats.rst

View File

@ -3792,6 +3792,13 @@ static struct syscore printk_syscore = {
* If appropriate, start nbcon kthreads and set @printk_kthreads_running.
* If any kthreads fail to start, those consoles are unregistered.
*
* Called after consoles are registered or unregistered.
*
* This MUST NOT be called within an hlist_for_each_entry_safe(console_list)
* loop because it can unregister multiple consoles if any kthreads fail to
* start. That would lead to use-after-free scenarios within the
* hlist_for_each_entry_safe(console_list) loop of the caller.
*
* Must be called under console_list_lock().
*/
static void printk_kthreads_check_locked(void)
@ -4230,7 +4237,20 @@ void register_console(struct console *newcon)
}
EXPORT_SYMBOL(register_console);
/* Must be called under console_list_lock(). */
/*
* Unregister the specified console.
*
* This can be called safely from within an
* hlist_for_each_entry_safe(console_list) loop because it unregisters
* _only_ the specified console.
*
* Afterwards the caller should call printk_kthreads_check_locked() since
* unregistering a console may require printer threads to start/stop. Note
* that printk_kthreads_check_locked() cannot be called safely from within
* an hlist_for_each_entry_safe(console_list) loop.
*
* Must be called under console_list_lock().
*/
static int unregister_console_locked(struct console *console)
{
bool use_device_lock = (console->flags & CON_NBCON) && console->write_atomic;
@ -4322,9 +4342,6 @@ static int unregister_console_locked(struct console *console)
if (console->exit)
res = console->exit(console);
/* Changed console list, may require printer threads to start/stop. */
printk_kthreads_check_locked();
return res;
}
@ -4333,7 +4350,12 @@ int unregister_console(struct console *console)
int res;
console_list_lock();
res = unregister_console_locked(console);
/* Changed console list, may require printer threads to start/stop. */
printk_kthreads_check_locked();
console_list_unlock();
return res;
}
@ -4472,6 +4494,10 @@ static int __init printk_late_init(void)
unregister_console_locked(con);
}
/* Changed console list, may require printer threads to start/stop. */
printk_kthreads_check_locked();
console_list_unlock();
ret = cpuhp_setup_state_nocalls(CPUHP_PRINTK_DEAD, "printk:dead", NULL,

View File

@ -1237,11 +1237,9 @@ static unsigned int space_used(struct prb_data_ring *data_ring,
if (BLK_DATALESS(blk_lpos))
return 0;
if (!is_blk_wrapped(data_ring, blk_lpos->begin, blk_lpos->next)) {
/* Data block does not wrap. */
return (DATA_INDEX(data_ring, blk_lpos->next) -
DATA_INDEX(data_ring, blk_lpos->begin));
}
/* Data block does not wrap. */
if (!is_blk_wrapped(data_ring, blk_lpos->begin, blk_lpos->next))
return blk_lpos->next - blk_lpos->begin;
/*
* For wrapping data blocks, the trailing (wasted) space is