ipw2x00: Use struct_size helper instead of open-coded arithmetic
Subsystems (3)
PATCH 1/1 ipw2x00: Use struct_size helper instead of open-coded arithmetic
Dynamic size calculations (especially multiplication) should not be performed in memory allocator function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors.
To avoid this scenario, use the struct_size helper.
--- drivers/net/wireless/intel/ipw2x00/libipw_tx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/intel/ipw2x00/libipw_tx.c +2 -2
@@ -179,8 +179,8 @@ static struct libipw_txb *libipw_alloc_txb(int nr_frags, int txb_size, {struct libipw_txb *txb;int i; - txb =kmalloc (sizeof (struct libipw_txb ) + (sizeof (u8 *) * nr_frags), - gfp_mask); + + txb =kmalloc (struct_size (txb, fragments, nr_frags), gfp_mask);if (!txb)return NULL ;
--
2.25.1
Stanislav Yakovlev
maintainerQuoted 8 lines · Len Baker
Dynamic size calculations (especially multiplication) should not be performed in memory allocator function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors.
Quoted 7 lines
To avoid this scenario, use the
struct_sizehelper.Signed-off-by Len Baker <[email protected]>--- drivers/net/wireless/intel/ipw2x00/libipw_tx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Looks fine, thanks!
Stanislav.
Quoted 10 lines · Len Baker
Dynamic size calculations (especially multiplication) should not be performed in memory allocator function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors.
To avoid this scenario, use the
struct_sizehelper.Signed-off-by Len Baker <[email protected]>
Patch applied to wireless-drivers-next.git, thanks.
6f78f4a41ee0 ipw2x00: Use struct_size helper instead of open-coded arithmetic
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches