]> Git Repo - J-linux.git/commitdiff
mm/sl[au]b: check if large object is valid in __ksize()
authorHyeonggon Yoo <[email protected]>
Wed, 17 Aug 2022 10:18:26 +0000 (19:18 +0900)
committerVlastimil Babka <[email protected]>
Thu, 1 Sep 2022 09:44:39 +0000 (11:44 +0200)
If address of large object is not beginning of folio or size of the
folio is too small, it must be invalid. WARN() and return 0 in such
cases.

Cc: Marco Elver <[email protected]>
Suggested-by: Vlastimil Babka <[email protected]>
Signed-off-by: Hyeonggon Yoo <[email protected]>
Reviewed-by: Vlastimil Babka <[email protected]>
Signed-off-by: Vlastimil Babka <[email protected]>
mm/slab_common.c

index 500eb777faca664d44ceced39f282af621603794..7972ec4b9ca42c62d2a43ad1f206781f8d5b8e52 100644 (file)
@@ -984,8 +984,13 @@ size_t __ksize(const void *object)
 
        folio = virt_to_folio(object);
 
-       if (unlikely(!folio_test_slab(folio)))
+       if (unlikely(!folio_test_slab(folio))) {
+               if (WARN_ON(folio_size(folio) <= KMALLOC_MAX_CACHE_SIZE))
+                       return 0;
+               if (WARN_ON(object != folio_address(folio)))
+                       return 0;
                return folio_size(folio);
+       }
 
        return slab_ksize(folio_slab(folio)->slab_cache);
 }
This page took 0.053458 seconds and 4 git commands to generate.