[PATCHv2 0/4] Access console drivers list under console_sem

From: Sergey Senozhatsky
Date: Fri Apr 26 2019 - 01:33:13 EST


Hello,

Normally, we grab console_sem lock before we iterate consoles
list, which is necessary if we want to be race free. The only exception
to this rule is console_flush_on_panic(). However, it seems that we are
not fully race free - register_console() iterates console drivers list
in unsafe manner in several places. E.g. the following scenarion:

CPU0 CPU1
register_console() unregister_console()
console_lock()
for_each_console() // modify console_drivers
con->foo kfree(con)

I factored out register_console() and unregister_console() and now
the bulk of the work is done under console_sem. Both in register
and unregister paths we now have that oddly looking thing

pr_info("console enabled/disabled");
console_unlock();
console_lock();

Which is not really odd, in fact. This is to make sure that we always
print messages on all the consoles.

v2:
- removed outdated comment (Petr)
- factor out register_console() and always run it under console_sem (Petr)
- added a patch which enusures that we always print "console disabled'
on every console, before we unregister one of them

Sergey Senozhatsky (4):
printk: factor out __unregister_console() code
printk: remove invalid register_console() comment
printk: factor out register_console() code
printk: make sure we always print console disabled message

kernel/printk/printk.c | 125 +++++++++++++++++++++++++----------------
1 file changed, 76 insertions(+), 49 deletions(-)

--
2.21.0