Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kasan: cleanup of kasan_enabled() checks

Deduplication of kasan_enabled() checks which are already used by callers.

* Altered functions:

check_page_allocation
Delete the check because callers have it already in __wrappers in
include/linux/kasan.h:
__kasan_kfree_large
__kasan_mempool_poison_pages
__kasan_mempool_poison_object

kasan_populate_vmalloc, kasan_release_vmalloc
Add __wrappers in include/linux/kasan.h.
They are called externally in mm/vmalloc.c.

__kasan_unpoison_vmalloc, __kasan_poison_vmalloc
Delete checks because there're already kasan_enabled() checks
in respective __wrappers in include/linux/kasan.h.

release_free_meta -- Delete the check because the higher caller path
has it already. See the stack trace:

__kasan_slab_free -- has the check already
__kasan_mempool_poison_object -- has the check already
poison_slab_object
kasan_save_free_info
release_free_meta
kasan_enabled() -- Delete here

Link: https://lkml.kernel.org/r/20251009155403.1379150-3-snovitoll@gmail.com
Signed-off-by: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: "Ritesh Harjani (IBM)" <ritesh.list@gmail.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Sabyrzhan Tasbolatov and committed by
Andrew Morton
ada5cbe3 27109f57

+22 -24
+18 -2
include/linux/kasan.h
··· 571 571 #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) 572 572 573 573 void kasan_populate_early_vm_area_shadow(void *start, unsigned long size); 574 - int kasan_populate_vmalloc(unsigned long addr, unsigned long size, gfp_t gfp_mask); 575 - void kasan_release_vmalloc(unsigned long start, unsigned long end, 574 + int __kasan_populate_vmalloc(unsigned long addr, unsigned long size, gfp_t gfp_mask); 575 + static inline int kasan_populate_vmalloc(unsigned long addr, 576 + unsigned long size, gfp_t gfp_mask) 577 + { 578 + if (kasan_enabled()) 579 + return __kasan_populate_vmalloc(addr, size, gfp_mask); 580 + return 0; 581 + } 582 + void __kasan_release_vmalloc(unsigned long start, unsigned long end, 576 583 unsigned long free_region_start, 577 584 unsigned long free_region_end, 578 585 unsigned long flags); 586 + static inline void kasan_release_vmalloc(unsigned long start, unsigned long end, 587 + unsigned long free_region_start, 588 + unsigned long free_region_end, 589 + unsigned long flags) 590 + { 591 + if (kasan_enabled()) 592 + return __kasan_release_vmalloc(start, end, free_region_start, 593 + free_region_end, flags); 594 + } 579 595 580 596 #else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ 581 597
-3
mm/kasan/common.c
··· 305 305 306 306 static inline bool check_page_allocation(void *ptr, unsigned long ip) 307 307 { 308 - if (!kasan_enabled()) 309 - return false; 310 - 311 308 if (ptr != page_address(virt_to_head_page(ptr))) { 312 309 kasan_report_invalid_free(ptr, ip, KASAN_REPORT_INVALID_FREE); 313 310 return true;
-3
mm/kasan/generic.c
··· 506 506 507 507 static void release_free_meta(const void *object, struct kasan_free_meta *meta) 508 508 { 509 - if (!kasan_enabled()) 510 - return; 511 - 512 509 /* Check if free meta is valid. */ 513 510 if (*(u8 *)kasan_mem_to_shadow(object) != KASAN_SLAB_FREE_META) 514 511 return;
+4 -16
mm/kasan/shadow.c
··· 354 354 return 0; 355 355 } 356 356 357 - static int __kasan_populate_vmalloc(unsigned long start, unsigned long end, gfp_t gfp_mask) 357 + static int __kasan_populate_vmalloc_do(unsigned long start, unsigned long end, gfp_t gfp_mask) 358 358 { 359 359 unsigned long nr_pages, nr_total = PFN_UP(end - start); 360 360 struct vmalloc_populate_data data; ··· 395 395 return ret; 396 396 } 397 397 398 - int kasan_populate_vmalloc(unsigned long addr, unsigned long size, gfp_t gfp_mask) 398 + int __kasan_populate_vmalloc(unsigned long addr, unsigned long size, gfp_t gfp_mask) 399 399 { 400 400 unsigned long shadow_start, shadow_end; 401 401 int ret; 402 - 403 - if (!kasan_enabled()) 404 - return 0; 405 402 406 403 if (!is_vmalloc_or_module_addr((void *)addr)) 407 404 return 0; ··· 421 424 shadow_start = PAGE_ALIGN_DOWN(shadow_start); 422 425 shadow_end = PAGE_ALIGN(shadow_end); 423 426 424 - ret = __kasan_populate_vmalloc(shadow_start, shadow_end, gfp_mask); 427 + ret = __kasan_populate_vmalloc_do(shadow_start, shadow_end, gfp_mask); 425 428 if (ret) 426 429 return ret; 427 430 ··· 563 566 * pages entirely covered by the free region, we will not run in to any 564 567 * trouble - any simultaneous allocations will be for disjoint regions. 565 568 */ 566 - void kasan_release_vmalloc(unsigned long start, unsigned long end, 569 + void __kasan_release_vmalloc(unsigned long start, unsigned long end, 567 570 unsigned long free_region_start, 568 571 unsigned long free_region_end, 569 572 unsigned long flags) ··· 571 574 void *shadow_start, *shadow_end; 572 575 unsigned long region_start, region_end; 573 576 unsigned long size; 574 - 575 - if (!kasan_enabled()) 576 - return; 577 577 578 578 region_start = ALIGN(start, KASAN_MEMORY_PER_SHADOW_PAGE); 579 579 region_end = ALIGN_DOWN(end, KASAN_MEMORY_PER_SHADOW_PAGE); ··· 620 626 * with setting memory tags, so the KASAN_VMALLOC_INIT flag is ignored. 621 627 */ 622 628 623 - if (!kasan_enabled()) 624 - return (void *)start; 625 - 626 629 if (!is_vmalloc_or_module_addr(start)) 627 630 return (void *)start; 628 631 ··· 642 651 */ 643 652 void __kasan_poison_vmalloc(const void *start, unsigned long size) 644 653 { 645 - if (!kasan_enabled()) 646 - return; 647 - 648 654 if (!is_vmalloc_or_module_addr(start)) 649 655 return; 650 656