From: Shuai Liu <847807867@qq.com>
To: Jakub Kicinski <kuba@kernel.org>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Paolo Abeni <pabeni@redhat.com>
Cc: Jiri Pirko <jiri@resnulli.us>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
syzbot+b3fca27eb4005f0111f4@syzkaller.appspotmail.com,
Shuai Liu <847807867@qq.com>
Subject: [PATCH] netdevsim: fix NULL deref in port attrs after unbind
Date: Sat, 7 Nov 2026 17:20:09 +0800 [thread overview]
Message-ID: <tencent_C7E2CBFD5E5A8E8541FEA08915F742EC6405@qq.com> (raw)
The new_port and del_port device attributes call nsim_drv_port_add() and
nsim_drv_port_del(), which fetch the driver private data with
dev_get_drvdata(). If the device has been unbound from the driver, that
private data is NULL and priv_to_devlink() turns it into a bogus pointer,
so a write to either attribute faults in devl_lock():
BUG: unable to handle page fault for address: fffffffffffffeb0
RIP: 0010:__lock_acquire
Call Trace:
...
nsim_drv_port_add
new_port_store
sriov_numvfs_store() already guards against this by taking device_lock()
and checking dev_get_drvdata(). Do the same in new_port_store() and
del_port_store(). Holding device_lock() also prevents the private data
from going away between the check and its use.
Fixes: 794b2c05ca1c ("netdevsim: extend device attrs to support port addition and deletion")
Reported-by: syzbot+b3fca27eb4005f0111f4@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=b3fca27eb4005f0111f4
Signed-off-by: Shuai Liu <847807867@qq.com>
---
Tested with the syzbot C reproducer on x86-64 QEMU using a KASAN +
lockdep kernel: without this patch the kernel panics in
nsim_drv_port_add() with a page fault at 0xffffffffffffef0; with it, the
write to new_port returns -ENOENT, the concurrent create/unbind/delete
race loop completes without a report, and adding/deleting a port on a
bound device still works.
AI assistance disclosure: the root-cause analysis and the draft patch
were produced with an AI coding assistant from the syzbot report; the
change was compiled, checkpatch-tested and runtime-verified as described
above.
---
drivers/net/netdevsim/bus.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c
index b792ee10b1c1..abcd0f38d85c 100644
--- a/drivers/net/netdevsim/bus.c
+++ b/drivers/net/netdevsim/bus.c
@@ -93,8 +93,13 @@ 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 +120,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.53.0
reply other threads:[~2026-11-07 9:20 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=tencent_C7E2CBFD5E5A8E8541FEA08915F742EC6405@qq.com \
--to=847807867@qq.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=syzbot+b3fca27eb4005f0111f4@syzkaller.appspotmail.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®