[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211216215351.3811471-4-willy@infradead.org>
Date: Thu, 16 Dec 2021 21:53:50 +0000
From: "Matthew Wilcox (Oracle)" <willy@...radead.org>
To: Kees Cook <keescook@...omium.org>
Cc: "Matthew Wilcox (Oracle)" <willy@...radead.org>,
linux-mm@...ck.org, linux-hardening@...r.kernel.org,
William Kucharski <william.kucharski@...cle.com>
Subject: [PATCH v4 3/4] mm/usercopy: Detect compound page overruns
Move the compound page overrun detection out of
CONFIG_HARDENED_USERCOPY_PAGESPAN so it's enabled for more people.
Signed-off-by: Matthew Wilcox (Oracle) <willy@...radead.org>
Acked-by: Kees Cook <keescook@...omium.org>
Reviewed-by: William Kucharski <william.kucharski@...cle.com>
---
mm/usercopy.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/mm/usercopy.c b/mm/usercopy.c
index 63476e1506e0..db2e8c4f79fd 100644
--- a/mm/usercopy.c
+++ b/mm/usercopy.c
@@ -163,7 +163,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;
/*
@@ -194,11 +193,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
@@ -258,6 +252,11 @@ static inline void check_heap_object(const void *ptr, unsigned long n,
if (PageSlab(page)) {
/* Check slab allocator for flags and size. */
__check_heap_object(ptr, n, page, to_user);
+ } else if (PageHead(page)) {
+ /* A compound allocation */
+ unsigned long offset = ptr - page_address(page);
+ if (offset + n > page_size(page))
+ usercopy_abort("page alloc", NULL, to_user, offset, n);
} else {
/* Verify object does not incorrectly span multiple pages. */
check_page_span(ptr, n, page, to_user);
--
2.33.0
Powered by blists - more mailing lists