Article View: muc.lists.freebsd.bugs
Article #845[Bug 301264] newbus: Device sysctl handlers may outlive the device softc
From: 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
Technical Details
Message-ID:
<bug-301264-227@https.bugs.freebsd.org/bugzilla/>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail From: bugzilla-noreply@freebsd.org Newsgroups: muc.lists.freebsd.bugs Subject: [Bug 301264] newbus: Device sysctl handlers may outlive the device softc Date: Sun, 29 Nov 2026 13:58:23 +0000 Organization: Newsgate at muc.de e.V. Approved: news-admin@muc.de Distribution: world Message-ID: <bug-301264-227@https.bugs.freebsd.org/bugzilla/> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2"; logging-data="5455"; mail-complaints-to="news-admin@muc.de" X-Original-To: bugs@mlmmj.nyi.freebsd.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795960703; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2uZr6yr0e7A0SatlbAV8s37eui42Zgb9O8cmSR6wUFI=; b=WohMQJNu59+bDfbnX5uYU9skwLhon/DvxPug2I5L2yJpWeHkxC3HUjJrGdBRGC4bt3O5wo Om5/7ddSuQ/1Gj/xVcR+trJuidbQ9u65utBFr0ioB8WFogwwFP62rP++aXcfLxGK0M3hxh RkwtoDUcEpgj2/Co2us5QTnROR2b6EX9cpq+1jQRs/5Ji7/TQX20cC7bmEf7yvkFATpYk+ sVexGBP0lHrLxpmSXf6AYgaH8DycjFCWa0BmNhv1u8SeNWuHEnPgmwXnDdc2rtYCf7QoNi /cag16sJVfe3Z/Z88W94e1aX+m/xKrLMsTtYwQgALLXcCHwqyGRO75kzC6gl1w== X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f Auto-Submitted: auto-generated Precedence: list X-Newsgate-Id: f02c70b8849f+ X-No-Archive: Yes