From: Dotan Barak Date: Thu, 12 Jul 2012 08:40:16 +0000 (+0300) Subject: net/mlx4_core: add sanity check when creating bitmap structure X-Git-Tag: v4.1.12-92~319^2^2~6^2~3 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=a6f7793000df068282d07ff732342dd2ea92f17c;p=users%2Fjedix%2Flinux-maple.git net/mlx4_core: add sanity check when creating bitmap structure If a user tries to allocate bitmap structure with invalid values, this may cause a kernel panic. Signed-off-by: Dotan Barak Reviewed-by: Yishai Hadas (Ported from Mellanox OFED 2.4) Signed-off-by: Mukesh Kacker --- diff --git a/drivers/net/ethernet/mellanox/mlx4/alloc.c b/drivers/net/ethernet/mellanox/mlx4/alloc.c index 0c51c69f802f..eb6d038f5de9 100644 --- a/drivers/net/ethernet/mellanox/mlx4/alloc.c +++ b/drivers/net/ethernet/mellanox/mlx4/alloc.c @@ -173,6 +173,10 @@ void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt, int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask, u32 reserved_bot, u32 reserved_top) { + /* sanity check */ + if (num <= (u64)reserved_top + reserved_bot) + return -EINVAL; + /* num must be a power of 2 */ if (num != roundup_pow_of_two(num)) return -EINVAL;