Skip to content

Commit c09bf0d

Browse files
keescristicc
authored andcommitted
printk: ringbuffer: Fix truncating buffer size min_t cast
If an output buffer size exceeded U16_MAX, the min_t(u16, ...) cast in copy_data() was causing writes to truncate. This manifested as output bytes being skipped, seen as %NUL bytes in pstore dumps when the available record size was larger than 65536. Fix the cast to no longer truncate the calculation. Cc: Petr Mladek <pmladek@suse.com> Cc: Sergey Senozhatsky <senozhatsky@chromium.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: John Ogness <john.ogness@linutronix.de> Reported-by: Vijay Balakrishna <vijayb@linux.microsoft.com> Link: https://lore.kernel.org/lkml/d8bb1ec7-a4c5-43a2-9de0-9643a70b899f@linux.microsoft.com/ Fixes: b6cf8b3 ("printk: add lockless ringbuffer") Cc: stable@vger.kernel.org Signed-off-by: Kees Cook <keescook@chromium.org> Tested-by: Vijay Balakrishna <vijayb@linux.microsoft.com> Tested-by: Guilherme G. Piccoli <gpiccoli@igalia.com> # Steam Deck Reviewed-by: Tyler Hicks (Microsoft) <code@tyhicks.com> Tested-by: Tyler Hicks (Microsoft) <code@tyhicks.com> Reviewed-by: John Ogness <john.ogness@linutronix.de> Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org> Reviewed-by: Petr Mladek <pmladek@suse.com> Signed-off-by: Petr Mladek <pmladek@suse.com> Link: https://lore.kernel.org/r/20230811054528.never.165-kees@kernel.org (cherry picked from commit 53e9e33) Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
1 parent 2dde18c commit c09bf0d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/printk/printk_ringbuffer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,7 @@ static bool copy_data(struct prb_data_ring *data_ring,
17351735
if (!buf || !buf_size)
17361736
return true;
17371737

1738-
data_size = min_t(u16, buf_size, len);
1738+
data_size = min_t(unsigned int, buf_size, len);
17391739

17401740
memcpy(&buf[0], data, data_size); /* LMM(copy_data:A) */
17411741
return true;

0 commit comments

Comments
 (0)