]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
printk_ringbuffer: Add sanity check for 0-size data
authorJohn Ogness <john.ogness@linutronix.de>
Thu, 26 Mar 2026 13:38:02 +0000 (14:44 +0106)
committerPetr Mladek <pmladek@suse.com>
Fri, 27 Mar 2026 16:12:37 +0000 (17:12 +0100)
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@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Tested-by: Petr Mladek <pmladek@suse.com>
Link: https://patch.msgid.link/20260326133809.8045-2-john.ogness@linutronix.de
Signed-off-by: Petr Mladek <pmladek@suse.com>
kernel/printk/printk_ringbuffer.c

index a3526bdd4e10d413d77bdedb2c27b2a0c017f6ad..aa4b39e94cfa2a8a38be00c6de2f319784f15795 100644 (file)
@@ -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. */