Skip to content

Commit a5f4d9d

Browse files
Yuanzheng Songkees
authored andcommitted
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: 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]
1 parent 710e4eb commit a5f4d9d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

mm/usercopy.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,6 @@ static inline void check_heap_object(const void *ptr, unsigned long n,
163163
{
164164
struct folio *folio;
165165

166-
if (!virt_addr_valid(ptr))
167-
return;
168-
169166
if (is_kmap_addr(ptr)) {
170167
unsigned long page_end = (unsigned long)ptr | (PAGE_SIZE - 1);
171168

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

190+
if (!virt_addr_valid(ptr))
191+
return;
192+
193193
folio = virt_to_folio(ptr);
194194

195195
if (folio_test_slab(folio)) {

0 commit comments

Comments
 (0)