Thread (36 messages) 36 messages, 9 authors, 2022-10-01
STALE1383d
Revisions (2)
  1. v1 [diff vs current]
  2. v2 current

[PATCH v2 12/16] devres: Use kmalloc_size_roundup() to match ksize() usage

From: Kees Cook <hidden>
Date: 2022-09-23 20:34:55
Also in: dri-devel, intel-wired-lan, linux-btrfs, linux-fsdevel, linux-hardening, linux-media, linux-mm, lkml, llvm
Subsystem: driver core, kobjects, debugfs and sysfs, the rest · Maintainers: Greg Kroah-Hartman, "Rafael J. Wysocki", Danilo Krummrich, Linus Torvalds

Round up allocations with kmalloc_size_roundup() so that devres's use
of ksize() is always accurate and no special handling of the memory is
needed by KASAN, UBSAN_BOUNDS, nor FORTIFY_SOURCE.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: Kees Cook <redacted>
---
 drivers/base/devres.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index 864d0b3f566e..7db20ce7ea8a 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -101,6 +101,9 @@ static bool check_dr_size(size_t size, size_t *tot_size)
 					size, tot_size)))
 		return false;
 
+	/* Actually allocate the full kmalloc bucket size. */
+	*tot_size = kmalloc_size_roundup(*tot_size);
+
 	return true;
 }
 
-- 
2.34.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help