From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,ziy@nvidia.com,zhen.ni@easystack.cn,ye.liu@linux.dev,vishal.moola@gmail.com,chenyichong@uniontech.com,akpm@linux-foundation.org
Subject: [merged mm-stable] tools-mm-page_owner_sort-bound-pattern-output-copies.patch removed from -mm tree
Date: Thu, 30 Jul 2026 19:44:00 -0700 [thread overview]
Message-ID: <20260731024401.3D1CD1F000E9@smtp.kernel.org> (raw)
The quilt patch titled
Subject: tools/mm/page_owner_sort: bound pattern output copies
has been removed from the -mm tree. Its filename was
tools-mm-page_owner_sort-bound-pattern-output-copies.patch
This patch was dropped because it was merged into the mm-stable branch
of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Yichong Chen <chenyichong@uniontech.com>
Subject: tools/mm/page_owner_sort: bound pattern output copies
Date: Mon, 29 Jun 2026 09:43:16 +0800
search_pattern() copies a regex capture into caller-provided buffers
without knowing their sizes. Several callers pass fixed-size buffers,
including FIELD_BUFF and TASK_COMM_LEN.
Pass the destination size to search_pattern(), reject captures that do not
fit before copying them, and terminate the output string inside
search_pattern().
Link: https://lore.kernel.org/20260629014316.130307-4-chenyichong@uniontech.com
Signed-off-by: Yichong Chen <chenyichong@uniontech.com>
Cc: Vishal Moola <vishal.moola@gmail.com>
Cc: Ye Liu <ye.liu@linux.dev>
Cc: Zhen Ni <zhen.ni@easystack.cn>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
tools/mm/page_owner_sort.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
--- a/tools/mm/page_owner_sort.c~tools-mm-page_owner_sort-bound-pattern-output-copies
+++ a/tools/mm/page_owner_sort.c
@@ -237,7 +237,8 @@ static int remove_pattern(regex_t *patte
return len - (pmatch[1].rm_eo - pmatch[1].rm_so);
}
-static int search_pattern(regex_t *pattern, char *pattern_str, char *buf)
+static int search_pattern(regex_t *pattern, char *pattern_str,
+ size_t pattern_str_size, char *buf)
{
int err, val_len;
regmatch_t pmatch[2];
@@ -249,8 +250,14 @@ static int search_pattern(regex_t *patte
return -1;
}
val_len = pmatch[1].rm_eo - pmatch[1].rm_so;
+ if ((size_t)val_len >= pattern_str_size) {
+ if (debug_on)
+ fprintf(stderr, "pattern too long in %s\n", buf);
+ return -1;
+ }
memcpy(pattern_str, buf + pmatch[1].rm_so, val_len);
+ pattern_str[val_len] = '\0';
return 0;
}
@@ -307,7 +314,8 @@ static int get_page_num(char *buf)
char order_str[FIELD_BUFF] = {0};
char *endptr;
- search_pattern(&order_pattern, order_str, buf);
+ if (search_pattern(&order_pattern, order_str, sizeof(order_str), buf) < 0)
+ return 0;
errno = 0;
order_val = strtol(order_str, &endptr, 10);
if (order_val > 64 || errno != 0 || endptr == order_str || *endptr != '\0') {
@@ -325,7 +333,8 @@ static pid_t get_pid(char *buf)
char pid_str[FIELD_BUFF] = {0};
char *endptr;
- search_pattern(&pid_pattern, pid_str, buf);
+ if (search_pattern(&pid_pattern, pid_str, sizeof(pid_str), buf) < 0)
+ return -1;
errno = 0;
pid = strtol(pid_str, &endptr, 10);
if (errno != 0 || endptr == pid_str || *endptr != '\0') {
@@ -344,7 +353,8 @@ static pid_t get_tgid(char *buf)
char tgid_str[FIELD_BUFF] = {0};
char *endptr;
- search_pattern(&tgid_pattern, tgid_str, buf);
+ if (search_pattern(&tgid_pattern, tgid_str, sizeof(tgid_str), buf) < 0)
+ return -1;
errno = 0;
tgid = strtol(tgid_str, &endptr, 10);
if (errno != 0 || endptr == tgid_str || *endptr != '\0') {
@@ -363,7 +373,9 @@ static __u64 get_ts_nsec(char *buf)
char ts_nsec_str[FIELD_BUFF] = {0};
char *endptr;
- search_pattern(&ts_nsec_pattern, ts_nsec_str, buf);
+ if (search_pattern(&ts_nsec_pattern, ts_nsec_str,
+ sizeof(ts_nsec_str), buf) < 0)
+ return -1;
errno = 0;
ts_nsec = strtoull(ts_nsec_str, &endptr, 10);
if (errno != 0 || endptr == ts_nsec_str || *endptr != '\0') {
@@ -384,7 +396,10 @@ static char *get_comm(char *buf)
memset(comm_str, 0, TASK_COMM_LEN);
- search_pattern(&comm_pattern, comm_str, buf);
+ if (search_pattern(&comm_pattern, comm_str, TASK_COMM_LEN, buf) < 0) {
+ free(comm_str);
+ return NULL;
+ }
errno = 0;
if (errno != 0) {
if (debug_on)
_
Patches currently in -mm which might be from chenyichong@uniontech.com are
hugetlbfs-release-subpool-on-fill_super-failure.patch
hugetlb-make-hugepage_put_subpool-tolerate-null.patch
hugetlb-evaluate-subpool-free-state-while-locked.patch
fat-release-buffer-head-after-rebuilding-parent.patch
reply other threads:[~2026-07-31 2:44 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260731024401.3D1CD1F000E9@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=chenyichong@uniontech.com \
--cc=mm-commits@vger.kernel.org \
--cc=vishal.moola@gmail.com \
--cc=ye.liu@linux.dev \
--cc=zhen.ni@easystack.cn \
--cc=ziy@nvidia.com \
/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.