* [PATCH] lkdtm/bugs: combine allocations with kzalloc_flex
@ 2026-03-17 3:15 Rosen Penev
0 siblings, 0 replies; only message in thread
From: Rosen Penev @ 2026-03-17 3:15 UTC (permalink / raw)
To: linux-kernel
Cc: Kees Cook, Arnd Bergmann, Greg Kroah-Hartman,
Gustavo A. R. Silva,
open list:KERNEL HARDENING (not covered by other
areas):Keyword:b__counted_by(_le|_be)?b
Avoid a separate kzalloc_objs call and just use a flexible array member
to do so. Simplifies allocation.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/misc/lkdtm/bugs.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/drivers/misc/lkdtm/bugs.c b/drivers/misc/lkdtm/bugs.c
index e0098f314570..938916e5b53c 100644
--- a/drivers/misc/lkdtm/bugs.c
+++ b/drivers/misc/lkdtm/bugs.c
@@ -515,9 +515,9 @@ struct lkdtm_extra {
struct lkdtm_cb_ptr {
int a, b, c;
int nr_extra;
- char *buf __counted_by_ptr(len);
size_t len;
struct lkdtm_extra *extra __counted_by_ptr(nr_extra);
+ char buf[] __counted_by(len);
};
static noinline void check_ptr_len(struct lkdtm_cb_ptr *p, size_t len)
@@ -533,17 +533,12 @@ static void lkdtm_PTR_BOUNDS(void)
{
struct lkdtm_cb_ptr *inst;
- inst = kzalloc_obj(*inst);
+ inst = kzalloc_flex(*inst, buf, element_count);
if (!inst) {
pr_err("FAIL: could not allocate struct lkdtm_cb_ptr!\n");
return;
}
- inst->buf = kzalloc(element_count, GFP_KERNEL);
- if (!inst->buf) {
- pr_err("FAIL: could not allocate inst->buf!\n");
- return;
- }
inst->len = element_count;
/* Double element_count */
@@ -564,7 +559,6 @@ static void lkdtm_PTR_BOUNDS(void)
ignored = inst->extra[inst->nr_extra].b;
kfree(inst->extra);
- kfree(inst->buf);
kfree(inst);
pr_err("FAIL: survived access of invalid pointer member offset!\n");
--
2.53.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-03-17 3:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-17 3:15 [PATCH] lkdtm/bugs: combine allocations with kzalloc_flex Rosen Penev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®