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]
Message-ID: <f36cdc92-c52a-664e-dad9-fccfa5c187d5@redhat.com>
Date:   Mon, 31 Jan 2022 15:28:36 +0100
From:   David Hildenbrand <david@...hat.com>
To:     "Matthew Wilcox (Oracle)" <willy@...radead.org>,
        Kees Cook <keescook@...omium.org>
Cc:     linux-mm@...ck.org, linux-hardening@...r.kernel.org
Subject: Re: [PATCH 3/4] mm/usercopy: Detect large folio overruns

On 11.01.22 00:15, Matthew Wilcox (Oracle) wrote:
> Move the compound page overrun detection out of
> CONFIG_HARDENED_USERCOPY_PAGESPAN and convert it to use folios so it's
> enabled for more people.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@...radead.org>
> Acked-by: Kees Cook <keescook@...omium.org>
> ---
>  mm/usercopy.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/mm/usercopy.c b/mm/usercopy.c
> index dcf71b7e3098..e1cb98087a05 100644
> --- a/mm/usercopy.c
> +++ b/mm/usercopy.c
> @@ -164,7 +164,6 @@ static inline void check_page_span(const void *ptr, unsigned long n,
>  {
>  #ifdef CONFIG_HARDENED_USERCOPY_PAGESPAN
>  	const void *end = ptr + n - 1;
> -	struct page *endpage;
>  	bool is_reserved, is_cma;
>  
>  	/*
> @@ -195,11 +194,6 @@ static inline void check_page_span(const void *ptr, unsigned long n,
>  		   ((unsigned long)end & (unsigned long)PAGE_MASK)))
>  		return;
>  
> -	/* Allow if fully inside the same compound (__GFP_COMP) page. */
> -	endpage = virt_to_head_page(end);
> -	if (likely(endpage == page))
> -		return;
> -
>  	/*
>  	 * Reject if range is entirely either Reserved (i.e. special or
>  	 * device memory), or CMA. Otherwise, reject since the object spans
> @@ -259,6 +253,10 @@ static inline void check_heap_object(const void *ptr, unsigned long n,
>  	if (folio_test_slab(folio)) {
>  		/* Check slab allocator for flags and size. */
>  		__check_heap_object(ptr, n, folio_slab(folio), to_user);
> +	} else if (folio_test_large(folio)) {
> +		unsigned long offset = ptr - folio_address(folio);

Nit: I'd have added an empty line.

> +		if (offset + n > folio_size(folio))
> +			usercopy_abort("page alloc", NULL, to_user, offset, n);
>  	} else {
>  		/* Verify object does not incorrectly span multiple pages. */
>  		check_page_span(ptr, n, folio_page(folio, 0), to_user);

LGTM

Reviewed-by: David Hildenbrand <david@...hat.com>

-- 
Thanks,

David / dhildenb

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ