[PATCH 1/4] mm: kvrealloc: disable KASAN when switching to vmalloc

Danilo Krummrich posted 4 patches 1 year, 4 months ago
[PATCH 1/4] mm: kvrealloc: disable KASAN when switching to vmalloc
Posted by Danilo Krummrich 1 year, 4 months ago
Disable KASAN accessibility checks when switching from a kmalloc buffer
to a vmalloc buffer.

Fixes: 923a26b4c679 ("mm: kvmalloc: align kvrealloc() with krealloc()")
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
 mm/util.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mm/util.c b/mm/util.c
index 29ae93f6344f..bfb2d69b6434 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -753,7 +753,10 @@ void *kvrealloc_noprof(const void *p, size_t size, gfp_t flags)
 
 		if (p) {
 			/* We already know that `p` is not a vmalloc address. */
-			memcpy(n, p, ksize(p));
+			kasan_disable_current();
+			memcpy(n, kasan_reset_tag(p), ksize(p));
+			kasan_enable_current();
+
 			kfree(p);
 		}
 	}
-- 
2.45.2
Re: [PATCH 1/4] mm: kvrealloc: disable KASAN when switching to vmalloc
Posted by Andrew Morton 1 year, 4 months ago
On Tue, 30 Jul 2024 20:49:41 +0200 Danilo Krummrich <dakr@kernel.org> wrote:

> Disable KASAN accessibility checks when switching from a kmalloc buffer
> to a vmalloc buffer.

This text tells us "what", which was utterly evident from a cursory
read of the code.

Please tell us the "why".  Completely.

> Fixes: 923a26b4c679 ("mm: kvmalloc: align kvrealloc() with krealloc()")

For those who are following along, this patch in mm-unstable so this
patch will be squished into the above.
Re: [PATCH 1/4] mm: kvrealloc: disable KASAN when switching to vmalloc
Posted by Danilo Krummrich 1 year, 4 months ago
On Tue, Jul 30, 2024 at 02:15:08PM -0700, Andrew Morton wrote:
> On Tue, 30 Jul 2024 20:49:41 +0200 Danilo Krummrich <dakr@kernel.org> wrote:
> 
> > Disable KASAN accessibility checks when switching from a kmalloc buffer
> > to a vmalloc buffer.
> 
> This text tells us "what", which was utterly evident from a cursory
> read of the code.
> 
> Please tell us the "why".  Completely.

As mentioned in the other reply. Since this is a fixup series for stuff that's
in mm-unstable already, and hence gets squashed in later on, I treated this more
like the list of changes one would also append when sending the next version of
a series.

If you expect such fixup commits to have the same detail than regular ones, I'll
surely add those details and resend. Please let me know.

> 
> > Fixes: 923a26b4c679 ("mm: kvmalloc: align kvrealloc() with krealloc()")
> 
> For those who are following along, this patch in mm-unstable so this
> patch will be squished into the above.
>