git: 880b670c6fdb - main - malloc: Unmark KASAN redzones if the full allocation size was requested

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Wed, 06 Oct 2021 20:09:53 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=880b670c6fdbd1268887869375771e0a74d2c8ac

commit 880b670c6fdbd1268887869375771e0a74d2c8ac
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2021-10-06 20:03:30 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2021-10-06 20:09:41 +0000

    malloc: Unmark KASAN redzones if the full allocation size was requested
    
    Consumers that want the full allocation size will typically access the
    full buffer, so mark the entire allocation as valid to avoid useless
    KASAN reports.
    
    Sponsored by:   The FreeBSD Foundation
---
 sys/kern/kern_malloc.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index b1c5909db2a4..4ecdcdacce01 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -1112,6 +1112,13 @@ malloc_usable_size(const void *addr)
 	else
 		size = malloc_large_size(slab);
 #endif
+
+	/*
+	 * Unmark the redzone to avoid reports from consumers who are
+	 * (presumably) about to use the full allocation size.
+	 */
+	kasan_mark(addr, size, size, 0);
+
 	return (size);
 }