From: sashiko-bot@kernel.org
To: "Mike Rapoport (Microsoft)" <rppt@kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"David Hildenbrand" <david@kernel.org>
Cc: "Peter Xu" <peterx@redhat.com>,
"Suren Baghdasaryan" <surenb@google.com>,
linux-mm@kvack.org
Subject: Re: [PATCH 4/4] selftests/mm: free the test context when uffd_test_ctx_init() fails
Date: Wed, 02 Dec 2026 19:18:49 +0000 [thread overview]
Message-ID: <sashiko-outbox-246545@kernel.org> (raw)
In-Reply-To: <20261202-fixes-uffd-sashiko-v1-4-a6f5a874334a@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] selftests/mm: uninitialized gopts fields used in
uffd_test_ctx_clear()
--
commit 8ee91369181d6477837e66884f6a29b9ebb0157e
Author: Mike Rapoport (Microsoft) <rppt@kernel.org>
selftests/mm: free the test context when uffd_test_ctx_init() fails
This commit cleans up the test context via uffd_test_ctx_clear() when
uffd_test_ctx_init() fails and initializes gopts->uffd to -1.
> diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c
> index a76851aced4d0..284cd8a9150d5 100644
> --- a/tools/testing/selftests/mm/uffd-common.c
> +++ b/tools/testing/selftests/mm/uffd-common.c
> @@ -325,6 +325,7 @@ int uffd_test_ctx_init(uffd_global_test_opts_t *gopts, uint64_t features, const
> gopts->area_src_alias = NULL;
> gopts->area_dst_alias = NULL;
> gopts->area_remap = NULL;
> + gopts->uffd = -1;
>
> if (uffd_test_case_ops && uffd_test_case_ops->pre_alloc) {
> ret = uffd_test_case_ops->pre_alloc(gopts, errmsg);
> @@ -337,20 +338,20 @@ int uffd_test_ctx_init(uffd_global_test_opts_t *gopts, uint64_t features, const
> if (ret) {
> if (errmsg)
> *errmsg = "memory allocation failed";
> - return ret;
> + goto err_clear;
> }
>
> if (uffd_test_case_ops && uffd_test_case_ops->post_alloc) {
> ret = uffd_test_case_ops->post_alloc(gopts, errmsg);
> if (ret)
> - return ret;
> + goto err_clear;
> }
>
> ret = userfaultfd_open(gopts, &features);
> if (ret) {
> if (errmsg)
> *errmsg = "possible lack of privilege";
> - return ret;
> + goto err_clear;
> }
>
> gopts->count_verify = malloc(gopts->nr_pages * sizeof(unsigned long long));
> @@ -399,6 +400,10 @@ int uffd_test_ctx_init(uffd_global_test_opts_t *gopts, uint64_t features, const
> err("pipe");
>
> return 0;
> +
> +err_clear:
> + uffd_test_ctx_clear(gopts);
> + return ret;
> }
[Severity: Low]
Can jumping to err_clear cause uffd_test_ctx_clear() to use uninitialized
gopts->count_verify, gopts->pipefd, gopts->area_src, and gopts->area_dst
pointers?
In uffd-stress.c, main() allocates gopts with malloc() without zeroing it.
If allocate_area(), post_alloc(), or userfaultfd_open() fails,
uffd_test_ctx_clear() runs before gopts->count_verify and gopts->pipefd
are assigned (and shmem_allocate_area() can also fail before assigning
*alloc_area), passing garbage pointers to close(), free(), and munmap().
Should uffd_test_ctx_init() also initialize those four fields to NULL at
entry alongside gopts->uffd = -1?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-fixes-uffd-sashiko-v1-0-a6f5a874334a@kernel.org?part=4
prev parent reply other threads:[~2026-12-02 19:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 18:20 [PATCH 0/4] userfaultfd: fixes for sashiko reports Mike Rapoport (Microsoft)
2026-12-02 18:20 ` [PATCH 1/4] userfaultfd: write-lock the VMA before clearing its uffd state Mike Rapoport (Microsoft)
2026-12-02 18:20 ` [PATCH 2/4] userfaultfd: mark zero pages moved by UFFDIO_MOVE soft-dirty Mike Rapoport (Microsoft)
2026-12-02 18:20 ` [PATCH 3/4] userfaultfd: mark THPs " Mike Rapoport (Microsoft)
2026-12-02 18:20 ` [PATCH 4/4] selftests/mm: free the test context when uffd_test_ctx_init() fails Mike Rapoport (Microsoft)
2026-12-02 19:18 ` sashiko-bot [this message]
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-246545@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=linux-mm@kvack.org \
--cc=peterx@redhat.com \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=surenb@google.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