Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH net] net: ethernet: mlx4: Fix memory allocation in mlx4_buddy_init()
@ 2020-08-31 14:37 Shung-Hsi Yu
  2020-09-01 20:13 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Shung-Hsi Yu @ 2020-08-31 14:37 UTC (permalink / raw)
  To: David S. Miller, Tariq Toukan, Jakub Kicinski
  Cc: netdev, linux-rdma, linux-kernel

On machines with much memory (> 2 TByte) and log_mtts_per_seg == 0, a
max_order of 31 will be passed to mlx_buddy_init(), which results in
s = BITS_TO_LONGS(1 << 31) becoming a negative value, leading to
kvmalloc_array() failure when it is converted to size_t.

  mlx4_core 0000:b1:00.0: Failed to initialize memory region table, aborting
  mlx4_core: probe of 0000:b1:00.0 failed with error -12

Fix this issue by changing the left shifting operand from a signed literal to
an unsigned one.

Fixes: 225c7b1feef1 ("IB/mlx4: Add a driver Mellanox ConnectX InfiniBand adapters")
Signed-off-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>
---
 drivers/net/ethernet/mellanox/mlx4/mr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/mr.c b/drivers/net/ethernet/mellanox/mlx4/mr.c
index d2986f1f2db0..d7444782bfdd 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mr.c
+++ b/drivers/net/ethernet/mellanox/mlx4/mr.c
@@ -114,7 +114,7 @@ static int mlx4_buddy_init(struct mlx4_buddy *buddy, int max_order)
 		goto err_out;
 
 	for (i = 0; i <= buddy->max_order; ++i) {
-		s = BITS_TO_LONGS(1 << (buddy->max_order - i));
+		s = BITS_TO_LONGS(1UL << (buddy->max_order - i));
 		buddy->bits[i] = kvmalloc_array(s, sizeof(long), GFP_KERNEL | __GFP_ZERO);
 		if (!buddy->bits[i])
 			goto err_out_free;
-- 
2.28.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH net] net: ethernet: mlx4: Fix memory allocation in mlx4_buddy_init()
  2020-08-31 14:37 [PATCH net] net: ethernet: mlx4: Fix memory allocation in mlx4_buddy_init() Shung-Hsi Yu
@ 2020-09-01 20:13 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2020-09-01 20:13 UTC (permalink / raw)
  To: shung-hsi.yu; +Cc: tariqt, kuba, netdev, linux-rdma, linux-kernel

From: Shung-Hsi Yu <shung-hsi.yu@suse.com>
Date: Mon, 31 Aug 2020 22:37:09 +0800

> On machines with much memory (> 2 TByte) and log_mtts_per_seg == 0, a
> max_order of 31 will be passed to mlx_buddy_init(), which results in
> s = BITS_TO_LONGS(1 << 31) becoming a negative value, leading to
> kvmalloc_array() failure when it is converted to size_t.
> 
>   mlx4_core 0000:b1:00.0: Failed to initialize memory region table, aborting
>   mlx4_core: probe of 0000:b1:00.0 failed with error -12
> 
> Fix this issue by changing the left shifting operand from a signed literal to
> an unsigned one.
> 
> Fixes: 225c7b1feef1 ("IB/mlx4: Add a driver Mellanox ConnectX InfiniBand adapters")
> Signed-off-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>

Applied and queued up for -stable, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-09-01 20:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-31 14:37 [PATCH net] net: ethernet: mlx4: Fix memory allocation in mlx4_buddy_init() Shung-Hsi Yu
2020-09-01 20:13 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).