lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <tencent_C9BC3F2FE38BB1EBA44887FB683CD195E705@qq.com>
Date: Wed, 19 Nov 2025 12:01:57 +0800
From: Yuwen Chen <ywen.chen@...mail.com>
To: akpm@...ux-foundation.org,
	senozhatsky@...omium.org,
	minchan@...nel.org
Cc: bgeffon@...gle.com,
	licayy@...look.com,
	linux-block@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	linux-mm@...ck.org,
	richardycc@...gle.com,
	ywen.chen@...mail.com
Subject: [PATCH v3] zram: Fix the issue that the write - back limits might overflow

When the page size exceeds 4KB, if bd_wb_limit is set to a value
that is not aligned with the page size, it will cause a numerical
wrap-around issue for bd_wb_limit. For example, when the page
size is set to 16KB and bd_wb_limit is set to 3, after one
write-back operation, the value of bd_wb_limit will become -1.
More seriously, since bd_wb_limit is an unsigned number, its
value may become as large as 2^64 - 1.

The core reason for this problem is that the unit of bd_wb_limit
is 4KB. For example, when a write-back occurs on a system with a
page size of 16KB, 4 needs to be subtracted from bd_wb_limit.
This operation takes place in the zram_account_writeback_submit
function.

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@...mail.com>
---
Changes in v3:
  - Simplify the code using rounddown.
Changes in v2:
  - Rebase the patch to adapt to the latest version.

 drivers/block/zram/zram_drv.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 8a13729..681f4ff 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -579,6 +579,16 @@ static ssize_t writeback_limit_store(struct device *dev,
 	if (kstrtoull(buf, 10, &val))
 		return ret;
 
+	/*
+         * When the page size is greater than 4KB, if bd_wb_limit is set to
+         * a value that is not page - size aligned, it will cause value
+         * wrapping. For example, when the page size is set to 16KB and
+         * bd_wb_limit is set to 3, a single write - back operation will
+         * cause bd_wb_limit to become -1. Even more terrifying is that
+         * bd_wb_limit is an unsigned number.
+         */
+	val = rounddown(val, PAGE_SIZE / 4096);
+
 	down_write(&zram->init_lock);
 	zram->bd_wb_limit = val;
 	up_write(&zram->init_lock);
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ