mm/sl[au]b: check if large object is valid in __ksize()
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 <elver@google.com> Suggested-by: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
This commit is contained in:
Родитель
8dfa9d5540
Коммит
d5eff73690
|
@ -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);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче