diff mbox series

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

Message ID 20240730185049.6244-2-dakr@kernel.org (mailing list archive)
State New
Headers show
Series (k)vrealloc (__GFP_ZERO) fixes | expand

Commit Message

Danilo Krummrich July 30, 2024, 6:49 p.m. UTC
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(-)

Comments

Andrew Morton July 30, 2024, 9:15 p.m. UTC | #1
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.
Danilo Krummrich July 30, 2024, 10:47 p.m. UTC | #2
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.
>
diff mbox series

Patch

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);
 		}
 	}