linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Liam R. Howlett" <Liam.Howlett@oracle.com>
To: SeongJae Park <sj@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@redhat.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	Vlastimil Babka <vbabka@suse.cz>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH 2/4] mm/madvise: split out madvise input validity check
Date: Thu, 6 Feb 2025 15:29:06 -0500	[thread overview]
Message-ID: <oucdbedlr4hniwxcsel7xfv2d6gy7uqw5rs5syfgchhllz5i36@lumnjpc5nmkt> (raw)
In-Reply-To: <20250206061517.2958-3-sj@kernel.org>

* SeongJae Park <sj@kernel.org> [250206 01:15]:
> Split out the madvise parameters validation logic from do_madvise(), for
> easy reuse of the logic from a future change.
> 
> Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
> Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
> Signed-off-by: SeongJae Park <sj@kernel.org>

Reviewed-by: Liam R. Howlett <howlett@gmail.com>

> ---
>  mm/madvise.c | 32 ++++++++++++++++++++++----------
>  1 file changed, 22 insertions(+), 10 deletions(-)
> 
> diff --git a/mm/madvise.c b/mm/madvise.c
> index df5a87a1846a..efab2878be7c 100644
> --- a/mm/madvise.c
> +++ b/mm/madvise.c
> @@ -1594,6 +1594,27 @@ static void madvise_unlock(struct mm_struct *mm, int behavior)
>  		mmap_read_unlock(mm);
>  }
>  
> +static bool is_valid_madvise(unsigned long start, size_t len_in, int behavior)
> +{
> +	size_t len;
> +
> +	if (!madvise_behavior_valid(behavior))
> +		return false;
> +
> +	if (!PAGE_ALIGNED(start))
> +		return false;
> +	len = PAGE_ALIGN(len_in);
> +
> +	/* Check to see whether len was rounded up from small -ve to zero */
> +	if (len_in && !len)
> +		return false;
> +
> +	if (start + len < start)
> +		return false;
> +
> +	return true;
> +}
> +
>  /*
>   * The madvise(2) system call.
>   *
> @@ -1673,20 +1694,11 @@ int do_madvise(struct mm_struct *mm, unsigned long start, size_t len_in, int beh
>  	size_t len;
>  	struct blk_plug plug;
>  
> -	if (!madvise_behavior_valid(behavior))
> +	if (!is_valid_madvise(start, len_in, behavior))
>  		return -EINVAL;
>  
> -	if (!PAGE_ALIGNED(start))
> -		return -EINVAL;
>  	len = PAGE_ALIGN(len_in);
> -
> -	/* Check to see whether len was rounded up from small -ve to zero */
> -	if (len_in && !len)
> -		return -EINVAL;
> -
>  	end = start + len;
> -	if (end < start)
> -		return -EINVAL;
>  
>  	if (end == start)
>  		return 0;
> -- 
> 2.39.5


  reply	other threads:[~2025-02-06 20:29 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-06  6:15 [PATCH 0/4] mm/madvise: remove redundant mmap_lock operations from process_madvise() SeongJae Park
2025-02-06  6:15 ` [PATCH 1/4] mm/madvise: split out mmap locking operations for madvise() SeongJae Park
2025-02-06 20:27   ` Liam R. Howlett
2025-02-06  6:15 ` [PATCH 2/4] mm/madvise: split out madvise input validity check SeongJae Park
2025-02-06 20:29   ` Liam R. Howlett [this message]
2025-02-06  6:15 ` [PATCH 3/4] mm/madvise: split out madvise() behavior execution SeongJae Park
2025-02-06 20:30   ` Liam R. Howlett
2025-02-06  6:15 ` [PATCH 4/4] mm/madvise: remove redundant mmap_lock operations from process_madvise() SeongJae Park
2025-02-06 13:04   ` Lorenzo Stoakes
2025-02-06 16:53     ` SeongJae Park
2025-02-06 20:32   ` Liam R. Howlett
2025-02-11  5:30   ` Lai, Yi
2025-02-11  6:37     ` SeongJae Park
2025-02-11 10:34     ` Lorenzo Stoakes
2025-02-11 18:32       ` SeongJae Park
2025-02-11  8:48 ` [PATCH 0/4] " Vern Hao
2025-02-11 18:28   ` SeongJae Park

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=oucdbedlr4hniwxcsel7xfv2d6gy7uqw5rs5syfgchhllz5i36@lumnjpc5nmkt \
    --to=liam.howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=dave@stgolabs.net \
    --cc=david@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=shakeel.butt@linux.dev \
    --cc=sj@kernel.org \
    --cc=vbabka@suse.cz \
    /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