Skip to content

Commit

Permalink
mm: usercopy: move the virt_addr_valid() below the is_vmalloc_addr()
Browse files Browse the repository at this point in the history
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: Yuanzheng Song <[email protected]>
Fixes: 4e140f5 ("mm/usercopy: Check kmap addresses properly")
Fixes: 0aef499 ("mm/usercopy: Detect vmalloc overruns")
Cc: Matthew Wilcox (Oracle) <[email protected]>
Signed-off-by: Kees Cook <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
Yuanzheng Song authored and kees committed May 16, 2022
1 parent 710e4eb commit a5f4d9d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mm/usercopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ static inline void check_heap_object(const void *ptr, unsigned long n,
{
struct folio *folio;

if (!virt_addr_valid(ptr))
return;

if (is_kmap_addr(ptr)) {
unsigned long page_end = (unsigned long)ptr | (PAGE_SIZE - 1);

Expand All @@ -190,6 +187,9 @@ static inline void check_heap_object(const void *ptr, unsigned long n,
return;
}

if (!virt_addr_valid(ptr))
return;

folio = virt_to_folio(ptr);

if (folio_test_slab(folio)) {
Expand Down

0 comments on commit a5f4d9d

Please sign in to comment.