[PATCH printk v2 2/2] printk_ringbuffer: Add sanity check for 0-size data
From: John Ogness
Date: Thu Mar 26 2026 - 09:45:54 EST
get_data() has a sanity check for regular data blocks to ensure at
least space for the ID exists. But a regular block should also have
at least 1 byte of data (otherwise it would be data-less instead of
regular).
Expand the get_data() block size sanity check to additionally expect
at least 1 byte of data.
Signed-off-by: John Ogness <john.ogness@xxxxxxxxxxxxx>
---
kernel/printk/printk_ringbuffer.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c
index a3526bdd4e10d..aa4b39e94cfa2 100644
--- a/kernel/printk/printk_ringbuffer.c
+++ b/kernel/printk/printk_ringbuffer.c
@@ -1308,8 +1308,11 @@ static const char *get_data(struct prb_data_ring *data_ring,
return NULL;
}
- /* A valid data block will always have at least an ID. */
- if (WARN_ON_ONCE(*data_size < sizeof(db->id)))
+ /*
+ * A regular data block will always have an ID and at least
+ * 1 byte of data. Data-less blocks were handled earlier.
+ */
+ if (WARN_ON_ONCE(*data_size <= sizeof(db->id)))
return NULL;
/* Subtract block ID space from size to reflect data size. */
--
2.47.3