Thread View: muc.lists.freebsd.bugs
1 messages
1 total messages
Started by bugzilla-noreply
Sun, 29 Nov 2026 13:58
[Bug 301264] newbus: Device sysctl handlers may outlive the device softc
Author: bugzilla-noreply
Date: Sun, 29 Nov 2026 13:58
Date: Sun, 29 Nov 2026 13:58
67 lines
3853 bytes
3853 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301264
Bug ID: 301264
Summary: newbus: Device sysctl handlers may outlive the device
softc
Product: Base System
Version: 16.0-CURRENT
Hardware: Any
OS: Any
Status: New
Severity: Affects Only Me
Priority: ---
Component: kern
Assignee: bugs@FreeBSD.org
Reporter: takawata@FreeBSD.org
Since `device_sysctl_fini()` is called after `device_set_driver(dev, NULL)`,
sysctl handlers may access the softc even after it has been freed.
Furthermore, sysctl handlers may access other resources while or after they are
released by `DEVICE_DETACH()`.
I had to work around this issue in D57767 by maintaining a separate
`sysctl_ctx_list` instead of using `device_get_sysctl_ctx()`.
One possible solution would be to introduce two new functions:
- `sysctl_ctx_quiesce()`: Prevent new invocations of sysctl handlers associated
with the context and drain all currently running handlers.
- `sysctl_ctx_resume()`: Allow subsequent invocations of those handlers again.
The detach sequence could then look something like this (simplified):
```
error = sysctl_ctx_quiesce(&dev->sysctl_ctx);
if (error != 0)
return (error);
error = DEVICE_DETACH(dev);
if (error != 0) {
sysctl_ctx_resume(&dev->sysctl_ctx);
return (error);
}
device_sysctl_fini(dev);
device_set_driver(dev, NULL);
```
This would allow drivers to safely release resources referenced by sysctl
handlers during `DEVICE_DETACH()`, without having to maintain their own sysctl
contexts solely for this purpose.
The attach failure path and locking implications would also need to be
considered.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads