From: "Ömer Mete Kaya" <omermetekaya0@gmail.com>
To: kuba@kernel.org, andrew+netdev@lunn.ch, davem@davemloft.net,
edumazet@google.com, pabeni@redhat.com
Cc: jiri@resnulli.us, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
"Ömer Mete Kaya" <omermetekaya0@gmail.com>
Subject: [PATCH net] netdevsim: take device_lock in new_port and del_port sysfs handlers
Date: Fri, 6 Nov 2026 21:57:54 +0300 [thread overview]
Message-ID: <20261106185840.774601-1-omermetekaya0@gmail.com> (raw)
new_port_store() and del_port_store() access the driver via
dev_get_drvdata() without holding device_lock() or checking for NULL.
The sysfs attributes are attached to the bus device type, so they
remain accessible after the driver is unbound. Writing to new_port or
del_port after unbind causes a NULL dereference or use-after-free.
Protect both handlers with device_lock() and a NULL drvdata check,
matching the existing numvfs_store() pattern.
Discovered by Sashiko, not triggered, not runtime tested.
Fixes: 794b2c05ca1c ("netdevsim: extend device attrs to support port addition and deletion")
Signed-off-by: Ömer Mete Kaya <omermetekaya0@gmail.com>
---
drivers/net/netdevsim/bus.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c
index b792ee10b1c1..822651e00776 100644
--- a/drivers/net/netdevsim/bus.c
+++ b/drivers/net/netdevsim/bus.c
@@ -93,8 +93,14 @@ new_port_store(struct device *dev, struct device_attribute *attr,
return -EINVAL;
}
- ret = nsim_drv_port_add(nsim_bus_dev, NSIM_DEV_PORT_TYPE_PF, port_index,
- addr_set ? eth_addr : NULL);
+ device_lock(dev);
+ ret = -ENOENT;
+ if (dev_get_drvdata(dev))
+ ret = nsim_drv_port_add(nsim_bus_dev,
+ NSIM_DEV_PORT_TYPE_PF, port_index,
+ addr_set ? eth_addr : NULL);
+ device_unlock(dev);
+
return ret ? ret : count;
}
@@ -115,7 +121,13 @@ del_port_store(struct device *dev, struct device_attribute *attr,
if (ret)
return ret;
- ret = nsim_drv_port_del(nsim_bus_dev, NSIM_DEV_PORT_TYPE_PF, port_index);
+ device_lock(dev);
+ ret = -ENOENT;
+ if (dev_get_drvdata(dev))
+ ret = nsim_drv_port_del(nsim_bus_dev,
+ NSIM_DEV_PORT_TYPE_PF, port_index);
+ device_unlock(dev);
+
return ret ? ret : count;
}
--
2.56.0
reply other threads:[~2026-11-06 19:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261106185840.774601-1-omermetekaya0@gmail.com \
--to=omermetekaya0@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®