OpenCloudOS-Kernel/drivers/infiniband/hw/mlx4
Jack Morgenstein b03bcde962 IB/mlx4: Fix integer overflow when calculating optimal MTT size
When the kernel was compiled using the UBSAN option,
we saw the following stack trace:

[ 1184.827917] UBSAN: Undefined behaviour in drivers/infiniband/hw/mlx4/mr.c:349:27
[ 1184.828114] signed integer overflow:
[ 1184.828247] -2147483648 - 1 cannot be represented in type 'int'

The problem was caused by calling round_up in procedure
mlx4_ib_umem_calc_optimal_mtt_size (on line 349, as noted in the stack
trace) with the second parameter (1 << block_shift) (which is an int).
The second parameter should have been (1ULL << block_shift) (which
is an unsigned long long).

(1 << block_shift) is treated by the compiler as an int (because 1 is
an integer).

Now, local variable block_shift is initialized to 31.
If block_shift is 31, 1 << block_shift is 1 << 31 = 0x80000000=-214748368.
This is the most negative int value.

Inside the round_up macro, there is a cast applied to ((1 << 31) - 1).
However, this cast is applied AFTER ((1 << 31) - 1) is calculated.
Since (1 << 31) is treated as an int, we get the negative overflow
identified by UBSAN in the process of calculating ((1 << 31) - 1).

The fix is to change (1 << block_shift) to (1ULL << block_shift) on
line 349.

Fixes: 9901abf583 ("IB/mlx4: Use optimal numbers of MTT entries")
Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2018-05-03 15:31:43 -04:00
..
Kconfig net: mellanox: add DEVLINK dependencies 2016-03-03 17:08:59 -05:00
Makefile IB/mlx4: Add iov directory in sysfs under the ib device 2012-09-30 20:33:39 -07:00
ah.c IB/providers: Avoid null netdev check for RoCE 2018-04-03 21:33:51 -06:00
alias_GUID.c IB/mlx4: Fix some spelling mistakes 2017-08-24 16:27:10 -04:00
cm.c IB/mlx4: Fix CM REQ retries in paravirt mode 2017-07-20 11:20:50 -04:00
cq.c IB/mlx: Set slid to zero in Ethernet completion struct 2018-02-28 12:10:32 -07:00
doorbell.c IB: Refactor umem to use linear SG table 2014-03-04 10:34:28 -08:00
mad.c Add OPA extended LID support 2017-08-18 14:47:37 -04:00
main.c IB/mlx4: Check for egress flow steering 2018-04-04 12:06:24 -06:00
mcg.c IB/mlx4: Suppress gcc 7 fall-through complaints 2017-10-14 20:47:06 -04:00
mlx4_ib.h IB/mlx4: Add Scatter FCS support over WQ creation 2018-03-15 15:58:05 -06:00
mr.c IB/mlx4: Fix integer overflow when calculating optimal MTT size 2018-05-03 15:31:43 -04:00
qp.c RDMA/mlx4: Add missed RSS hash inner header flag 2018-04-27 14:22:23 -04:00
srq.c IB/core: Separate CQ handle in SRQ context 2017-08-29 08:30:16 -04:00
sysfs.c IB/mlx4: fix sprintf format warning 2017-09-13 18:53:15 -07:00