]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
net/mlx4_core: add sanity check when creating bitmap structure
authorDotan Barak <dotanb@dev.mellanox.co.il>
Thu, 12 Jul 2012 08:40:16 +0000 (11:40 +0300)
committerMukesh Kacker <mukesh.kacker@oracle.com>
Tue, 7 Jul 2015 21:38:11 +0000 (14:38 -0700)
If a user tries to allocate bitmap structure with invalid values, this may
cause a kernel panic.

Signed-off-by: Dotan Barak <dotanb@dev.mellanox.co.il>
Reviewed-by: Yishai Hadas <yishaih@mellanox.com>
(Ported from Mellanox OFED 2.4)

Signed-off-by: Mukesh Kacker <mukesh.kacker@oracle.com>
drivers/net/ethernet/mellanox/mlx4/alloc.c

index 0c51c69f802faf63a849300508ad4e809eeb7e3a..eb6d038f5de900599f0aa0d066575fecadaab902 100644 (file)
@@ -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;