From: John Ogness <john.ogness@linutronix.de>
To: Sebastian Siewior <bigeasy@linutronix.de>
Cc: Clark Williams <williams@redhat.com>,
Petr Mladek <pmladek@suse.com>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
Michael Thalmeier <michael.thalmeier@hale.at>,
Vincent Whitchurch <vincent.whitchurch@axis.com>,
linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org,
"Luis Claudio R. Goncalves" <lgoncalv@redhat.com>
Subject: [PATCH 5.10-rt] printk: ignore consoles without write() callback
Date: Fri, 17 Feb 2023 09:53:44 +0106 [thread overview]
Message-ID: <878rgw65lb.fsf@jogness.linutronix.de> (raw)
In-Reply-To: <87bkls65pf.fsf@jogness.linutronix.de>
The ttynull driver does not provide an implementation for the write()
callback. This leads to a NULL pointer dereference in the related
printing kthread, which assumes it can call that callback.
Do not create kthreads for consoles that do not implement the write()
callback. Also, for pr_flush(), ignore consoles that do not implement
write() or write_atomic(), since there is no way those consoles can
flush their output.
Link: https://lore.kernel.org/lkml/1831554214.546921.1676479103702.JavaMail.zimbra@hale.at
Reported-by: Michael Thalmeier <michael.thalmeier@hale.at>
Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
kernel/printk/printk.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index d2205872304d..64747c72fbea 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2267,6 +2267,10 @@ static int printk_kthread_func(void *data)
/* Must be called within console_lock(). */
static void start_printk_kthread(struct console *con)
{
+ /* No need to start a printing thread if the console cannot print. */
+ if (!con->write)
+ return;
+
con->thread = kthread_run(printk_kthread_func, con,
"pr/%s%d", con->name, con->index);
if (IS_ERR(con->thread)) {
@@ -3566,6 +3570,8 @@ bool pr_flush(int timeout_ms, bool reset_on_progress)
for_each_console(con) {
if (!(con->flags & CON_ENABLED))
continue;
+ if (!con->write && !con->write_atomic)
+ continue;
printk_seq = atomic64_read(&con->printk_seq);
if (printk_seq < seq)
diff += seq - printk_seq;
--
2.30.2
next prev parent reply other threads:[~2023-02-17 8:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-16 10:39 [PATCH 5.15-rt] printk: ignore consoles without write() callback John Ogness
2023-02-16 16:54 ` Sebastian Siewior
2023-02-17 8:45 ` John Ogness
2023-02-17 8:47 ` John Ogness [this message]
2023-02-17 11:55 ` [PATCH 5.10-rt] " Luis Claudio R. Goncalves
2025-04-23 10:10 ` [PATCH 5.15-rt] " Krishanth Jagaduri
2025-04-28 14:45 ` [External] : " Joseph Salisbury
2025-05-21 12:30 ` Krishanth Jagaduri
2025-05-21 15:32 ` Joseph Salisbury
2025-05-23 5:05 ` Krishanth Jagaduri
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=878rgw65lb.fsf@jogness.linutronix.de \
--to=john.ogness@linutronix.de \
--cc=bigeasy@linutronix.de \
--cc=lgoncalv@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=michael.thalmeier@hale.at \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=vincent.whitchurch@axis.com \
--cc=williams@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).