From: sashiko-bot@kernel.org
To: "Weilin Tong" <tongweilin@linux.alibaba.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Ryan Roberts" <ryan.roberts@arm.com>
Cc: "David Hildenbrand" <david@kernel.org>,
"Baolin Wang" <baolin.wang@linux.alibaba.com>,
linux-mm@kvack.org
Subject: Re: [PATCH] tools/mm/thpmaps: handle carriage returns and non-UTF-8 filenames
Date: Tue, 03 Nov 2026 08:54:44 +0000 [thread overview]
Message-ID: <sashiko-outbox-194896@kernel.org> (raw)
In-Reply-To: <20261102085419.696232-1-tongweilin@linux.alibaba.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] tools/mm/thpmaps: UnicodeEncodeError in vma_print() on non-UTF-8 filenames
--
commit 5f793a93e6fde4bbef2fd7ad6b6bda119aa8b288
Author: Weilin Tong <tongweilin@linux.alibaba.com>
tools/mm/thpmaps: handle carriage returns and non-UTF-8 filenames
This commit updates VMAList.__init__() in tools/mm/thpmaps to open
/proc/<pid>/smaps with newline='\n' and errors='surrogateescape' so that
carriage returns in mapped filenames do not split header lines and
non-UTF-8 bytes do not raise UnicodeDecodeError while reading.
Link: https://lore.kernel.org/linux-mm/20261101211644.c63a2028bbede0f763f41f80@linux-foundation.org/
> diff --git a/tools/mm/thpmaps b/tools/mm/thpmaps
> index a1a9bc30514f3..f89568bd499ec 100644
> --- a/tools/mm/thpmaps
> +++ b/tools/mm/thpmaps
> @@ -196,7 +196,8 @@ class VMAList:
> # instance to receive VMAs.
> def __init__(self, pid='self', stats=[]):
> self.vmas = []
> - with open(f'/proc/{pid}/smaps', 'r') as file:
> + with open(f'/proc/{pid}/smaps', 'r', newline='\n',
> + errors='surrogateescape') as file:
[Severity: Medium]
When VMAList.__init__() opens /proc/<pid>/smaps with
errors='surrogateescape', non-UTF-8 bytes in a mapped filename are decoded
into lone surrogate code points in vma.name.
In default (non-rollup) mode, do_main() passes each VMA to vma_print():
tools/mm/thpmaps:do_main() {
...
if args.rollup:
...
else:
vma_print(vma, pid)
stats_print(stats, vma_anon, vma_file, args.inc_empty)
except (FileNotFoundError, ProcessLookupError, FileIOException):
...
}
And vma_print() writes vma.name directly to sys.stdout via print():
tools/mm/thpmaps:vma_print() {
print("{:010d}: {:016x}-{:016x} {}{}{}{} {:08x} {:02x}:{:02x} {:08x} {}"
.format(
pid, vma.start, vma.end,
'r' if vma.read else '-', 'w' if vma.write else '-',
'x' if vma.execute else '-', 'p' if vma.private else 's',
vma.pgoff, vma.major, vma.minor, vma.inode, vma.name
))
}
Under standard UTF-8 locales, sys.stdout uses errors='strict' by default,
which rejects lone surrogates. Doesn't printing a VMA with non-UTF-8
filename bytes in vma_print() still terminate the script with an uncaught
UnicodeEncodeError unless sys.stdout is also reconfigured (for example with
errors='surrogateescape' or errors='backslashreplace') or vma.name is
sanitized before printing?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261102085419.696232-1-tongweilin@linux.alibaba.com?part=1
next prev parent reply other threads:[~2026-11-03 8:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 7:49 [PATCH 0/3] tools/mm/thpmaps: fix THP statistics and mapping names Weilin Tong
2026-10-27 7:49 ` [PATCH 1/3] tools/mm/thpmaps: fix partial THP anon/file accounting Weilin Tong
2026-10-27 7:49 ` [PATCH 2/3] tools/mm/thpmaps: fix missing order-1 file THP statistics Weilin Tong
2026-11-02 12:51 ` David Hildenbrand (Arm)
2026-10-27 7:49 ` [PATCH 3/3] tools/mm/thpmaps: fix missing mapping names Weilin Tong
2026-11-02 5:16 ` Andrew Morton
2026-11-02 8:54 ` [PATCH] tools/mm/thpmaps: handle carriage returns and non-UTF-8 filenames Weilin Tong
2026-11-03 8:54 ` sashiko-bot [this message]
2026-11-03 9:24 ` Weilin Tong
2026-11-02 12:53 ` [PATCH 3/3] tools/mm/thpmaps: fix missing mapping names David Hildenbrand (Arm)
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=sashiko-outbox-194896@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@kernel.org \
--cc=linux-mm@kvack.org \
--cc=ryan.roberts@arm.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tongweilin@linux.alibaba.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox