[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CA+fCnZeDaNG+hXq1kP2uEX1V4ZY=PNg_M8Ljfwoi9i+4qGSm6A@mail.gmail.com>
Date: Sat, 17 Jan 2026 02:16:10 +0100
From: Andrey Konovalov <andreyknvl@...il.com>
To: Andrey Ryabinin <ryabinin.a.a@...il.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>, Maciej Żenczykowski <maze@...gle.com>,
Maciej Wieczor-Retman <m.wieczorretman@...me>, Alexander Potapenko <glider@...gle.com>,
Dmitry Vyukov <dvyukov@...gle.com>, Vincenzo Frascino <vincenzo.frascino@....com>,
kasan-dev@...glegroups.com, Uladzislau Rezki <urezki@...il.com>, linux-kernel@...r.kernel.org,
linux-mm@...ck.org, joonki.min@...sung-slsi.corp-partner.google.com,
stable@...r.kernel.org
Subject: Re: [PATCH 1/2] mm/kasan: Fix KASAN poisoning in vrealloc()
On Fri, Jan 16, 2026 at 2:26 PM Andrey Ryabinin <ryabinin.a.a@...il.com> wrote:
>
> So something like bellow I guess.
Yeah, looks good.
> I think this would actually have the opposite effect and make the code harder to follow.
> Introducing an extra wrapper adds another layer of indirection and more boilerplate, which
> makes the control flow less obvious and the code harder to navigate and grep.
>
> And what's the benefit here? I don't clearly see it.
One functional benefit is when HW_TAGS mode enabled in .config but
disabled via command-line, we avoid a function call into KASAN
runtime.
>From the readability perspective, what we had before the recent
clean-up was an assortment of kasan_enabled/kasan_arch_ready checks in
lower-level KASAN functions, which made it hard to figure out what
actually happens when KASAN is not enabled. And these high-level
checks make it more clear. At least in my opinion.
>
> ---
> include/linux/kasan.h | 10 +++++++++-
> mm/kasan/shadow.c | 5 +----
> 2 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/kasan.h b/include/linux/kasan.h
> index ff27712dd3c8..338a1921a50a 100644
> --- a/include/linux/kasan.h
> +++ b/include/linux/kasan.h
> @@ -641,9 +641,17 @@ kasan_unpoison_vmap_areas(struct vm_struct **vms, int nr_vms,
> __kasan_unpoison_vmap_areas(vms, nr_vms, flags);
> }
>
> -void kasan_vrealloc(const void *start, unsigned long old_size,
> +void __kasan_vrealloc(const void *start, unsigned long old_size,
> unsigned long new_size);
>
> +static __always_inline void kasan_vrealloc(const void *start,
> + unsigned long old_size,
> + unsigned long new_size)
> +{
> + if (kasan_enabled())
> + __kasan_vrealloc(start, old_size, new_size);
> +}
> +
> #else /* CONFIG_KASAN_VMALLOC */
>
> static inline void kasan_populate_early_vm_area_shadow(void *start,
> diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c
> index e9b6b2d8e651..29b0d0d38b40 100644
> --- a/mm/kasan/shadow.c
> +++ b/mm/kasan/shadow.c
> @@ -651,12 +651,9 @@ void __kasan_poison_vmalloc(const void *start, unsigned long size)
> kasan_poison(start, size, KASAN_VMALLOC_INVALID, false);
> }
>
> -void kasan_vrealloc(const void *addr, unsigned long old_size,
> +void __kasan_vrealloc(const void *addr, unsigned long old_size,
> unsigned long new_size)
> {
> - if (!kasan_enabled())
> - return;
> -
> if (new_size < old_size) {
> kasan_poison_last_granule(addr, new_size);
>
> --
> 2.52.0
>
>
Powered by blists - more mailing lists