RDMA/hns: Prevent undefined behavior in hns_roce_set_user_sq_size()
authorJason Gunthorpe <jgg@mellanox.com>
Sat, 8 Jun 2019 09:25:14 +0000 (12:25 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 17 Jan 2020 18:48:35 +0000 (19:48 +0100)
commit9fe3a5a5c082f6531a14e4b3f7766443c0f91e2b
treeb5802a6d117754c267f7ff7fdaada4be1210f82f
parent9677ee580027a8d2db4a579fd65d34a8e5e912f2
RDMA/hns: Prevent undefined behavior in hns_roce_set_user_sq_size()

commit 515f60004ed985d2b2f03659365752e0b6142986 upstream.

The "ucmd->log_sq_bb_count" variable is a user controlled variable in the
0-255 range.  If we shift more than then number of bits in an int then
it's undefined behavior (it shift wraps), and potentially the int could
become negative.

Fixes: 9a4435375cd1 ("IB/hns: Add driver files for hns RoCE driver")
Link: https://lore.kernel.org/r/20190608092514.GC28890@mwanda
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/infiniband/hw/hns/hns_roce_qp.c