public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] printk: ringbuffer: Fix truncating buffer size min_t cast
@ 2023-08-11  5:45 Kees Cook
  2023-08-11  6:16 ` Vijay Balakrishna
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Kees Cook @ 2023-08-11  5:45 UTC (permalink / raw)
  To: Petr Mladek
  Cc: Kees Cook, Sergey Senozhatsky, Steven Rostedt, John Ogness,
	Vijay Balakrishna, stable, Tony Luck, Guilherme G. Piccoli,
	Paul E. McKenney, linux-kernel, linux-hardening

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>
Closes: https://lore.kernel.org/lkml/d8bb1ec7-a4c5-43a2-9de0-9643a70b899f@linux.microsoft.com/
Fixes: b6cf8b3f3312 ("printk: add lockless ringbuffer")
Cc: stable@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 kernel/printk/printk_ringbuffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c
index 2dc4d5a1f1ff..fde338606ce8 100644
--- a/kernel/printk/printk_ringbuffer.c
+++ b/kernel/printk/printk_ringbuffer.c
@@ -1735,7 +1735,7 @@ static bool copy_data(struct prb_data_ring *data_ring,
 	if (!buf || !buf_size)
 		return true;
 
-	data_size = min_t(u16, buf_size, len);
+	data_size = min_t(unsigned int, buf_size, len);
 
 	memcpy(&buf[0], data, data_size); /* LMM(copy_data:A) */
 	return true;
-- 
2.34.1


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

end of thread, other threads:[~2023-08-14 13:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-11  5:45 [PATCH] printk: ringbuffer: Fix truncating buffer size min_t cast Kees Cook
2023-08-11  6:16 ` Vijay Balakrishna
2023-08-11 13:29 ` Guilherme G. Piccoli
2023-08-11 16:53 ` Tyler Hicks
2023-08-14  6:20 ` John Ogness
2023-08-14  7:40 ` Sergey Senozhatsky
2023-08-14 10:42 ` David Laight
2023-08-14 12:56   ` Petr Mladek
2023-08-14 13:33     ` David Laight
2023-08-14 11:40 ` Petr Mladek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox