linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH for-rc] RDMA/siw: Fix failure handling during device creation
@ 2020-02-26 14:29 Bernard Metzler
  2020-02-28 16:17 ` Jason Gunthorpe
  0 siblings, 1 reply; 2+ messages in thread
From: Bernard Metzler @ 2020-02-26 14:29 UTC (permalink / raw)
  To: dledford, jgg, linux-kernel, linux-rdma, netdev, syzkaller-bugs
  Cc: Bernard Metzler

A failing call to ib_device_set_netdev() during device creation
caused system crash due to xa_destroy of uninitialized xarray
hit by device deallocation. Fixed by moving xarray initialization
before potential device deallocation.
Fixes also correct propagation of ib_device_set_netdev() failure
to caller.

Reported-by: syzbot+2e80962bedd9559fe0b3@syzkaller.appspotmail.com
Signed-off-by: Bernard Metzler <bmt@zurich.ibm.com>
---
 drivers/infiniband/sw/siw/siw_main.c | 39 ++++++++++++++--------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/drivers/infiniband/sw/siw/siw_main.c b/drivers/infiniband/sw/siw/siw_main.c
index 96ed349c0939..839decfd9032 100644
--- a/drivers/infiniband/sw/siw/siw_main.c
+++ b/drivers/infiniband/sw/siw/siw_main.c
@@ -303,7 +303,7 @@ static const struct ib_device_ops siw_device_ops = {
 
 static struct siw_device *siw_device_create(struct net_device *netdev)
 {
-	struct siw_device *sdev = NULL;
+	struct siw_device *sdev;
 	struct ib_device *base_dev;
 	struct device *parent = netdev->dev.parent;
 	int rv;
@@ -319,13 +319,13 @@ static struct siw_device *siw_device_create(struct net_device *netdev)
 		if (netdev->type != ARPHRD_LOOPBACK) {
 			pr_warn("siw: device %s error: no parent device\n",
 				netdev->name);
-			return NULL;
+			return ERR_PTR(-EINVAL);
 		}
 		parent = &netdev->dev;
 	}
 	sdev = ib_alloc_device(siw_device, base_dev);
 	if (!sdev)
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 
 	base_dev = &sdev->base_dev;
 
@@ -388,6 +388,9 @@ static struct siw_device *siw_device_create(struct net_device *netdev)
 		{ .max_segment_size = SZ_2G };
 	base_dev->num_comp_vectors = num_possible_cpus();
 
+	xa_init_flags(&sdev->qp_xa, XA_FLAGS_ALLOC1);
+	xa_init_flags(&sdev->mem_xa, XA_FLAGS_ALLOC1);
+
 	ib_set_device_ops(base_dev, &siw_device_ops);
 	rv = ib_device_set_netdev(base_dev, netdev, 1);
 	if (rv)
@@ -415,9 +418,6 @@ static struct siw_device *siw_device_create(struct net_device *netdev)
 	sdev->attrs.max_srq_wr = SIW_MAX_SRQ_WR;
 	sdev->attrs.max_srq_sge = SIW_MAX_SGE;
 
-	xa_init_flags(&sdev->qp_xa, XA_FLAGS_ALLOC1);
-	xa_init_flags(&sdev->mem_xa, XA_FLAGS_ALLOC1);
-
 	INIT_LIST_HEAD(&sdev->cep_list);
 	INIT_LIST_HEAD(&sdev->qp_list);
 
@@ -435,7 +435,7 @@ static struct siw_device *siw_device_create(struct net_device *netdev)
 error:
 	ib_dealloc_device(base_dev);
 
-	return NULL;
+	return ERR_PTR(rv);
 }
 
 /*
@@ -542,8 +542,8 @@ static struct notifier_block siw_netdev_nb = {
 static int siw_newlink(const char *basedev_name, struct net_device *netdev)
 {
 	struct ib_device *base_dev;
-	struct siw_device *sdev = NULL;
-	int rv = -ENOMEM;
+	struct siw_device *sdev;
+	int rv;
 
 	if (!siw_dev_qualified(netdev))
 		return -EINVAL;
@@ -554,18 +554,19 @@ static int siw_newlink(const char *basedev_name, struct net_device *netdev)
 		return -EEXIST;
 	}
 	sdev = siw_device_create(netdev);
-	if (sdev) {
-		dev_dbg(&netdev->dev, "siw: new device\n");
+	if (IS_ERR(sdev))
+		return PTR_ERR(sdev);
 
-		if (netif_running(netdev) && netif_carrier_ok(netdev))
-			sdev->state = IB_PORT_ACTIVE;
-		else
-			sdev->state = IB_PORT_DOWN;
+	dev_dbg(&netdev->dev, "siw: new device\n");
 
-		rv = siw_device_register(sdev, basedev_name);
-		if (rv)
-			ib_dealloc_device(&sdev->base_dev);
-	}
+	if (netif_running(netdev) && netif_carrier_ok(netdev))
+		sdev->state = IB_PORT_ACTIVE;
+	else
+		sdev->state = IB_PORT_DOWN;
+
+	rv = siw_device_register(sdev, basedev_name);
+	if (rv)
+		ib_dealloc_device(&sdev->base_dev);
 	return rv;
 }
 
-- 
2.17.2


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

* Re: [PATCH for-rc] RDMA/siw: Fix failure handling during device creation
  2020-02-26 14:29 [PATCH for-rc] RDMA/siw: Fix failure handling during device creation Bernard Metzler
@ 2020-02-28 16:17 ` Jason Gunthorpe
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Gunthorpe @ 2020-02-28 16:17 UTC (permalink / raw)
  To: Bernard Metzler
  Cc: dledford, linux-kernel, linux-rdma, netdev, syzkaller-bugs

On Wed, Feb 26, 2020 at 03:29:20PM +0100, Bernard Metzler wrote:
> A failing call to ib_device_set_netdev() during device creation
> caused system crash due to xa_destroy of uninitialized xarray
> hit by device deallocation. Fixed by moving xarray initialization
> before potential device deallocation.
> Fixes also correct propagation of ib_device_set_netdev() failure
> to caller.

This is for -rc, so please split into two patches. The error
propagation is probably not -rc worthy

Jason

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

end of thread, other threads:[~2020-02-28 16:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-26 14:29 [PATCH for-rc] RDMA/siw: Fix failure handling during device creation Bernard Metzler
2020-02-28 16:17 ` Jason Gunthorpe

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