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: <20251020112824.144391-1-swarajgaikwad1925@gmail.com>
Date: Mon, 20 Oct 2025 11:28:24 +0000
From: Swaraj Gaikwad <swarajgaikwad1925@...il.com>
To: SeongJae Park <sj@...nel.org>,
	Andrew Morton <akpm@...ux-foundation.org>,
	damon@...ts.linux.dev (open list:DAMON),
	linux-mm@...ck.org (open list:DAMON),
	linux-kernel@...r.kernel.org (open list)
Cc: skhan@...uxfoundation.org,
	david.hunter.linux@...il.com,
	Swaraj Gaikwad <swarajgaikwad1925@...il.com>
Subject: [PATCH] mm/damon/sysfs-schemes: Validate nid usage in nid_show()

The nid_show() function previously returned the node ID (nid) without
verifying if the goal object of damos_sysfs_quota_goal was using a
node-based metric. This could lead to incorrect reporting when the
goal metric was unrelated to node memory.

This patch introduces a validation step to ensure that nid_show() only
returns the node ID for valid node-based metrics:
- DAMOS_QUOTA_NODE_MEM_USED_BP
- DAMOS_QUOTA_NODE_MEM_FREE_BP

For other metrics, it returns -EINVAL to prevent misleading information.

Tested with KUnit:
- Built kernel with KUnit and DAMON sysfs tests enabled.
- Executed KUnit tests:
  ./kunit.py run --kunitconfig ./mm/mm/damon/tests/.kunitconfig
- All 25 tests passed, including damon_sysfs_test_add_targets.

Based on commit 3a8660878839 ("Linux 6.18-rc1").

Signed-off-by: Swaraj Gaikwad <swarajgaikwad1925@...il.com>
---
 mm/damon/sysfs-schemes.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 6536f16006c9..23a73b94fe53 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -1112,7 +1112,16 @@ static ssize_t nid_show(struct kobject *kobj,
 	struct damos_sysfs_quota_goal *goal = container_of(kobj, struct
 			damos_sysfs_quota_goal, kobj);
 
-	/* todo: return error if the goal is not using nid */
+	switch (goal->metric) {
+		case DAMOS_QUOTA_USER_INPUT:
+		case DAMOS_QUOTA_SOME_MEM_PSI_US:
+			return -EINVAL;
+		case DAMOS_QUOTA_NODE_MEM_USED_BP:
+		case DAMOS_QUOTA_NODE_MEM_FREE_BP:
+			break;
+		default:
+			return -EINVAL;
+	}
 
 	return sysfs_emit(buf, "%d\n", goal->nid);
 }
-- 
2.51.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ