Skip to content

Commit 53e9e33

Browse files
keespmladek
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 <[email protected]> Cc: Sergey Senozhatsky <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: John Ogness <[email protected]> Reported-by: Vijay Balakrishna <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Fixes: b6cf8b3 ("printk: add lockless ringbuffer") Cc: [email protected] Signed-off-by: Kees Cook <[email protected]> Tested-by: Vijay Balakrishna <[email protected]> Tested-by: Guilherme G. Piccoli <[email protected]> # Steam Deck Reviewed-by: Tyler Hicks (Microsoft) <[email protected]> Tested-by: Tyler Hicks (Microsoft) <[email protected]> Reviewed-by: John Ogness <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Signed-off-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent cd47fe8 commit 53e9e33

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/printk/printk_ringbuffer.c

Lines changed: 1 addition & 1 deletion
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)