diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2021-11-05 23:45:12 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2021-11-26 13:36:16 +0300 |
commit | 26df52b3e8168a736b6f463b2f6f46c93c4e0c1a (patch) | |
tree | 58152bf8a6716722690fdb2ea0e0ac93f6eb2b4a | |
parent | b19675b6a046da6b4e160a78eedb3dd2584aa889 (diff) | |
download | linux-26df52b3e8168a736b6f463b2f6f46c93c4e0c1a.tar.xz |
zram: off by one in read_block_state()
[ Upstream commit a88e03cf3d190cf46bc4063a9b7efe87590de5f4 ]
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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r-- | drivers/block/zram/zram_drv.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 104206a79501..5e05bfcecd7b 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -699,7 +699,7 @@ static ssize_t read_block_state(struct file *file, char __user *buf, zram_test_flag(zram, index, ZRAM_WB) ? 'w' : '.', zram_test_flag(zram, index, ZRAM_HUGE) ? 'h' : '.'); - if (count < copied) { + if (count <= copied) { zram_slot_unlock(zram, index); break; } |