From a68d20c9939e23a9ff989e7712f7680a7a185b0a Mon Sep 17 00:00:00 2001 From: luoqing Date: Tue, 26 May 2026 16:56:48 +0800 Subject: [PATCH] block: Use struct_size() helper in kmalloc() Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows. Signed-off-by: luoqing --- block/bio.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/block/bio.c b/block/bio.c index 811a96796202..190446a081a2 100644 --- a/block/bio.c +++ b/block/bio.c @@ -630,8 +630,7 @@ struct bio *bio_kmalloc(unsigned short nr_vecs, gfp_t gfp_mask) if (nr_vecs > BIO_MAX_INLINE_VECS) return NULL; - return kmalloc(sizeof(*bio) + nr_vecs * sizeof(struct bio_vec), - gfp_mask); + return kmalloc(struct_size(bio, bio_vec, nr_vecs), gfp_mask); } EXPORT_SYMBOL(bio_kmalloc);