From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Nguyen Duy Nhat Anh <neganhat@gmail.com>, akpm@linux-foundation.org
Cc: jgg@ziepe.ca, jhubbard@nvidia.com, peterx@redhat.com,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] mm/gup: document unlocked invariant in fixup_user_fault
Date: Mon, 5 Oct 2026 12:29:48 +0200 [thread overview]
Message-ID: <645204ff-6c50-4ef3-9070-78ac602560b1@kernel.org> (raw)
In-Reply-To: <20261005093756.22709-1-neganhat@gmail.com>
On 10/5/26 11:37, Nguyen Duy Nhat Anh wrote:
> Static analysis tools flag potential NULL pointer
> dereferences of 'unlocked' in fixup_user_fault() when handling
> VM_FAULT_COMPLETED or VM_FAULT_RETRY.
>
> These warnings are false positives. 'unlocked' is only dereferenced when
> handle_mm_fault() returns VM_FAULT_COMPLETED or VM_FAULT_RETRY. Both of
> these return codes require FAULT_FLAG_ALLOW_RETRY to be set in
> fault_flags, which fixup_user_fault() only sets if 'unlocked' is non-NULL
> upon entry. Therefore, if 'unlocked' is NULL, the control flow branches
> that dereference 'unlocked' are unreachable.
>
> However, this part of the code is subtle and can trip up
> contributors or automated tools. Document this invariant with a comment
> above 'if (unlocked)' where fault_flags is constructed, explaining why
> omitting FAULT_FLAG_ALLOW_RETRY guarantees 'unlocked' will not be
> dereferenced later in the fault recovery loop.
>
> Suggested-by: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Nguyen Duy Nhat Anh <neganhat@gmail.com>
> ---
> v1: https://lore.kernel.org/linux-mm/20261003194846.205918-1-neganhat@gmail.com/
>
> v2 changes:
> - Instead of adding runtime NULL checks at dereference sites,
> document the FAULT_FLAG_ALLOW_RETRY invariant above if (unlocked).
> ---
> mm/gup.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/mm/gup.c b/mm/gup.c
> index eb898ea1ee22..58fa75441da1 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -1570,6 +1570,12 @@ int fixup_user_fault(struct mm_struct *mm,
>
> address = untagged_addr_remote(mm, address);
>
> + /*
> + * If the caller passes 'unlocked' as NULL, FAULT_FLAG_ALLOW_RETRY is omitted.
> + * This guarantees handle_mm_fault() will never drop the lock or
> + * return VM_FAULT_COMPLETED / VM_FAULT_RETRY, making subsequent
> + * dereferences of 'unlocked' unreachable when NULL.
> + */
> if (unlocked)
> fault_flags |= FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
>
For which audience is the comment targeted? For people that know what they are
doing? No.
For tools that report such problems? No.
So I don't think this (4 lines of comment) is the right way to improve this.
--
Cheers,
David
next prev parent reply other threads:[~2026-10-05 10:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-03 19:48 [PATCH] mm/gup: fix NULL pointer dereference in fixup_user_fault() Nguyen Duy Nhat Anh
2026-10-04 19:56 ` Andrew Morton
2026-10-05 2:19 ` Lance Yang
2026-10-05 10:27 ` David Hildenbrand (Arm)
2026-10-05 9:37 ` [PATCH v2] mm/gup: document unlocked invariant in fixup_user_fault Nguyen Duy Nhat Anh
2026-10-05 10:29 ` David Hildenbrand (Arm) [this message]
2026-10-05 11:22 ` Nhật Anh Nguyễn Duy
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=645204ff-6c50-4ef3-9070-78ac602560b1@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=neganhat@gmail.com \
--cc=peterx@redhat.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®