Commit a5f4d9df authored by Yuanzheng Song's avatar Yuanzheng Song Committed by Kees Cook

mm: usercopy: move the virt_addr_valid() below the is_vmalloc_addr()

The is_kmap_addr() and the is_vmalloc_addr() in the check_heap_object()
will not work, because the virt_addr_valid() will exclude the kmap and
vmalloc regions. So let's move the virt_addr_valid() below
the is_vmalloc_addr().
Signed-off-by: default avatarYuanzheng Song <songyuanzheng@huawei.com>
Fixes: 4e140f59 ("mm/usercopy: Check kmap addresses properly")
Fixes: 0aef499f ("mm/usercopy: Detect vmalloc overruns")
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20220505071037.4121100-1-songyuanzheng@huawei.com
parent 710e4ebf
...@@ -163,9 +163,6 @@ static inline void check_heap_object(const void *ptr, unsigned long n, ...@@ -163,9 +163,6 @@ static inline void check_heap_object(const void *ptr, unsigned long n,
{ {
struct folio *folio; struct folio *folio;
if (!virt_addr_valid(ptr))
return;
if (is_kmap_addr(ptr)) { if (is_kmap_addr(ptr)) {
unsigned long page_end = (unsigned long)ptr | (PAGE_SIZE - 1); unsigned long page_end = (unsigned long)ptr | (PAGE_SIZE - 1);
...@@ -190,6 +187,9 @@ static inline void check_heap_object(const void *ptr, unsigned long n, ...@@ -190,6 +187,9 @@ static inline void check_heap_object(const void *ptr, unsigned long n,
return; return;
} }
if (!virt_addr_valid(ptr))
return;
folio = virt_to_folio(ptr); folio = virt_to_folio(ptr);
if (folio_test_slab(folio)) { if (folio_test_slab(folio)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment