linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii@kernel.org>
To: linux-mm@kvack.org, akpm@linux-foundation.org, urezki@gmail.com,
	hch@infradead.org
Cc: vbabka@suse.cz, dakr@kernel.org, mhocko@suse.com,
	linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
	ast@kernel.org, Andrii Nakryiko <andrii@kernel.org>
Subject: [PATCH mm/stable] mm: fix vrealloc()'s KASAN poisoning logic
Date: Mon, 25 Nov 2024 16:52:06 -0800	[thread overview]
Message-ID: <20241126005206.3457974-1-andrii@kernel.org> (raw)

When vrealloc() reuses already allocated vmap_area, we need to
re-annotate poisoned and unpoisoned portions of underlying memory
according to the new size.

Note, hard-coding KASAN_VMALLOC_PROT_NORMAL might not be exactly
correct, but KASAN flag logic is pretty involved and spread out
throughout __vmalloc_node_range_noprof(), so I'm using the bare minimum
flag here and leaving the rest to mm people to refactor this logic and
reuse it here.

Fixes: 3ddc2fefe6f3 ("mm: vmalloc: implement vrealloc()")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 mm/vmalloc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 7ed39d104201..f009b21705c1 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -4093,7 +4093,8 @@ void *vrealloc_noprof(const void *p, size_t size, gfp_t flags)
 		/* Zero out spare memory. */
 		if (want_init_on_alloc(flags))
 			memset((void *)p + size, 0, old_size - size);
-
+		kasan_poison_vmalloc(p + size, old_size - size);
+		kasan_unpoison_vmalloc(p, size, KASAN_VMALLOC_PROT_NORMAL);
 		return (void *)p;
 	}
 
-- 
2.43.5



             reply	other threads:[~2024-11-26  0:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-26  0:52 Andrii Nakryiko [this message]
2024-11-28  0:58 ` Andrew Morton
2024-11-28  6:15   ` Andrii Nakryiko
2024-12-04 17:01     ` Alexei Starovoitov
2024-12-04 21:50       ` Andrew Morton
2024-12-04 22:18         ` Alexei Starovoitov

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=20241126005206.3457974-1-andrii@kernel.org \
    --to=andrii@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=dakr@kernel.org \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=urezki@gmail.com \
    --cc=vbabka@suse.cz \
    /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