All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev, SJ Park <sj@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 7.3 02/38] mm/damon/core: error damos_commit_quota_goal() for zero target_value
Date: Wed, 28 Oct 2026 17:59:49 +0100	[thread overview]
Message-ID: <20261028165940.465084933@linuxfoundation.org> (raw)
In-Reply-To: <20261028165940.394092994@linuxfoundation.org>

7.3-stable review patch.  If anyone has any objections, please let me know.

------------------

From: SJ Park <sj@kernel.org>

[ Upstream commit 610c4438fb66e06d9e693c0ad3b2c1be54c0d61f ]

Patch series "mm/damon: move zero damos quota target_value handling to the
core layer".

Having zero DAMOS quota target value can cause division by zero.  DAMON
API callers are checking the target value parameters to avoid that.  It is
easy to make mistakes in some of the multiple API callers.  Move that to
the core layer.

Patch 1 adds the corner case handling into the core layer DAMON parameters
validation logic.  Patches 2 and 3 remove no more needed DAMON API callers
side handling of the corner case in DAMON_LRU_SORT and DMON_SAMPLIE_MTIER,
respectively.

This patch (of 3):

If a DAMOS scheme has a damos_quota_goal of zero target_value,
damos_quota_goal() could trigger division-by-zero error.  Hence each DAMON
API callers should do the zero target_value validation.  It is easy to
make mistakes.  Actually such bugs in DAMON_LRU_SORT and
DAMON_SAMPLE_MTIER were found and fixed [1].

It is better to handle the corner case only once in the core layer,
instead of multiple places in all DAMON API callers.  One straightforward
option is using an alternative denominator for the corner case in the
damos_quota_goal().  However, the zero target_value is meaningless.  In
this case, the quota goal is always evaluated as achieved or
over-achieved.  The quota will only keep being reduced.

Simply avoid using zero target_value by adding a check in the core layer
DAMOS quota goal parameters validation/commit path,
damos_commit_quota_goal().  Update it to return an error in the case.
Also update its caller to propagate the error.

Notes for stable kernel porting.  The upstream commit doesn't have
Fixes: and therefore not ported to stable kernels.  It turned out it
fixes commit 8b549a4fd3c5 ("mm/damon/sysfs-schemes: commit damos quota
goals user input to DAMOS") which was merged into v6.8.  The user impact
is a race condition that can result in divide-by-zero.  Hence backport.
Reproducing the issue requires sysfs write permission, certain DAMON ABI
usages that are supposed to be uncommon, and a rare race timing, though.
The issue was discovered [2] by Sashiko as a part [3] of its bug report.

[2] https://sashiko.dev/#/bug/linux-7f814c9a-986f-4103-a55a-ef9537dcf62b
[3] https://lore.kernel.org/20261021005234.94107-1-sj@kernel.org

Link: https://lore.kernel.org/20260903010722.94244-1-sj@kernel.org
Link: https://lore.kernel.org/20260903010722.94244-2-sj@kernel.org
Link: https://lore.kernel.org/20260803134034.15217-1-sj@kernel.org [1]
Signed-off-by: SJ Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: SJ Park <sj@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 mm/damon/core.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index ab3c4d7549644..74d22a596fc13 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1136,15 +1136,18 @@ static void damos_commit_quota_goal_union(
 	}
 }
 
-static void damos_commit_quota_goal(
+static int damos_commit_quota_goal(
 		struct damos_quota_goal *dst, struct damos_quota_goal *src)
 {
+	if (!src->target_value)
+		return  -EINVAL;
 	dst->metric = src->metric;
 	dst->target_value = src->target_value;
 	if (dst->metric == DAMOS_QUOTA_USER_INPUT)
 		dst->current_value = src->current_value;
 	/* keep last_psi_total as is, since it will be updated in next cycle */
 	damos_commit_quota_goal_union(dst, src);
+	return 0;
 }
 
 /**
@@ -1162,14 +1165,17 @@ static void damos_commit_quota_goal(
 int damos_commit_quota_goals(struct damos_quota *dst, struct damos_quota *src)
 {
 	struct damos_quota_goal *dst_goal, *next, *src_goal, *new_goal;
-	int i = 0, j = 0;
+	int i = 0, j = 0, err;
 
 	damos_for_each_quota_goal_safe(dst_goal, next, dst) {
 		src_goal = damos_nth_quota_goal(i++, src);
-		if (src_goal)
-			damos_commit_quota_goal(dst_goal, src_goal);
-		else
+		if (src_goal) {
+			err = damos_commit_quota_goal(dst_goal, src_goal);
+			if (err)
+				return err;
+		} else {
 			damos_destroy_quota_goal(dst_goal);
+		}
 	}
 	damos_for_each_quota_goal_safe(src_goal, next, src) {
 		if (j++ < i)
@@ -1178,7 +1184,11 @@ int damos_commit_quota_goals(struct damos_quota *dst, struct damos_quota *src)
 				src_goal->metric, src_goal->target_value);
 		if (!new_goal)
 			return -ENOMEM;
-		damos_commit_quota_goal(new_goal, src_goal);
+		err = damos_commit_quota_goal(new_goal, src_goal);
+		if (err) {
+			damos_free_quota_goal(new_goal);
+			return err;
+		}
 		damos_add_quota_goal(dst, new_goal);
 	}
 	return 0;
-- 
2.53.0




  parent reply	other threads:[~2026-10-28 17:04 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 16:59 [PATCH 7.3 00/38] 7.3.1-rc1 review Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 01/38] genirq/proc: Fix missing CPU header in /proc/interrupts Greg Kroah-Hartman
2026-10-28 16:59 ` Greg Kroah-Hartman [this message]
2026-10-28 16:59 ` [PATCH 7.3 03/38] Bluetooth: L2CAP: refuse __l2cap_chan_add if chan already has conn Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 04/38] tools/dma: fix building with O= Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 05/38] tracing: Hold trace_types_lock when updating modules in persistent instances Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 06/38] tracing: Hold trace_types_lock when resetting last boot data from readers Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 07/38] tracing: Reject incomplete event filter expressions Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 08/38] tracing: Save the event file instead of the compatible histogram Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 09/38] tracing: Unregister field variable histograms when the command fails Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 10/38] tracing: Add the bucket size to expr_field_str() Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 11/38] tracing: Fix 64-bit and signed histogram fields on 32-bit kernels Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 12/38] tracing/histograms: Verify event_call identity when updating synth_event refcount Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 13/38] tracing/syscalls: Use copy_from_user for the faultable syscall buffer Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 14/38] io_uring/poll: avoid retry wakeup loss when dropping ownership Greg Kroah-Hartman
2026-10-29  7:53   ` Jiri Slaby
2026-10-29  9:07     ` Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 15/38] io_uring/wait: wake real-time waiters from hard interrupt context Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 16/38] io_uring/net: keep recv buffer select length within MAX_RW_COUNT Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 17/38] io_uring/waitid: prevent cancel reference wrap Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 18/38] io_uring: end the drain when the drain request completes Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 19/38] keys: Avoid the owner account dereference in named keyring lookup Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 20/38] keys: Check the authorization payload in process keyring searches Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 21/38] keys: Protect the type name while describing a key Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 22/38] keys: make keyring indexes independent of kernel addresses Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 23/38] keys: Protect the read method check against type removal Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 24/38] KEYS: Fix key_reject_and_link() race with keyring restriction Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 25/38] KEYS: trusted: Fix blob allocation size in tpm2_key_decode() Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 26/38] keys/trusted_keys: return immediately after TPM unseal failure Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 27/38] asymmetric_keys: reject trust keys without IDs Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 28/38] ftrace: Initialize modname and offset in print_rec() Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 29/38] coredump: hold RCU while releasing parked threads Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 30/38] signal: only SIGKILL and the freezers interrupt a coredumping task Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 31/38] io-wq: order the exit bit against worker creation task work Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 32/38] signal: dont retarget shared signals in a dying thread group Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 33/38] ptrace: refuse to change the signal mask of a user worker Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 34/38] fork: release the files of a failed fork after sched_cancel_fork() Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 35/38] exit: hang up the tty before closing the files Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 36/38] coredump: prevent TIF_NOTIFY_SIGNAL from interrupting coredumps Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 37/38] pid_namespace: prevent TIF_NOTIFY_SIGNAL from interrupting the reaper Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 38/38] signal: allow taks to temporarily block TIF_NOTIFY_SIGNAL Greg Kroah-Hartman
2026-10-28 18:08 ` [PATCH 7.3 00/38] 7.3.1-rc1 review Ronald Warsow
2026-10-28 19:40 ` Brett A C Sheffield
2026-10-29  4:01 ` Takeshi Ogasawara
2026-10-29  5:00 ` Peter Schneider
2026-10-29 12:06 ` Barry K. Nathan
2026-10-29 13:53 ` Miguel Ojeda
2026-10-29 14:12 ` Ron Economos
2026-10-29 14:42 ` SJ Park
2026-10-29 15:17 ` Shuah Khan
2026-10-29 17:48 ` Florian Fainelli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261028165940.465084933@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=patches@lists.linux.dev \
    --cc=sashal@kernel.org \
    --cc=sj@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.