lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 19 Aug 2020 11:14:55 -0700
From:   John Hubbard <jhubbard@...dia.com>
To:     Barry Song <song.bao.hua@...ilicon.com>,
        <akpm@...ux-foundation.org>, <linux-mm@...ck.org>,
        <linux-kernel@...r.kernel.org>
CC:     <linuxarm@...wei.com>, Jan Kara <jack@...e.cz>,
        Jérôme Glisse <jglisse@...hat.com>,
        "Matthew Wilcox (Oracle)" <willy@...radead.org>,
        Al Viro <viro@...iv.linux.org.uk>,
        "Christoph Hellwig" <hch@...radead.org>,
        Dan Williams <dan.j.williams@...el.com>,
        "Dave Chinner" <david@...morbit.com>,
        Jason Gunthorpe <jgg@...pe.ca>,
        "Jonathan Corbet" <corbet@....net>, Michal Hocko <mhocko@...e.com>,
        Mike Kravetz <mike.kravetz@...cle.com>,
        Shuah Khan <shuah@...nel.org>, Vlastimil Babka <vbabka@...e.cz>
Subject: Re: [PATCH] mm/gup: don't permit users to call get_user_pages with
 FOLL_LONGTERM

On 8/19/20 4:01 AM, Barry Song wrote:
> gug prohibits users from calling get_user_pages() with FOLL_PIN. But it

Maybe Andrew can fix the typo above: gug --> gup.


> allows users to call get_user_pages() with FOLL_LONGTERM only. It seems
> insensible.
> 
> since FOLL_LONGTERM is a stricter case of FOLL_PIN, we should prohibit
> users from calling get_user_pages() with FOLL_LONGTERM while not with
> FOLL_PIN.
> 
> mm/gup_benchmark.c used to be the only user who did this improperly.
> But it has been fixed by moving to use pin_user_pages().

For future patches, you don't have to write everything in the
commit log. Some things are better placed in a cover letter or after
the "---" line, because they don't need to be recorded forever.

Anyway, the diffs seem fine, assuming that you've audited the call sites.

thanks,
-- 
John Hubbard
NVIDIA

> 
> Cc: John Hubbard <jhubbard@...dia.com>
> Cc: Jan Kara <jack@...e.cz>
> Cc: Jérôme Glisse <jglisse@...hat.com>
> Cc: "Matthew Wilcox (Oracle)" <willy@...radead.org>
> Cc: Al Viro <viro@...iv.linux.org.uk>
> Cc: Christoph Hellwig <hch@...radead.org>
> Cc: Dan Williams <dan.j.williams@...el.com>
> Cc: Dave Chinner <david@...morbit.com>
> Cc: Jason Gunthorpe <jgg@...pe.ca>
> Cc: Jonathan Corbet <corbet@....net>
> Cc: Michal Hocko <mhocko@...e.com>
> Cc: Mike Kravetz <mike.kravetz@...cle.com>
> Cc: Shuah Khan <shuah@...nel.org>
> Cc: Vlastimil Babka <vbabka@...e.cz>
> Signed-off-by: Barry Song <song.bao.hua@...ilicon.com>
> ---
>   mm/gup.c | 37 ++++++++++++++++++++++---------------
>   1 file changed, 22 insertions(+), 15 deletions(-)
> 
> diff --git a/mm/gup.c b/mm/gup.c
> index ae096ea7583f..4da669f79566 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -1789,6 +1789,25 @@ static long __get_user_pages_remote(struct mm_struct *mm,
>   				       gup_flags | FOLL_TOUCH | FOLL_REMOTE);
>   }
>   
> +static bool is_valid_gup_flags(unsigned int gup_flags)
> +{
> +	/*
> +	 * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
> +	 * never directly by the caller, so enforce that with an assertion:
> +	 */
> +	if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
> +		return false;
> +	/*
> +	 * FOLL_PIN is a prerequisite to FOLL_LONGTERM. Another way of saying
> +	 * that is, FOLL_LONGTERM is a specific case, more restrictive case of
> +	 * FOLL_PIN.
> +	 */
> +	if (WARN_ON_ONCE(gup_flags & FOLL_LONGTERM))
> +		return false;
> +
> +	return true;
> +}
> +
>   /**
>    * get_user_pages_remote() - pin user pages in memory
>    * @mm:		mm_struct of target mm
> @@ -1854,11 +1873,7 @@ long get_user_pages_remote(struct mm_struct *mm,
>   		unsigned int gup_flags, struct page **pages,
>   		struct vm_area_struct **vmas, int *locked)
>   {
> -	/*
> -	 * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
> -	 * never directly by the caller, so enforce that with an assertion:
> -	 */
> -	if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
> +	if (!is_valid_gup_flags(gup_flags))
>   		return -EINVAL;
>   
>   	return __get_user_pages_remote(mm, start, nr_pages, gup_flags,
> @@ -1904,11 +1919,7 @@ long get_user_pages(unsigned long start, unsigned long nr_pages,
>   		unsigned int gup_flags, struct page **pages,
>   		struct vm_area_struct **vmas)
>   {
> -	/*
> -	 * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
> -	 * never directly by the caller, so enforce that with an assertion:
> -	 */
> -	if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
> +	if (!is_valid_gup_flags(gup_flags))
>   		return -EINVAL;
>   
>   	return __gup_longterm_locked(current->mm, start, nr_pages,
> @@ -2810,11 +2821,7 @@ EXPORT_SYMBOL_GPL(get_user_pages_fast_only);
>   int get_user_pages_fast(unsigned long start, int nr_pages,
>   			unsigned int gup_flags, struct page **pages)
>   {
> -	/*
> -	 * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
> -	 * never directly by the caller, so enforce that:
> -	 */
> -	if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
> +	if (!is_valid_gup_flags(gup_flags))
>   		return -EINVAL;
>   
>   	/*
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ