linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] zram: Fix the issue that the write - back limits might overflow
@ 2025-11-18  8:15 Yuwen Chen
  2025-11-18 17:58 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Yuwen Chen @ 2025-11-18  8:15 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>
---
Changes in v2:
  - Rebase the patch to adapt to the latest version.

 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 8a13729..5780604 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -579,6 +579,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_write(&zram->init_lock);
 	zram->bd_wb_limit = val;
 	up_write(&zram->init_lock);
-- 
2.34.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] zram: Fix the issue that the write - back limits might overflow
  2025-11-18  8:15 [PATCH v2] zram: Fix the issue that the write - back limits might overflow Yuwen Chen
@ 2025-11-18 17:58 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2025-11-18 17:58 UTC (permalink / raw)
  To: Yuwen Chen
  Cc: senozhatsky, bgeffon, licayy, linux-block, linux-kernel,
	linux-mm, minchan, richardycc

On Tue, 18 Nov 2025 16:15:50 +0800 Yuwen Chen <ywen.chen@foxmail.com> 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.

Please update the changelog to fully describe this out-of-bounds
situation.  Where does it occur, why, how, with what effects?

> This patch fixes the issue by limiting bd_wb_limit to be an
> integer multiple of PAGE_SIZE / 4096.

I don't see at all how clearing the lower 11 bits is related to "page
size is larger than 4 KB".

All quite confusing!

> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -579,6 +579,7 @@ static ssize_t writeback_limit_store(struct device *dev,
>  	if (kstrtoull(buf, 10, &val))
>  		return ret;
>  
> +	val = val & (~((1UL << (PAGE_SHIFT - 12)) - 1));

Needs a little comment, I suggest.

>  	down_write(&zram->init_lock);
>  	zram->bd_wb_limit = val;
>  	up_write(&zram->init_lock);
> -- 
> 2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-18 17:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-18  8:15 [PATCH v2] zram: Fix the issue that the write - back limits might overflow Yuwen Chen
2025-11-18 17:58 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox