All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] printk: Use scnprintf() to print the message about the dropped messages on a console
@ 2023-01-17 16:10 Petr Mladek
  2023-01-17 21:48 ` John Ogness
  2023-01-18  9:31 ` Petr Mladek
  0 siblings, 2 replies; 4+ messages in thread
From: Petr Mladek @ 2023-01-17 16:10 UTC (permalink / raw)
  To: John Ogness
  Cc: Sergey Senozhatsky, Steven Rostedt, coverity-bot,
	Gustavo A . R . Silva, linux-next, linux-hardening, linux-kernel,
	Petr Mladek, coverity-bot

Use scnprintf() for printing the message about dropped messages on
a console. It returns the really written length of the message.
It prevents potential buffer overflow when the returned length is
later used to copy the buffer content.

Note that the previous code was safe because the scratch buffer was
big enough and the message always fit in. But scnprintf() makes
it more safe, definitely.

Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
Addresses-Coverity-ID: 1530570 ("Memory - corruptions")
Fixes: c4fcc617e148 ("printk: introduce console_prepend_dropped() for dropped messages")
Link: https://lore.kernel.org/r/202301131544.D9E804CCD@keescook
Signed-off-by: Petr Mladek <pmladek@suse.com>
---
 kernel/printk/printk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 55338bfd3b55..a9b7dade0d2e 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2716,7 +2716,7 @@ static void console_prepend_dropped(struct printk_message *pmsg, unsigned long d
 	char *outbuf = &pbufs->outbuf[0];
 	size_t len;
 
-	len = snprintf(scratchbuf, scratchbuf_sz,
+	len = scnprintf(scratchbuf, scratchbuf_sz,
 		       "** %lu printk messages dropped **\n", dropped);
 
 	/*
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] printk: Use scnprintf() to print the message about the dropped messages on a console
  2023-01-17 16:10 [PATCH] printk: Use scnprintf() to print the message about the dropped messages on a console Petr Mladek
@ 2023-01-17 21:48 ` John Ogness
  2023-01-18  0:33   ` Sergey Senozhatsky
  2023-01-18  9:31 ` Petr Mladek
  1 sibling, 1 reply; 4+ messages in thread
From: John Ogness @ 2023-01-17 21:48 UTC (permalink / raw)
  To: Petr Mladek
  Cc: Sergey Senozhatsky, Steven Rostedt, coverity-bot,
	Gustavo A . R . Silva, linux-next, linux-hardening, linux-kernel,
	Petr Mladek, coverity-bot

On 2023-01-17, Petr Mladek <pmladek@suse.com> wrote:
> Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
> Addresses-Coverity-ID: 1530570 ("Memory - corruptions")
> Fixes: c4fcc617e148 ("printk: introduce console_prepend_dropped() for dropped messages")
> Link: https://lore.kernel.org/r/202301131544.D9E804CCD@keescook
> Signed-off-by: Petr Mladek <pmladek@suse.com>

Reviewed-by: John Ogness <john.ogness@linutronix.de>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] printk: Use scnprintf() to print the message about the dropped messages on a console
  2023-01-17 21:48 ` John Ogness
@ 2023-01-18  0:33   ` Sergey Senozhatsky
  0 siblings, 0 replies; 4+ messages in thread
From: Sergey Senozhatsky @ 2023-01-18  0:33 UTC (permalink / raw)
  To: John Ogness
  Cc: Petr Mladek, Sergey Senozhatsky, Steven Rostedt, coverity-bot,
	Gustavo A . R . Silva, linux-next, linux-hardening, linux-kernel,
	coverity-bot

On (23/01/17 22:54), John Ogness wrote:
> On 2023-01-17, Petr Mladek <pmladek@suse.com> wrote:
> > Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
> > Addresses-Coverity-ID: 1530570 ("Memory - corruptions")
> > Fixes: c4fcc617e148 ("printk: introduce console_prepend_dropped() for dropped messages")
> > Link: https://lore.kernel.org/r/202301131544.D9E804CCD@keescook
> > Signed-off-by: Petr Mladek <pmladek@suse.com>
> 
> Reviewed-by: John Ogness <john.ogness@linutronix.de>

Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] printk: Use scnprintf() to print the message about the dropped messages on a console
  2023-01-17 16:10 [PATCH] printk: Use scnprintf() to print the message about the dropped messages on a console Petr Mladek
  2023-01-17 21:48 ` John Ogness
@ 2023-01-18  9:31 ` Petr Mladek
  1 sibling, 0 replies; 4+ messages in thread
From: Petr Mladek @ 2023-01-18  9:31 UTC (permalink / raw)
  To: John Ogness
  Cc: Sergey Senozhatsky, Steven Rostedt, coverity-bot,
	Gustavo A . R . Silva, linux-next, linux-hardening, linux-kernel,
	coverity-bot

On Tue 2023-01-17 17:10:31, Petr Mladek wrote:
> Use scnprintf() for printing the message about dropped messages on
> a console. It returns the really written length of the message.
> It prevents potential buffer overflow when the returned length is
> later used to copy the buffer content.
> 
> Note that the previous code was safe because the scratch buffer was
> big enough and the message always fit in. But scnprintf() makes
> it more safe, definitely.
> 
> Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
> Addresses-Coverity-ID: 1530570 ("Memory - corruptions")
> Fixes: c4fcc617e148 ("printk: introduce console_prepend_dropped() for dropped messages")
> Link: https://lore.kernel.org/r/202301131544.D9E804CCD@keescook
> Signed-off-by: Petr Mladek <pmladek@suse.com>

JFYI, the patch has been comitted into printk/linux.git,
branch rework/buffers-cleanup.

Best Regards,
Petr

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-18 10:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-17 16:10 [PATCH] printk: Use scnprintf() to print the message about the dropped messages on a console Petr Mladek
2023-01-17 21:48 ` John Ogness
2023-01-18  0:33   ` Sergey Senozhatsky
2023-01-18  9:31 ` Petr Mladek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.