mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dev Jain <dev.jain@arm.com>
To: Ryan Roberts <ryan.roberts@arm.com>,
	akpm@linux-foundation.org, vbabka@kernel.org, harry@kernel.org,
	ryabinin.a.a@gmail.com
Cc: surenb@google.com, mhocko@suse.com, jackmanb@google.com,
	hannes@cmpxchg.org, ziy@nvidia.com, hao.li@linux.dev,
	cl@gentwo.org, rientjes@google.com, roman.gushchin@linux.dev,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	glider@google.com, andreyknvl@gmail.com, dvyukov@google.com,
	vincenzo.frascino@arm.com, kasan-dev@googlegroups.com,
	anshuman.khandual@arm.com, catalin.marinas@arm.com
Subject: Re: [PATCH 2/3] kasan: avoid re-poisoning tag-based kmalloc redzones
Date: Wed, 20 May 2026 14:03:14 +0530	[thread overview]
Message-ID: <32fd8890-7c06-4a2d-9b8d-691a2d6b44aa@arm.com> (raw)
In-Reply-To: <4061d696-1567-41fe-9ff9-af408ca6d4bd@arm.com>


> 
> I got the problem now. The problem is that krealloc() does not know what was the
> old allocation size.
> 
> So only talking about HW tags, can't we simply do the following. We can use
> HW tags integrated init to initialize only the part we want to unpoison.
> 
> 
> diff --git a/mm/kasan/common.c b/mm/kasan/common.c
> index b7d05c2a6d93d..c424be3cd02bb 100644
> --- a/mm/kasan/common.c
> +++ b/mm/kasan/common.c
> @@ -474,7 +474,7 @@ void * __must_check __kasan_krealloc(const void *object, size_t size, gfp_t flag
>  	 * Part of it might already have been unpoisoned, but it's unknown
>  	 * how big that part is.
>  	 */
> -	kasan_unpoison(object, size, false);
> +	kasan_unpoison(object, size, want_init_on_alloc(flags));
> 
>  	slab = virt_to_slab(object);
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index 0baa906f39ab8..62ee59fc389d8 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -6686,7 +6686,7 @@ __do_krealloc(const void *p, size_t new_size, unsigned long align, gfp_t flags,
>  		goto alloc_new;
> 
>  	/* Zero out spare memory. */
> -	if (want_init_on_alloc(flags)) {
> +	if (want_init_on_alloc(flags) && !kasan_has_integrated_init()) {
>  		kasan_disable_current();
>  		if (orig_size && orig_size < new_size)
>  			memset(kasan_reset_tag(p) + orig_size, 0, new_size - orig_size);


Okay, this would overwrite the data which we still need.


> 
> 
> 
>>
>

  reply	other threads:[~2026-05-20  8:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-13 10:57 [PATCH 0/3] kasan: hw_tags: some micro-optimizations Dev Jain
2026-05-13 10:57 ` [PATCH 1/3] mm/slub: hw_tags: skip page-allocator unpoisoning on slab allocation Dev Jain
2026-05-14 12:11   ` Ryan Roberts
2026-05-15  7:04     ` Dev Jain
2026-05-13 10:57 ` [PATCH 2/3] kasan: avoid re-poisoning tag-based kmalloc redzones Dev Jain
2026-05-19  8:15   ` Dev Jain
2026-05-19  8:53     ` Ryan Roberts
2026-05-20  7:02       ` Dev Jain
2026-05-20  8:33         ` Dev Jain [this message]
2026-05-20  4:32     ` Dev Jain
2026-05-13 10:57 ` [PATCH 3/3] vmalloc: hw_tags: optimize vmalloc redzoning Dev Jain
2026-05-19  7:35   ` Dev Jain
2026-05-14  9:56 ` [PATCH 0/3] kasan: hw_tags: some micro-optimizations Harry Yoo (Oracle)
2026-05-14 10:22   ` Dev Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=32fd8890-7c06-4a2d-9b8d-691a2d6b44aa@arm.com \
    --to=dev.jain@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@gmail.com \
    --cc=anshuman.khandual@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=cl@gentwo.org \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=hannes@cmpxchg.org \
    --cc=hao.li@linux.dev \
    --cc=harry@kernel.org \
    --cc=jackmanb@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=ryabinin.a.a@gmail.com \
    --cc=ryan.roberts@arm.com \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=vincenzo.frascino@arm.com \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome