]> git.dujemihanovic.xyz Git - linux.git/commitdiff
zram: off by one in read_block_state()
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 5 Nov 2021 20:45:12 +0000 (13:45 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 6 Nov 2021 20:30:43 +0000 (13:30 -0700)
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: c0265342bff4 ("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>
drivers/block/zram/zram_drv.c

index 081e77d595d78d3bc3112e6ec4ffc2e1c01db1d7..f61910c65f0f574a37c1c0d04c9afcb88cddcb00 100644 (file)
@@ -910,7 +910,7 @@ static ssize_t read_block_state(struct file *file, char __user *buf,
                        zram_test_flag(zram, index, ZRAM_HUGE) ? 'h' : '.',
                        zram_test_flag(zram, index, ZRAM_IDLE) ? 'i' : '.');
 
-               if (count < copied) {
+               if (count <= copied) {
                        zram_slot_unlock(zram, index);
                        break;
                }