Skip to content

Commit 7091fcc

Browse files
Dan Carpentergregkh
authored andcommitted
zram: off by one in read_block_state()
[ Upstream commit a88e03c ] 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 <dan.carpenter@oracle.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Sergey Senozhatsky <senozhatsky@chromium.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 64bde0c commit 7091fcc

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎drivers/block/zram/zram_drv.c‎

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

910-
if (count < copied) {
910+
if (count <= copied) {
911911
zram_slot_unlock(zram, index);
912912
break;
913913
}

0 commit comments

Comments
 (0)