* [PATCH] zram: Fix the issue that the write - back limits might overflow
@ 2025-11-18 7:39 Yuwen Chen
2025-11-18 7:49 ` Sergey Senozhatsky
2025-11-18 7:52 ` Sergey Senozhatsky
0 siblings, 2 replies; 4+ messages in thread
From: Yuwen Chen @ 2025-11-18 7:39 UTC (permalink / raw)
To: senozhatsky
Cc: akpm, bgeffon, licayy, linux-block, linux-kernel, linux-mm,
minchan, richardycc, ywen.chen
Since the value of bd_wb_limit is an unsigned number, when the
page size is larger than 4 KB, it may cause an out-of-bounds situation.
This patch fixes the issue by limiting bd_wb_limit to be an
integer multiple of PAGE_SIZE / 4096.
Fixes: 1d69a3f8ae77e ("zram: idle writeback fixes and cleanup")
Signed-off-by: Yuwen Chen <ywen.chen@foxmail.com>
---
drivers/block/zram/zram_drv.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 4f2824a..4ecf2e7 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -562,6 +562,7 @@ static ssize_t writeback_limit_store(struct device *dev,
if (kstrtoull(buf, 10, &val))
return ret;
+ val = val & (~((1UL << (PAGE_SHIFT - 12)) - 1));
down_read(&zram->init_lock);
spin_lock(&zram->wb_limit_lock);
zram->bd_wb_limit = val;
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] zram: Fix the issue that the write - back limits might overflow
2025-11-18 7:39 [PATCH] zram: Fix the issue that the write - back limits might overflow Yuwen Chen
@ 2025-11-18 7:49 ` Sergey Senozhatsky
2025-11-18 7:52 ` Sergey Senozhatsky
1 sibling, 0 replies; 4+ messages in thread
From: Sergey Senozhatsky @ 2025-11-18 7:49 UTC (permalink / raw)
To: Yuwen Chen
Cc: senozhatsky, akpm, bgeffon, licayy, linux-block, linux-kernel,
linux-mm, minchan, richardycc
On (25/11/18 15:39), Yuwen Chen wrote:
> Since the value of bd_wb_limit is an unsigned number, when the
> page size is larger than 4 KB, it may cause an out-of-bounds situation.
>
> This patch fixes the issue by limiting bd_wb_limit to be an
> integer multiple of PAGE_SIZE / 4096.
>
> Fixes: 1d69a3f8ae77e ("zram: idle writeback fixes and cleanup")
> Signed-off-by: Yuwen Chen <ywen.chen@foxmail.com>
> ---
> drivers/block/zram/zram_drv.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 4f2824a..4ecf2e7 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -562,6 +562,7 @@ static ssize_t writeback_limit_store(struct device *dev,
> if (kstrtoull(buf, 10, &val))
> return ret;
>
> + val = val & (~((1UL << (PAGE_SHIFT - 12)) - 1));
> down_read(&zram->init_lock);
> spin_lock(&zram->wb_limit_lock);
> zram->bd_wb_limit = val;
This patch is against unfixed writeback_limit_store() function,
it will need to be resubmitted once [1] lands.
[1] https://lore.kernel.org/linux-mm/20251118073000.1928107-1-senozhatsky@chromium.org
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] zram: Fix the issue that the write - back limits might overflow
2025-11-18 7:39 [PATCH] zram: Fix the issue that the write - back limits might overflow Yuwen Chen
2025-11-18 7:49 ` Sergey Senozhatsky
@ 2025-11-18 7:52 ` Sergey Senozhatsky
2025-11-18 8:21 ` Yuwen Chen
1 sibling, 1 reply; 4+ messages in thread
From: Sergey Senozhatsky @ 2025-11-18 7:52 UTC (permalink / raw)
To: Yuwen Chen
Cc: senozhatsky, akpm, bgeffon, licayy, linux-block, linux-kernel,
linux-mm, minchan, richardycc
On (25/11/18 15:39), Yuwen Chen wrote:
> Since the value of bd_wb_limit is an unsigned number, when the
> page size is larger than 4 KB, it may cause an out-of-bounds situation.
>
> This patch fixes the issue by limiting bd_wb_limit to be an
> integer multiple of PAGE_SIZE / 4096.
I really wish we could just change wb code to use PAGE_SIZE not 4K
units [1], unfortunately it's probably too late to change that now.
[1] https://lore.kernel.org/linux-kernel/20251110052741.92031-1-senozhatsky@chromium.org
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] zram: Fix the issue that the write - back limits might overflow
2025-11-18 7:52 ` Sergey Senozhatsky
@ 2025-11-18 8:21 ` Yuwen Chen
0 siblings, 0 replies; 4+ messages in thread
From: Yuwen Chen @ 2025-11-18 8:21 UTC (permalink / raw)
To: senozhatsky
Cc: akpm, bgeffon, licayy, linux-block, linux-kernel, linux-mm,
minchan, richardycc, ywen.chen
On (25/11/18 15:39), Sergey Senozhatsky wrote:
> I really wish we could just change wb code to use PAGE_SIZE not 4K
> units [1], unfortunately it's probably too late to change that now.
>
> [1] https://lore.kernel.org/linux-kernel/20251110052741.92031-1-senozhatsky@chromium.org
I've taken a look at the patch you submitted before. This is indeed
a very frustrating thing. I'm not sure if we can make the change. If
we can change it to use PAGE_SIZE, it will reduce a lot of unnecessary
logic.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-11-18 8:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-18 7:39 [PATCH] zram: Fix the issue that the write - back limits might overflow Yuwen Chen
2025-11-18 7:49 ` Sergey Senozhatsky
2025-11-18 7:52 ` Sergey Senozhatsky
2025-11-18 8:21 ` Yuwen Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox