Skip to contentSkip to conversation

RDMA/core: fix UAF in ib_get_eth_speed

PATCH In review Denis Kirjanov 5 participants 5 messages Mar 28, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 RDMA/core: fix UAF in ib_get_eth_speed

A call to ib_device_get_netdev from ib_get_eth_speed may lead to a race condition while accessing a netdevice instance since we don't hold the rtnl lock while checking the registration state:

	if (res && res->reg_state != NETREG_REGISTERED) {

v2: unlock rtnl on error patch

Reported-by [email protected]
Fixes d41861942fc55 ("IB/core: Add generic function to extract IB speed from netdev")
---
 drivers/infiniband/core/verbs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/infiniband/core/verbs.c +4 -2
index 94a7f3b0c71c..9c09d8c328b4 100644
@@ -1976,11 +1976,13 @@ int ib_get_eth_speed(struct ib_device *dev, u32 port_num, u16 *speed, u8 *width)
 	if (rdma_port_get_link_layer(dev, port_num) != IB_LINK_LAYER_ETHERNET)
 		return -EINVAL;
 
+	rtnl_lock();
 	netdev = ib_device_get_netdev(dev, port_num);
-	if (!netdev)
+	if (!netdev) {
+		rtnl_unlock()
 		return -ENODEV;
+	}
 
-	rtnl_lock();
 	rc = __ethtool_get_link_ksettings(netdev, &lksettings);
 	rtnl_unlock();
 
Signature · 1 line
2.30.2
#1 lore raw
Quoted 9 lines · Denis Kirjanov

A call to ib_device_get_netdev from ib_get_eth_speed may lead to a race condition while accessing a netdevice instance since we don't hold the rtnl lock while checking the registration state:

        if (res && res->reg_state != NETREG_REGISTERED) {

v2: unlock rtnl on error patch

What about other callers of ib_device_get_netdev() ?

It seems they also could be racy.

Quoted 30 lines
Reported-by [email protected]
Fixes d41861942fc55 ("IB/core: Add generic function to extract IB speed from netdev")
---
 drivers/infiniband/core/verbs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/infiniband/core/verbs.c +4 -3
index 94a7f3b0c71c..9c09d8c328b4 100644
@@ -1976,11 +1976,13 @@ int ib_get_eth_speed(struct ib_device *dev, u32 port_num, u16 *speed, u8 *width)
        if (rdma_port_get_link_layer(dev, port_num) != IB_LINK_LAYER_ETHERNET)
                return -EINVAL;
 
+       rtnl_lock();
        netdev = ib_device_get_netdev(dev, port_num);
-       if (!netdev)
+       if (!netdev) {
+               rtnl_unlock()
                return -ENODEV;
+       }
 
-       rtnl_lock();
        rc = __ethtool_get_link_ksettings(netdev, &lksettings);
        rtnl_unlock();
 
--

2.30.2

#2 lore raw
Quoted 8 lines · Eric Dumazet
Quoted 7 lines · Denis Kirjanov

A call to ib_device_get_netdev from ib_get_eth_speed may lead to a race condition while accessing a netdevice instance since we don't hold the rtnl lock while checking the registration state:

        if (res && res->reg_state != NETREG_REGISTERED) {
Quoted 4 lines
Quoted 2 lines

v2: unlock rtnl on error patch

What about other callers of ib_device_get_netdev() ?

I'll add ASSERT_RTNL() to ib_device_get_netdev and update the remaining callers.

Thanks!

Quoted 33 lines

It seems they also could be racy.

Quoted 30 lines
Reported-by [email protected]
Fixes d41861942fc55 ("IB/core: Add generic function to extract IB speed from netdev")
---
 drivers/infiniband/core/verbs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/infiniband/core/verbs.c +4 -3
index 94a7f3b0c71c..9c09d8c328b4 100644
@@ -1976,11 +1976,13 @@ int ib_get_eth_speed(struct ib_device *dev, u32 port_num, u16 *speed, u8 *width)
        if (rdma_port_get_link_layer(dev, port_num) != IB_LINK_LAYER_ETHERNET)
                return -EINVAL;
 
+       rtnl_lock();
        netdev = ib_device_get_netdev(dev, port_num);
-       if (!netdev)
+       if (!netdev) {
+               rtnl_unlock()
                return -ENODEV;
+       }
 
-       rtnl_lock();
        rc = __ethtool_get_link_ksettings(netdev, &lksettings);
        rtnl_unlock();
 
--

2.30.2

#3 lore raw
In reply to Denis Kirjanov
Quoted 20 lines · Denis Kirjanov

A call to ib_device_get_netdev from ib_get_eth_speed may lead to a race condition while accessing a netdevice instance since we don't hold the rtnl lock while checking the registration state:

	if (res && res->reg_state != NETREG_REGISTERED) {

v2: unlock rtnl on error patch

Reported-by [email protected]
Fixes d41861942fc55 ("IB/core: Add generic function to extract IB speed from netdev")
---
 drivers/infiniband/core/verbs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/infiniband/core/verbs.c +0 -0
index 94a7f3b0c71c..9c09d8c328b4 100644

drivers/infiniband/core/verbs.c int ib_get_eth_speed(struct ib_device *dev, u32 port_num, u16 *speed, u8 *width) · line 1980

Quoted 5 lines
drivers/infiniband/core/verbs.c +1 -0
@@ -1976,11 +1976,13 @@ int ib_get_eth_speed(struct ib_device *dev, u32 port_num, u16 *speed, u8 *width)
 	if (rdma_port_get_link_layer(dev, port_num) != IB_LINK_LAYER_ETHERNET)
 		return -EINVAL;
 
+	rtnl_lock();
 	netdev = ib_device_get_netdev(dev, port_num);

ib_device_get_netdev() hold ref to dev before checking reg_state, isn't it enough ?

Quoted 13 lines
drivers/infiniband/core/verbs.c +3 -3
-	if (!netdev)
+	if (!netdev) {
+		rtnl_unlock()
 		return -ENODEV;
+	}
 
-	rtnl_lock();
 	rc = __ethtool_get_link_ksettings(netdev, &lksettings);
 	rtnl_unlock();
 
--

2.30.2

Reviewed-by on v2 1/1
#4 lore raw
In reply to Denis Kirjanov
Quoted 45 lines

-----Original Message-----
From: Denis Kirjanov <[email protected]>
Sent: Thursday, March 28, 2024 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Denis Kirjanov <[email protected]>; [email protected]
Subject: [PATCH v2 net] RDMA/core: fix UAF in ib_get_eth_speed

A call to ib_device_get_netdev from ib_get_eth_speed may lead to a race condition while accessing a netdevice instance since we don't hold the rtnl lock while checking the registration state:

	if (res && res->reg_state != NETREG_REGISTERED) {

v2: unlock rtnl on error patch

Reported-by [email protected]
Fixes d41861942fc55 ("IB/core: Add generic function to extract IB speed from

netdev")

---
 drivers/infiniband/core/verbs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/infiniband/core/verbs.c index renamed from drivers/infiniband/core/verbs.c +0 -0

94a7f3b0c71c..9c09d8c328b4 100644

drivers/infiniband/core/verbs.c +4 -2
@@ -1976,11 +1976,13 @@ int ib_get_eth_speed(struct ib_device *dev, u32
 port_num, u16 *speed, u8 *width)
 	if (rdma_port_get_link_layer(dev, port_num) !=
 IB_LINK_LAYER_ETHERNET)
 		return -EINVAL;
 
+	rtnl_lock();
 	netdev = ib_device_get_netdev(dev, port_num);
-	if (!netdev)
+	if (!netdev) {
+		rtnl_unlock()
 		return -ENODEV;
+	}
 
-	rtnl_lock();
 	rc = __ethtool_get_link_ksettings(netdev, &lksettings);

rtnl_unlock();

Quoted 3 lines

--
2.30.2