Skip to content

Commit 407f666

Browse files
jognesspmladek
authored andcommitted
printk_ringbuffer: Add sanity check for 0-size data
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 <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Tested-by: Petr Mladek <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Petr Mladek <[email protected]>
1 parent 8e81ecb commit 407f666

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

kernel/printk/printk_ringbuffer.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,8 +1308,11 @@ static const char *get_data(struct prb_data_ring *data_ring,
13081308
return NULL;
13091309
}
13101310

1311-
/* A valid data block will always have at least an ID. */
1312-
if (WARN_ON_ONCE(*data_size < sizeof(db->id)))
1311+
/*
1312+
* A regular data block will always have an ID and at least
1313+
* 1 byte of data. Data-less blocks were handled earlier.
1314+
*/
1315+
if (WARN_ON_ONCE(*data_size <= sizeof(db->id)))
13131316
return NULL;
13141317

13151318
/* Subtract block ID space from size to reflect data size. */

0 commit comments

Comments
 (0)