printk: Use scnprintf() to print the message about the dropped messages on a console
Subsystems (2)
Petr Mladek
maintainerPATCH 1/1 printk: Use scnprintf() to print the message about the dropped messages on a console
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.
Addresses-Coverity-ID: 1530570 ("Memory - corruptions")
--- kernel/printk/printk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/printk/printk.c +1 -1
@@ -2716,7 +2716,7 @@ static void console_prepend_dropped(struct printk_message *pmsg, unsigned long dchar *outbuf = &pbufs->outbuf[0 ];size_t len; - len =snprintf (scratchbuf, scratchbuf_sz, + len =scnprintf (scratchbuf, scratchbuf_sz,"** %lu printk messages dropped **\n" , dropped);/*
Signature · 1 line
2.35.3
Quoted 5 lines · Petr Mladek
Reported-by coverity-bot <[email protected]>Addresses-Coverity-ID: 1530570 ("Memory - corruptions")
Fixes c4fcc617e148 ("printk: introduce console_prepend_dropped() for dropped messages")Signed-off-by Petr Mladek <[email protected]>
Quoted 8 lines · John Ogness
Quoted 5 lines · Petr Mladek
Reported-by coverity-bot <[email protected]>Addresses-Coverity-ID: 1530570 ("Memory - corruptions")
Fixes c4fcc617e148 ("printk: introduce console_prepend_dropped() for dropped messages")Signed-off-by Petr Mladek <[email protected]>Reviewed-by John Ogness <[email protected]>
Petr Mladek
maintainerQuoted 9 lines · Petr Mladek
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.
Quoted 5 lines
Reported-by coverity-bot <[email protected]>Addresses-Coverity-ID: 1530570 ("Memory - corruptions")
Fixes c4fcc617e148 ("printk: introduce console_prepend_dropped() for dropped messages")Signed-off-by Petr Mladek <[email protected]>
JFYI, the patch has been comitted into printk/linux.git, branch rework/buffers-cleanup.
Best Regards,
Petr