From: "David Hildenbrand (Arm)" <david@kernel.org>
To: fujunjie <fujunjie1@qq.com>, Andrew Morton <akpm@linux-foundation.org>
Cc: "Liam R . Howlett" <Liam.Howlett@oracle.com>,
Lorenzo Stoakes <ljs@kernel.org>,
Vlastimil Babka <vbabka@kernel.org>, Jann Horn <jannh@google.com>,
Shuah Khan <shuah@kernel.org>,
Christian Brauner <brauner@kernel.org>,
SeongJae Park <sj@kernel.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH] mm/madvise: reject invalid process_madvise() advice for zero-length vectors
Date: Mon, 27 Apr 2026 09:49:46 +0200 [thread overview]
Message-ID: <40a48a9a-57d6-4658-89a0-68891b5bda99@kernel.org> (raw)
In-Reply-To: <tencent_98F3571EF9236437E5165F5C08CF258A9E08@qq.com>
On 4/26/26 13:08, fujunjie wrote:
> process_madvise() validates the advice while walking the imported iovec.
> If the iovec has zero total length, vector_madvise() never enters the
> loop and returns 0 without checking whether the advice value is valid.
>
> For a local mm, such as process_madvise(PIDFD_SELF, ...), the remote-only
> process_madvise_remote_valid() check is skipped. As a result, an invalid
> advice can be reported as success when the vector has zero total length.
> This differs from madvise(), which rejects an invalid advice before
> returning success for a zero-length range.
>
> Reject invalid advice before walking the vector. Valid zero-length
> requests remain no-ops and continue to return 0.
>
> Add a selftest that covers invalid advice with a zero-length iovec and an
> empty vector, while also checking that a valid zero-length request still
> succeeds.
>
> Fixes: 021781b01275 ("mm/madvise: unrestrict process_madvise() for current process")
> Signed-off-by: fujunjie <fujunjie1@qq.com>
> ---
> Testing:
> - Built bzImage.
> - Built tools/testing/selftests/mm/process_madv.
> - Ran tools/testing/selftests/mm/process_madv in QEMU:
> # PASSED: 7 / 7 tests passed.
>
> mm/madvise.c | 3 +++
> tools/testing/selftests/mm/process_madv.c | 29 +++++++++++++++++++++++
> 2 files changed, 32 insertions(+)
>
> diff --git a/mm/madvise.c b/mm/madvise.c
> index 69708e953cf56..83fe9e651a907 100644
> --- a/mm/madvise.c
> +++ b/mm/madvise.c
> @@ -2046,6 +2046,9 @@ static ssize_t vector_madvise(struct mm_struct *mm, struct iov_iter *iter,
>
> total_len = iov_iter_count(iter);
>
> + if (!madvise_behavior_valid(behavior))
> + return -EINVAL;
> +
I'd suggest performing the check just before the !process_madvise_remote_valid()
check, such that "invalid/unsupported" orders are reported in the same priority,
independent of local vs. non-local MM.
Or is there a good reason to not do it there?
--
Cheers,
David
next prev parent reply other threads:[~2026-04-27 7:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-26 11:08 [PATCH] mm/madvise: reject invalid process_madvise() advice for zero-length vectors fujunjie
2026-04-26 19:41 ` Andrew Morton
2026-04-27 6:51 ` fujunjie
2026-04-27 7:49 ` David Hildenbrand (Arm) [this message]
2026-04-27 9:43 ` [PATCH v2] " fujunjie
2026-04-27 11:49 ` David Hildenbrand (Arm)
2026-04-28 7:05 ` Lorenzo Stoakes
2026-04-28 1:11 ` SeongJae Park
2026-04-28 7:02 ` Lorenzo Stoakes
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=40a48a9a-57d6-4658-89a0-68891b5bda99@kernel.org \
--to=david@kernel.org \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=fujunjie1@qq.com \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=shuah@kernel.org \
--cc=sj@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox