Skip to content

Commit a88e03c

Browse files
Dan Carpentertorvalds
authored andcommitted
zram: off by one in read_block_state()
snprintf() returns the number of bytes it would have printed if there were space. But it does not count the NUL terminator. So that means that if "count == copied" then this has already overflowed by one character. This bug likely isn't super harmful in real life. Link: https://lkml.kernel.org/r/20210916130404.GA25094@kili Fixes: c026534 ("zram: introduce zram memory tracking") Signed-off-by: Dan Carpenter <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Sergey Senozhatsky <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 4aabdc1 commit a88e03c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/block/zram/zram_drv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ static ssize_t read_block_state(struct file *file, char __user *buf,
910910
zram_test_flag(zram, index, ZRAM_HUGE) ? 'h' : '.',
911911
zram_test_flag(zram, index, ZRAM_IDLE) ? 'i' : '.');
912912

913-
if (count < copied) {
913+
if (count <= copied) {
914914
zram_slot_unlock(zram, index);
915915
break;
916916
}

0 commit comments

Comments
 (0)