From: Lorenzo Stoakes <ljs@kernel.org>
To: Chris Gellermann <christian.gellermann@codasip.com>
Cc: brauner@kernel.org, shuah@kernel.org, akpm@linux-foundation.org,
david@kernel.org, liam@infradead.org, vbabka@kernel.org,
rppt@kernel.org, surenb@google.com, mhocko@suse.com,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [PATCH] selftest: Fix UB of getline due to missing var init
Date: Tue, 26 May 2026 14:33:24 +0100 [thread overview]
Message-ID: <ahWNRKCzGykpYE0h@lucifer> (raw)
In-Reply-To: <20260526113848.530105-1-christian.gellermann@codasip.com>
On Tue, May 26, 2026 at 01:38:48PM +0200, Chris Gellermann wrote:
> Clone3_set_tid uses getline(&line, &len, f) in a loop to read the
> child's process status. The code expects that getline allocates the
> buffer for the line on the first loop iteration. For this, glibc[1]
> requires char *line to be set to NULL:
>
> > ssize_t getline(char **restrict lineptr, ...)
> > If *lineptr is set to NULL before the call, then getline() will
> > allocate a buffer for storing the line.
>
> However, char *line is only declared, leading to an undefined
> initialization value. Fix this by properly initializing it to NULL.
>
> Same issue fixed in mlock-random-test.
>
> [1] https://man7.org/linux/man-pages/man3/getline.3.html
>
> Fixes: 41585bbeeef9 ("selftests: add tests for clone3() with *set_tid")
> Fixes: 26b4224d9961 ("selftests: expanding more mlock selftest")
You'll need separate commits for each I think? That'd at least make life
easier. You can send them as a series.
> Signed-off-by: Chris Gellermann <christian.gellermann@codasip.com>
> ---
> tools/testing/selftests/clone3/clone3_set_tid.c | 2 +-
> tools/testing/selftests/mm/mlock-random-test.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/clone3/clone3_set_tid.c b/tools/testing/selftests/clone3/clone3_set_tid.c
> index 5c944aee6b41..485efa7c9eed 100644
> --- a/tools/testing/selftests/clone3/clone3_set_tid.c
> +++ b/tools/testing/selftests/clone3/clone3_set_tid.c
> @@ -141,7 +141,7 @@ int main(int argc, char *argv[])
> {
> FILE *f;
> char buf;
> - char *line;
> + char *line = NULL;
> int status;
> int ret = -1;
> size_t len = 0;
> diff --git a/tools/testing/selftests/mm/mlock-random-test.c b/tools/testing/selftests/mm/mlock-random-test.c
> index 9d349c151360..16294bc7dae6 100644
> --- a/tools/testing/selftests/mm/mlock-random-test.c
> +++ b/tools/testing/selftests/mm/mlock-random-test.c
> @@ -84,7 +84,7 @@ int get_proc_locked_vm_size(void)
> int get_proc_page_size(unsigned long addr)
> {
> FILE *smaps;
> - char *line;
> + char *line = NULL;
Strange this didn't result in noticeable bugs but maybe perceived as flakes
or such?
> unsigned long mmupage_size = 0;
> size_t size;
>
> --
> 2.47.3
>
Cheers, Lorenzo
next prev parent reply other threads:[~2026-05-26 13:33 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 11:38 [PATCH] selftest: Fix UB of getline due to missing var init Chris Gellermann
2026-05-26 12:19 ` David Hildenbrand (Arm)
2026-05-26 13:33 ` Lorenzo Stoakes [this message]
2026-05-26 18:34 ` Andrew Morton
2026-05-27 16:23 ` Lorenzo Stoakes
2026-06-03 10:43 ` [PATCH v2 1/2] selftests/clone3: Fix wild pointer access of getline due to missing init Chris Gellermann
2026-06-03 10:43 ` [PATCH v2 2/2] selftests/mm: Fix potential " Chris Gellermann
2026-06-03 12:05 ` [PATCH v2 1/2] selftests/clone3: Fix " Lorenzo Stoakes
2026-06-03 14:57 ` Chris Gellermann
2026-07-22 13:02 ` [PATCH v2 0/2] selftests: Add missing initalization of pointer passed to getline Chris Gellermann
2026-07-22 13:02 ` [PATCH v2 1/2] selftests/clone3: Fix wild pointer access of getline due to missing init Chris Gellermann
2026-07-22 13:02 ` [PATCH v2 2/2] selftests/mm: Fix potential " Chris Gellermann
2026-07-28 19:31 ` [PATCH v2 0/2] selftests: Add missing initalization of pointer passed to getline David Hildenbrand (Arm)
2026-07-29 0:27 ` Andrew Morton
2026-07-29 7:59 ` 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=ahWNRKCzGykpYE0h@lucifer \
--to=ljs@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=christian.gellermann@codasip.com \
--cc=david@kernel.org \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@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.