From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Anshuman Tewari <anshumantewari123@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Lorenzo Stoakes <ljs@kernel.org>, Shuah Khan <shuah@kernel.org>,
Zi Yan <ziy@nvidia.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
"Liam R . Howlett" <liam@infradead.org>,
Nico Pache <nico.pache@linux.dev>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
Usama Arif <usama.arif@linux.dev>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selftests/mm: check strdup() and fix buf leak in parse_test_type()
Date: Fri, 21 Aug 2026 18:18:37 +0200 [thread overview]
Message-ID: <e7c339b8-b936-40c7-b121-1a4c14838dd9@kernel.org> (raw)
In-Reply-To: <CAJqi8kJf9EzfZWBo=1KpEzGiq+vGRz0J0mN+-NXAjrtq9HDrMg@mail.gmail.com>
On 8/21/26 18:09, Anshuman Tewari wrote:
> Thanks David, agreed — strdup() is overkill here for a single-use
> parse, and dropping it is the right call.
>
> One small consideration on the approach: working on argv[0] in place
> means strsep() will overwrite the : separator with '\0', so the
> original string (e.g. "khugepaged:anon") ends up truncated after
> parsing. Nothing today reads argv[0] again afterward, so it's safe as
> things stand, but it does mean correctness quietly depends on that
> staying true — a future change that logs argv[0], re-parses it, or
> echoes it back in an error/usage message would get the mutated version
> instead of what the user actually typed.
>
> If we'd rather not rely on that invariant, an alternative that still
> avoids strdup()/free() entirely: copy the type argument into a small
> fixed-size stack buffer (with a bounds check against its length first)
> and run strsep() on that copy instead of on argv[0] directly. Same
> benefit as your version — no allocation, nothing to free, no
> NULL-check needed — but argv[0] itself stays untouched.
>
> Happy to write this up as a v2 if it seems worthwhile, or if you think
> relying on "nothing downstream needs argv[0]" is fine as-is, I'm okay
> going with your version too. Your call.
I don't think we have to worry about other such argv[0] users. If they ever
appear, basic testing would reveal them.
--
Cheers,
David
next prev parent reply other threads:[~2026-08-21 16:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-21 11:44 Anshuman
2026-08-21 14:18 ` David Hildenbrand (Arm)
2026-08-21 16:09 ` Anshuman Tewari
2026-08-21 16:18 ` David Hildenbrand (Arm) [this message]
2026-08-21 20:14 ` Anshuman Tewari
2026-08-25 11:03 ` David Hildenbrand (Arm)
2026-08-25 18:20 ` Anshuman Tewari
2026-08-25 18:32 ` 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=e7c339b8-b936-40c7-b121-1a4c14838dd9@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=anshumantewari123@gmail.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=dev.jain@arm.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=nico.pache@linux.dev \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®