* [PATCH] RDMA/mlx4: Remove unnessesary check in mlx4_ib_modify_wq()
@ 2021-05-07 10:22 Jiapeng Chong
2021-05-09 8:58 ` Leon Romanovsky
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Jiapeng Chong @ 2021-05-07 10:22 UTC (permalink / raw)
To: yishaih; +Cc: dledford, jgg, linux-rdma, linux-kernel, Jiapeng Chong
cur_state and new_state are enums and when GCC considers
them as unsigned, the conditions are never met.
Clean up the following smatch warning:
drivers/infiniband/hw/mlx4/qp.c:4258 mlx4_ib_modify_wq() warn: unsigned
'cur_state' is never less than zero.
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
drivers/infiniband/hw/mlx4/qp.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/qp.c
index 92ddbcc..162aa59 100644
--- a/drivers/infiniband/hw/mlx4/qp.c
+++ b/drivers/infiniband/hw/mlx4/qp.c
@@ -4255,8 +4255,7 @@ int mlx4_ib_modify_wq(struct ib_wq *ibwq, struct ib_wq_attr *wq_attr,
ibwq->state;
new_state = wq_attr_mask & IB_WQ_STATE ? wq_attr->wq_state : cur_state;
- if (cur_state < IB_WQS_RESET || cur_state > IB_WQS_ERR ||
- new_state < IB_WQS_RESET || new_state > IB_WQS_ERR)
+ if (cur_state > IB_WQS_ERR || new_state > IB_WQS_ERR)
return -EINVAL;
if ((new_state == IB_WQS_RDY) && (cur_state == IB_WQS_ERR))
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] RDMA/mlx4: Remove unnessesary check in mlx4_ib_modify_wq()
2021-05-07 10:22 [PATCH] RDMA/mlx4: Remove unnessesary check in mlx4_ib_modify_wq() Jiapeng Chong
@ 2021-05-09 8:58 ` Leon Romanovsky
2021-05-09 9:40 ` Leon Romanovsky
2021-05-11 17:43 ` Jason Gunthorpe
2 siblings, 0 replies; 5+ messages in thread
From: Leon Romanovsky @ 2021-05-09 8:58 UTC (permalink / raw)
To: Jiapeng Chong; +Cc: yishaih, dledford, jgg, linux-rdma, linux-kernel
On Fri, May 07, 2021 at 06:22:41PM +0800, Jiapeng Chong wrote:
> cur_state and new_state are enums and when GCC considers
> them as unsigned, the conditions are never met.
>
> Clean up the following smatch warning:
>
> drivers/infiniband/hw/mlx4/qp.c:4258 mlx4_ib_modify_wq() warn: unsigned
> 'cur_state' is never less than zero.
>
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
> drivers/infiniband/hw/mlx4/qp.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
Thanks,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] RDMA/mlx4: Remove unnessesary check in mlx4_ib_modify_wq()
2021-05-07 10:22 [PATCH] RDMA/mlx4: Remove unnessesary check in mlx4_ib_modify_wq() Jiapeng Chong
2021-05-09 8:58 ` Leon Romanovsky
@ 2021-05-09 9:40 ` Leon Romanovsky
2021-05-11 17:43 ` Jason Gunthorpe
2 siblings, 0 replies; 5+ messages in thread
From: Leon Romanovsky @ 2021-05-09 9:40 UTC (permalink / raw)
To: Jiapeng Chong; +Cc: yishaih, dledford, jgg, linux-rdma, linux-kernel
On Fri, May 07, 2021 at 06:22:41PM +0800, Jiapeng Chong wrote:
> cur_state and new_state are enums and when GCC considers
> them as unsigned, the conditions are never met.
>
> Clean up the following smatch warning:
>
> drivers/infiniband/hw/mlx4/qp.c:4258 mlx4_ib_modify_wq() warn: unsigned
> 'cur_state' is never less than zero.
>
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
> drivers/infiniband/hw/mlx4/qp.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/qp.c
> index 92ddbcc..162aa59 100644
> --- a/drivers/infiniband/hw/mlx4/qp.c
> +++ b/drivers/infiniband/hw/mlx4/qp.c
> @@ -4255,8 +4255,7 @@ int mlx4_ib_modify_wq(struct ib_wq *ibwq, struct ib_wq_attr *wq_attr,
> ibwq->state;
> new_state = wq_attr_mask & IB_WQ_STATE ? wq_attr->wq_state : cur_state;
>
> - if (cur_state < IB_WQS_RESET || cur_state > IB_WQS_ERR ||
> - new_state < IB_WQS_RESET || new_state > IB_WQS_ERR)
> + if (cur_state > IB_WQS_ERR || new_state > IB_WQS_ERR)
> return -EINVAL;
Actually the more robust change will be to move this change to the ib_uverbs_ex_modify_wq().
Thanks
>
> if ((new_state == IB_WQS_RDY) && (cur_state == IB_WQS_ERR))
> --
> 1.8.3.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] RDMA/mlx4: Remove unnessesary check in mlx4_ib_modify_wq()
2021-05-07 10:22 [PATCH] RDMA/mlx4: Remove unnessesary check in mlx4_ib_modify_wq() Jiapeng Chong
2021-05-09 8:58 ` Leon Romanovsky
2021-05-09 9:40 ` Leon Romanovsky
@ 2021-05-11 17:43 ` Jason Gunthorpe
2021-05-18 7:05 ` Leon Romanovsky
2 siblings, 1 reply; 5+ messages in thread
From: Jason Gunthorpe @ 2021-05-11 17:43 UTC (permalink / raw)
To: Jiapeng Chong; +Cc: yishaih, dledford, linux-rdma, linux-kernel
On Fri, May 07, 2021 at 06:22:41PM +0800, Jiapeng Chong wrote:
> cur_state and new_state are enums and when GCC considers
> them as unsigned, the conditions are never met.
But doesn't gcc consider enums to be 'int' as the standard requires?
This change looks really sketchy to me, cur_state and new_state are
both userspace controlled data. We should not make assumptions about
the underlying signedness of an enum when validating user data.
Jason
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] RDMA/mlx4: Remove unnessesary check in mlx4_ib_modify_wq()
2021-05-11 17:43 ` Jason Gunthorpe
@ 2021-05-18 7:05 ` Leon Romanovsky
0 siblings, 0 replies; 5+ messages in thread
From: Leon Romanovsky @ 2021-05-18 7:05 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Jiapeng Chong, yishaih, dledford, linux-rdma, linux-kernel
On Tue, May 11, 2021 at 02:43:02PM -0300, Jason Gunthorpe wrote:
> On Fri, May 07, 2021 at 06:22:41PM +0800, Jiapeng Chong wrote:
> > cur_state and new_state are enums and when GCC considers
> > them as unsigned, the conditions are never met.
>
> But doesn't gcc consider enums to be 'int' as the standard requires?
Ohh, I missed that.
>
> This change looks really sketchy to me, cur_state and new_state are
> both userspace controlled data. We should not make assumptions about
> the underlying signedness of an enum when validating user data.
I still think that the right change should be in
ib_uverbs_ex_modify_wq(), so both mlx4 and mlx5 will be protected.
Thanks
>
> Jason
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-05-18 7:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-07 10:22 [PATCH] RDMA/mlx4: Remove unnessesary check in mlx4_ib_modify_wq() Jiapeng Chong
2021-05-09 8:58 ` Leon Romanovsky
2021-05-09 9:40 ` Leon Romanovsky
2021-05-11 17:43 ` Jason Gunthorpe
2021-05-18 7:05 ` Leon Romanovsky
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.