FAILED: patch "[PATCH] mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once" failed to apply to 7.3-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 7.3-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-7.3.y
git checkout FETCH_HEAD
git cherry-pick -x af19aff38d6faea35b10f26cca32d0e54f8aea5e
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 7.3.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From af19aff38d6faea35b10f26cca32d0e54f8aea5e Mon Sep 17 00:00:00 2001
From: SJ Park <[email protected]>
Date: Mon, 14 Sep 2026 07:23:19 -0700
Subject: [PATCH] mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once
DAMON sysfs interface reads the user-provided size range arguments for hugepage_size type DAMOS filter twice. Once for validation, and once again for assignments to the variable that will be passed to the core layer. If the user updates the arguments in parallel, an invalid size range could be passed to the core layer. Avoid it by doing the assignments first, and then validating the assigned variables before passing those to the core layer.
User impact of the bug should be trivial. From the core layer's perspective, the invalid size range is not really invalid. It just works as having a weird size range. No critical issues such as a crash or a leak could happen. And sane users ain't do such parallel arguments update anyway. If they do, such racy behavior is arguably somewhat expected and deserved. That said, there is no reason to keep such races.
--- mm/damon/sysfs-schemes.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
mm/damon/sysfs-schemes.c +3 -4
@@ -2840,13 +2840,12 @@ static int damon_sysfs_add_scheme_filters(struct damos *scheme, }else if (filter->type ==DAMOS_FILTER_TYPE_TARGET ) { filter->target_idx = sysfs_filter->target_idx; }else if (filter->type ==DAMOS_FILTER_TYPE_HUGEPAGE_SIZE ) { -if (sysfs_filter->range_min > - sysfs_filter->range_max) { + filter->sz_range.min = sysfs_filter->range_min; + filter->sz_range.max = sysfs_filter->range_max; +if (filter->range_min > filter->range_max) {damos_destroy_filter (filter);return -EINVAL ; } - filter->sz_range.min = sysfs_filter->range_min; - filter->sz_range.max = sysfs_filter->range_max; }else if (filter->type ==DAMOS_FILTER_TYPE_PROBE_HITS_WSUM ) { filter->range_min = sysfs_filter->range_min; filter->range_max = sysfs_filter->range_max;
Signature · 1 line
2.53.0
SJ Park
maintainerPATCH 1/1 mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once
DAMON sysfs interface reads the user-provided size range arguments for hugepage_size type DAMOS filter twice. Once for validation, and once again for assignments to the variable that will be passed to the core layer. If the user updates the arguments in parallel, an invalid size range could be passed to the core layer. Avoid it by doing the assignments first, and then validating the assigned variables before passing those to the core layer.
User impact of the bug should be trivial. From the core layer's perspective, the invalid size range is not really invalid. It just works as having a weird size range. No critical issues such as a crash or a leak could happen. And sane users ain't do such parallel arguments update anyway. If they do, such racy behavior is arguably somewhat expected and deserved. That said, there is no reason to keep such races.
--- mm/damon/sysfs-schemes.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
mm/damon/sysfs-schemes.c +2 -3
@@ -2831,12 +2831,11 @@ static int damon_sysfs_add_scheme_filters(struct damos *scheme, }else if (filter->type ==DAMOS_FILTER_TYPE_TARGET ) { filter->target_idx = sysfs_filter->target_idx; }else if (filter->type ==DAMOS_FILTER_TYPE_HUGEPAGE_SIZE ) { -if (sysfs_filter->sz_range.min > - sysfs_filter->sz_range.max) { + filter->sz_range = sysfs_filter->sz_range; +if (filter->sz_range.min > filter->sz_range.max) {damos_destroy_filter (filter);return -EINVAL ; } - filter->sz_range = sysfs_filter->sz_range; }damos_add_filter (scheme, filter);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 7.3.y] mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once
Sashiko has reviewed this patch and found no issues.
Quoted 15 lines
DAMON sysfs interface reads the user-provided size range arguments for
hugepage_sizetype DAMOS filter twice. Once for validation, and once again for assignments to the variable that will be passed to the core layer. If the user updates the arguments in parallel, an invalid size range could be passed to the core layer. Avoid it by doing the assignments first, and then validating the assigned variables before passing those to the core layer.User impact of the bug should be trivial. From the core layer's perspective, the invalid size range is not really invalid. It just works as having a weird size range. No critical issues such as a crash or a leak could happen. And sane users ain't do such parallel arguments update anyway. If they do, such racy behavior is arguably somewhat expected and deserved. That said, there is no reason to keep such races.
Quoted 10 lines
Fixes ea1f204ba29a ("mm/damon/sysfs-schemes: add files for setting damos_filter->sz_range")Signed-off-by SJ Park <[email protected]>Signed-off-by Andrew Morton <[email protected]>Cc Brendan Higgins <[email protected]>Cc David Gow <[email protected]>Cc Usama Arif <[email protected]>Cc <[email protected]>(cherry picked from commit af19aff38d6faea35b10f26cca32d0e54f8aea5e)Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH 7.3.y] mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once
In reply to SJ ParkQuoted 1 line
mm/damon/sysfs-schemes: readsysfs_filter->sz_rangeonly once
Queued for 7.3, thanks.
Signature · 2 lines
Thanks, Sasha