linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] IB/mlx4: Test port number before querying type.
@ 2018-07-02 21:02 Tarick Bedeir
  2018-07-03  6:21 ` Leon Romanovsky
  0 siblings, 1 reply; 4+ messages in thread
From: Tarick Bedeir @ 2018-07-02 21:02 UTC (permalink / raw)
  To: Yishai Hadas, Doug Ledford, Jason Gunthorpe
  Cc: edumazet, linux-rdma, linux-kernel, Tarick Bedeir

rdma_ah_find_type() can reach into ib_device->port_immutable with a
potentially out-of-bounds port number, so check that the port number is
valid first.

Fixes: 44c58487d51a ("IB/core: Define 'ib' and 'roce' rdma_ah_attr types")
Signed-off-by: Tarick Bedeir <tarick@google.com>
---
 drivers/infiniband/hw/mlx4/qp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/qp.c
index f045491f2c14..4f1dabecf9a5 100644
--- a/drivers/infiniband/hw/mlx4/qp.c
+++ b/drivers/infiniband/hw/mlx4/qp.c
@@ -4034,9 +4034,9 @@ static void to_rdma_ah_attr(struct mlx4_ib_dev *ibdev,
 	u8 port_num = path->sched_queue & 0x40 ? 2 : 1;
 
 	memset(ah_attr, 0, sizeof(*ah_attr));
-	ah_attr->type = rdma_ah_find_type(&ibdev->ib_dev, port_num);
 	if (port_num == 0 || port_num > dev->caps.num_ports)
 		return;
+	ah_attr->type = rdma_ah_find_type(&ibdev->ib_dev, port_num);
 
 	if (ah_attr->type == RDMA_AH_ATTR_TYPE_ROCE)
 		rdma_ah_set_sl(ah_attr, ((path->sched_queue >> 3) & 0x7) |
-- 
2.18.0.399.gad0ab374a1-goog


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

* Re: [PATCH] IB/mlx4: Test port number before querying type.
  2018-07-02 21:02 [PATCH] IB/mlx4: Test port number before querying type Tarick Bedeir
@ 2018-07-03  6:21 ` Leon Romanovsky
  2018-07-03 14:44   ` Tarick Bedeir
  0 siblings, 1 reply; 4+ messages in thread
From: Leon Romanovsky @ 2018-07-03  6:21 UTC (permalink / raw)
  To: Tarick Bedeir
  Cc: Yishai Hadas, Doug Ledford, Jason Gunthorpe, edumazet,
	linux-rdma, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1373 bytes --]

On Mon, Jul 02, 2018 at 02:02:34PM -0700, Tarick Bedeir wrote:
> rdma_ah_find_type() can reach into ib_device->port_immutable with a
> potentially out-of-bounds port number, so check that the port number is
> valid first.
>
> Fixes: 44c58487d51a ("IB/core: Define 'ib' and 'roce' rdma_ah_attr types")
> Signed-off-by: Tarick Bedeir <tarick@google.com>
> ---
>  drivers/infiniband/hw/mlx4/qp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/qp.c
> index f045491f2c14..4f1dabecf9a5 100644
> --- a/drivers/infiniband/hw/mlx4/qp.c
> +++ b/drivers/infiniband/hw/mlx4/qp.c
> @@ -4034,9 +4034,9 @@ static void to_rdma_ah_attr(struct mlx4_ib_dev *ibdev,
>  	u8 port_num = path->sched_queue & 0x40 ? 2 : 1;
>
>  	memset(ah_attr, 0, sizeof(*ah_attr));
> -	ah_attr->type = rdma_ah_find_type(&ibdev->ib_dev, port_num);
>  	if (port_num == 0 || port_num > dev->caps.num_ports)

Did you get any warning from any checker about out-of-bounds access?

According to the line above, port_num can be 2 or 1 which are valid ports for mlx4
and the check above doesn't do much.

>  		return;
> +	ah_attr->type = rdma_ah_find_type(&ibdev->ib_dev, port_num);
>
>  	if (ah_attr->type == RDMA_AH_ATTR_TYPE_ROCE)
>  		rdma_ah_set_sl(ah_attr, ((path->sched_queue >> 3) & 0x7) |
> --
> 2.18.0.399.gad0ab374a1-goog
>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

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

* Re: [PATCH] IB/mlx4: Test port number before querying type.
  2018-07-03  6:21 ` Leon Romanovsky
@ 2018-07-03 14:44   ` Tarick Bedeir
  2018-07-04 11:25     ` Leon Romanovsky
  0 siblings, 1 reply; 4+ messages in thread
From: Tarick Bedeir @ 2018-07-03 14:44 UTC (permalink / raw)
  To: leon; +Cc: Yishai Hadas, dledford, jgg, Eric Dumazet, linux-rdma, linux-kernel

On Mon, Jul 2, 2018 at 11:21 PM Leon Romanovsky <leon@kernel.org> wrote:
>
> On Mon, Jul 02, 2018 at 02:02:34PM -0700, Tarick Bedeir wrote:
> > rdma_ah_find_type() can reach into ib_device->port_immutable with a
> > potentially out-of-bounds port number, so check that the port number is
> > valid first.
> >
> > Fixes: 44c58487d51a ("IB/core: Define 'ib' and 'roce' rdma_ah_attr types")
> > Signed-off-by: Tarick Bedeir <tarick@google.com>
> > ---
> >  drivers/infiniband/hw/mlx4/qp.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/qp.c
> > index f045491f2c14..4f1dabecf9a5 100644
> > --- a/drivers/infiniband/hw/mlx4/qp.c
> > +++ b/drivers/infiniband/hw/mlx4/qp.c
> > @@ -4034,9 +4034,9 @@ static void to_rdma_ah_attr(struct mlx4_ib_dev *ibdev,
> >       u8 port_num = path->sched_queue & 0x40 ? 2 : 1;
> >
> >       memset(ah_attr, 0, sizeof(*ah_attr));
> > -     ah_attr->type = rdma_ah_find_type(&ibdev->ib_dev, port_num);
> >       if (port_num == 0 || port_num > dev->caps.num_ports)
>
> Did you get any warning from any checker about out-of-bounds access?

Indeed, I observed a KASAN warning for an out-of-bounds read in
to_rdma_ah_attr().

> According to the line above, port_num can be 2 or 1 which are valid ports for mlx4
> and the check above doesn't do much.

There are mlx4 devices with only one port.

>
> >               return;
> > +     ah_attr->type = rdma_ah_find_type(&ibdev->ib_dev, port_num);
> >
> >       if (ah_attr->type == RDMA_AH_ATTR_TYPE_ROCE)
> >               rdma_ah_set_sl(ah_attr, ((path->sched_queue >> 3) & 0x7) |
> > --
> > 2.18.0.399.gad0ab374a1-goog
> >

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

* Re: [PATCH] IB/mlx4: Test port number before querying type.
  2018-07-03 14:44   ` Tarick Bedeir
@ 2018-07-04 11:25     ` Leon Romanovsky
  0 siblings, 0 replies; 4+ messages in thread
From: Leon Romanovsky @ 2018-07-04 11:25 UTC (permalink / raw)
  To: Tarick Bedeir
  Cc: Yishai Hadas, dledford, jgg, Eric Dumazet, linux-rdma, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1648 bytes --]

On Tue, Jul 03, 2018 at 07:44:25AM -0700, Tarick Bedeir wrote:
> On Mon, Jul 2, 2018 at 11:21 PM Leon Romanovsky <leon@kernel.org> wrote:
> >
> > On Mon, Jul 02, 2018 at 02:02:34PM -0700, Tarick Bedeir wrote:
> > > rdma_ah_find_type() can reach into ib_device->port_immutable with a
> > > potentially out-of-bounds port number, so check that the port number is
> > > valid first.
> > >
> > > Fixes: 44c58487d51a ("IB/core: Define 'ib' and 'roce' rdma_ah_attr types")
> > > Signed-off-by: Tarick Bedeir <tarick@google.com>
> > > ---
> > >  drivers/infiniband/hw/mlx4/qp.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/qp.c
> > > index f045491f2c14..4f1dabecf9a5 100644
> > > --- a/drivers/infiniband/hw/mlx4/qp.c
> > > +++ b/drivers/infiniband/hw/mlx4/qp.c
> > > @@ -4034,9 +4034,9 @@ static void to_rdma_ah_attr(struct mlx4_ib_dev *ibdev,
> > >       u8 port_num = path->sched_queue & 0x40 ? 2 : 1;
> > >
> > >       memset(ah_attr, 0, sizeof(*ah_attr));
> > > -     ah_attr->type = rdma_ah_find_type(&ibdev->ib_dev, port_num);
> > >       if (port_num == 0 || port_num > dev->caps.num_ports)
> >
> > Did you get any warning from any checker about out-of-bounds access?
>
> Indeed, I observed a KASAN warning for an out-of-bounds read in
> to_rdma_ah_attr().
>
> > According to the line above, port_num can be 2 or 1 which are valid ports for mlx4
> > and the check above doesn't do much.
>
> There are mlx4 devices with only one port.

Thanks, I never saw such device, but found one on ebay :).

Reviewed-by: Leon Romanovsky <leonro@mellanox.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

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

end of thread, other threads:[~2018-07-04 11:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-02 21:02 [PATCH] IB/mlx4: Test port number before querying type Tarick Bedeir
2018-07-03  6:21 ` Leon Romanovsky
2018-07-03 14:44   ` Tarick Bedeir
2018-07-04 11:25     ` Leon Romanovsky

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).