[PATCH 1/2] block: Use struct_size() helper in kmalloc()

From: luoqing

Date: Fri Mar 06 2026 - 03:02:26 EST


From: luoqing <luoqing@xxxxxxxxxx>

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 <luoqing@xxxxxxxxxx>
---
block/bio.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index d80d5d26804e..397fc3bc0ede 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -657,8 +657,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);

--
2.25.1