printk: ignore consoles without write() callback
John Ogness
maintainerPATCH 1/1 printk: ignore consoles without write() callback
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.
---
This is only a problem for the PREEMPT_RT tree. Mainline does not have this problem.
kernel/printk/printk.c | 6 ++++++ 1 file changed, 6 insertions(+)
kernel/printk/printk.c +6 -0
@@ -2343,6 +2343,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)) {
@@ -3737,6 +3741,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 =read_console_seq (con);if (printk_seq < seq) diff += seq - printk_seq;
Signature · 1 line
2.30.2
Quoted 2 lines · John Ogness
This is only a problem for the
PREEMPT_RTtree. Mainline does not have this problem.
Is this 5.15 and less or current dev RT and less?
Sebastian
John Ogness
maintainerQuoted 4 lines · Sebastian Siewior
Quoted 2 lines
This is only a problem for the
PREEMPT_RTtree. Mainline does not have this problem.Is this 5.15 and less or current dev RT and less?
5.10-rt is also affected. The changes for 5.10-rt are the same, but the patch does not apply as-is. I will reply with a patch for 5.10-rt.
5.4-rt is not affected.
John Ogness
John Ogness
maintainerPATCH 1/1 printk: ignore consoles without write() callback
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.
--- kernel/printk/printk.c | 6 ++++++ 1 file changed, 6 insertions(+)
kernel/printk/printk.c +6 -0
@@ -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;
Signature · 1 line
2.30.2
Quoted 4 lines · John Ogness
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.
Quoted 8 lines
Do not create kthreads for consoles that do not implement the
write()callback. Also, forpr_flush(), ignore consoles that do not implementwrite()orwrite_atomic(), since there is no way those consoles can flush their output.Reported-by Michael Thalmeier <[email protected]>Signed-off-by John Ogness <[email protected]>
Thank you! I will apply that to the next 5.10-rt build.
Luis
Quoted 31 lines
--- kernel/printk/printk.c | 6 ++++++ 1 file changed, 6 insertions(+)kernel/printk/printk.c +6
-0@@ -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;Signature · 1 line
2.30.2
---end quoted text---
Quoted 4 lines · John Ogness
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.
Quoted 8 lines
Do not create kthreads for consoles that do not implement the
write()callback. Also, forpr_flush(), ignore consoles that do not implementwrite()orwrite_atomic()since there is no way those consoles can flush their output.---
This is only a problem for thePREEMPT_RTtree. Mainline does not have this problem.
Sorry for resurrecting this old thread but we actually want this patch in 5.15-rt.
I am not sure why this was not applied to 5.15-rt yet since it is already applied to 5.10-rt.
Could you please consider to pick this for 5.15-rt?
Best regards,
Krishanth
Re: [External] : Re: [PATCH 5.15-rt] printk: ignore consoles without write() callback
Quoted 16 lines · Krishanth Jagaduri
Quoted 4 lines · John Ogness
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.Quoted 8 lines
Do not create kthreads for consoles that do not implement the
write()callback. Also, forpr_flush(), ignore consoles that do not implementwrite()orwrite_atomic()since there is no way those consoles can flush their output.---
This is only a problem for thePREEMPT_RTtree. Mainline does not have this problem.Sorry for resurrecting this old thread but we actually want this patch in 5.15-rt.
Quoted 7 lines
I am not sure why this was not applied to 5.15-rt yet since it is already applied to 5.10-rt.
Could you please consider to pick this for 5.15-rt?
Best regards,
Krishanth
Hi Krishanth,
Thanks for pointing this out. I will investigate including this patch in the next v5.15 patch set, which should be released this week.
Thanks,
Joe
Re: [External] : Re: [PATCH 5.15-rt] printk: ignore consoles without write() callback
Quoted 8 lines · Joseph Salisbury
Hi Krishanth,
Thanks for pointing this out. I will investigate including this patch in the next v5.15 patch set, which should be released this week.
Thanks,
Joe
Thank you for including this patch in v5.15.183-rt85.
Best regards,
Krishanth
Re: [External] : Re: [PATCH 5.15-rt] printk: ignore consoles without write() callback
Quoted 6 lines · Krishanth Jagaduri
Quoted 5 lines · Joseph Salisbury
Hi Krishanth,
Thanks for pointing this out. I will investigate including this patch in the next v5.15 patch set, which should be released this week.
Quoted 7 lines
Quoted 3 lines
Thanks,
Joe
Thank you for including this patch in v5.15.183-rt85.
Best regards,
Krishanth
Not a problem, Krishanth! Just let me know if you run into any issues.
Thanks,
Joe
Re: [External] : Re: [PATCH 5.15-rt] printk: ignore consoles without write() callback
Quoted 14 lines · Joseph Salisbury
Quoted 11 lines · Krishanth Jagaduri
Quoted 8 lines · Joseph Salisbury
Hi Krishanth,
Thanks for pointing this out. I will investigate including this patch in the next v5.15 patch set, which should be released this week.
Thanks,
Joe
Thank you for including this patch in v5.15.183-rt85.
Quoted 8 lines
Quoted 2 lines
Best regards,
KrishanthNot a problem, Krishanth! Just let me know if you run into any issues.
Thanks,
Joe
Sure, I will let you know if any.
Best regards,
Krishanth