#
19512355 |
| 09-Feb-2025 |
Zhenlei Huang <zlei@FreeBSD.org> |
sysctl: Harden sysctl_handle_string() against unterminated string
In case a variable string which is not null-terminated is passed in, strlen() may report a length exceeding the max length, hence it
sysctl: Harden sysctl_handle_string() against unterminated string
In case a variable string which is not null-terminated is passed in, strlen() may report a length exceeding the max length, hence it is possible to leak a portion of kernel memory to the userland.
Harden that by using strnlen() to limit the length to the max length. While here, refactor the code a little to improve readability.
Note that, when calculating the out length, the null terminator '\0' of the string is taken into account if available. This is not really necessary but userland applications may have already relied on this behavior.
Reviewed by: avg, kib, olce Fixes: 210176ad76ee sysctl(9): add CTLFLAG_NEEDGIANT flag MFC after: 4 days Differential Revision: https://reviews.freebsd.org/D48881
show more ...
|
Revision tags: release/14.1.0-p7, release/14.2.0-p1, release/13.4.0-p3 |
|
#
faa845aa |
| 25-Jan-2025 |
Zhenlei Huang <zlei@FreeBSD.org> |
kern_sysctl: Fix printing function name in the re-use sysctl leaf warning
The helper function sysctl_warn_reuse() is intended to print the name of the caller rather than that of itself.
PR: 221853
kern_sysctl: Fix printing function name in the re-use sysctl leaf warning
The helper function sysctl_warn_reuse() is intended to print the name of the caller rather than that of itself.
PR: 221853 Fixes: 4ae2ade11426 Enhance debugibility of sysctl leaf re-use warnings MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D48645
show more ...
|
#
7d1d9cc4 |
| 21-Dec-2024 |
Mark Johnston <markj@FreeBSD.org> |
sysctl: Do not serialize requests when running as root
Bugs or unexpected behaviour can cause a user thread to block in a sysctl handler for a long time. "procstat -kka" is the most useful tool to
sysctl: Do not serialize requests when running as root
Bugs or unexpected behaviour can cause a user thread to block in a sysctl handler for a long time. "procstat -kka" is the most useful tool to see why this might happen, but it can block on sysctlmemlock too.
Since the purpose of this lock is merely to ensure userspace can't wire too much memory, don't require it for requests from privileged threads.
PR: 282994 Reviewed by: kib, jhb MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D47842
show more ...
|
Revision tags: release/14.2.0, release/13.4.0, release/14.1.0 |
|
#
d5eae570 |
| 01-May-2024 |
Mark Johnston <markj@FreeBSD.org> |
sysctl: Make sysctl_ctx_free() a bit safer
Clear the list before returning so that sysctl_ctx_free() can be called more than once on the same list without side effects. This simplifies error handli
sysctl: Make sysctl_ctx_free() a bit safer
Clear the list before returning so that sysctl_ctx_free() can be called more than once on the same list without side effects. This simplifies error handling in drivers; previously, drivers would have to be careful to call sysctl_ctx_free() at most once to avoid a use-after-free.
While here, use TAILQ_FOREACH_SAFE in the loop which unregisters OIDs.
Reviewed by: thj, emaste MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D45041
show more ...
|
Revision tags: release/13.3.0 |
|
#
29363fb4 |
| 23-Nov-2023 |
Warner Losh <imp@FreeBSD.org> |
sys: Remove ancient SCCS tags.
Remove ancient SCCS tags from the tree, automated scripting, with two minor fixup to keep things compiling. All the common forms in the tree were removed with a perl s
sys: Remove ancient SCCS tags.
Remove ancient SCCS tags from the tree, automated scripting, with two minor fixup to keep things compiling. All the common forms in the tree were removed with a perl script.
Sponsored by: Netflix
show more ...
|
#
0a713948 |
| 22-Nov-2023 |
Alexander Motin <mav@FreeBSD.org> |
Replace random sbuf_printf() with cheaper cat/putc.
|
Revision tags: release/14.0.0 |
|
#
f80babf9 |
| 23-Sep-2023 |
Alexander Motin <mav@FreeBSD.org> |
kern_sysctl: Make name2oid() non-destructive to the name
It is not the first time I see it panicking while trying to modify const memory. Lets make it safer and easier to use. While there, mark fe
kern_sysctl: Make name2oid() non-destructive to the name
It is not the first time I see it panicking while trying to modify const memory. Lets make it safer and easier to use. While there, mark few functions using it also const.
MFC after: 10 days
show more ...
|
#
cf7974fd |
| 21-Sep-2023 |
Zhenlei Huang <zlei@FreeBSD.org> |
sysctl: Update 'master' copy of vnet SYSCTLs on kernel environment variables change
Complete phase three of 3da1cf1e88f8.
With commit 110113bc086f, vnet sysctl variables can be loader tunable but t
sysctl: Update 'master' copy of vnet SYSCTLs on kernel environment variables change
Complete phase three of 3da1cf1e88f8.
With commit 110113bc086f, vnet sysctl variables can be loader tunable but the feature is limited. When the kernel modules have been initialized, any changes (e.g. via kenv) to kernel environment variable will not affect subsequently created VNETs.
This change relexes the limitation by listening on kernel environment variable's set / unset events, and then update the 'master' copy of vnet SYSCTL or restore it to its initial value.
With this change, TUNABLE_XXX_FETCH can be greately eliminated for vnet loader tunables.
Reviewed by: glebius Fixes: 110113bc086f sysctl(9): Enable vnet sysctl variables to be loader tunable MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D41825
show more ...
|
#
110113bc |
| 09-Sep-2023 |
Zhenlei Huang <zlei@FreeBSD.org> |
sysctl(9): Enable vnet sysctl variables to be loader tunable
Complete phase two of 3da1cf1e88f8.
In 3da1cf1e88f8, the meaning of the flag CTLFLAG_TUN is extended to automatically check if there is
sysctl(9): Enable vnet sysctl variables to be loader tunable
Complete phase two of 3da1cf1e88f8.
In 3da1cf1e88f8, the meaning of the flag CTLFLAG_TUN is extended to automatically check if there is a kernel environment variable which shall initialize the SYSCTL during early boot. It works for all SYSCTL types both statically and dynamically created ones, except for the SYSCTLs which belong to VNETs.
This change extends the meaning further, to allow it also works for the SYSCTLs which belong to VNETs. A typical usage is ``` VNET_DEFINE_STATIC(int, foo) = 0; SYSCTL_INT(_net, OID_AUTO, foo, CTLFLAG_RWTUN | CTLFLAG_VNET, &VNET_NAME(foo), 0, "Description of the foo loader tunable"); ```
Note that the implementation has a limitation. It behaves the same way as that of non-vnet loader tunables. That is, after the kernel or modules being initialized, any changes (e.g. via kenv) to kernel environment variable will not affect the corresponding vnet variable of subsequently created VNETs. To overcome it, we can use TUNABLE_XXX_FETCH to fetch the kernel environment variable into those vnet variables during vnet constructing.
This change will fix the following SYSCTLs those belong to VNETs and have CTLFLAG_TUN flag: ``` net.add_addr_allfibs net.bpf.optimize_writers net.inet.tcp.fastopen.ccache_buckets net.link.bridge.inherit_mac net.link.bridge.ipfw_arp net.link.bridge.log_stp net.link.bridge.pfil_bridge net.link.bridge.pfil_local_phys net.link.bridge.pfil_member net.link.bridge.pfil_onlyip net.link.lagg.default_use_flowid net.link.lagg.default_use_numa net.link.lagg.default_flowid_shift net.link.lagg.lacp.debug net.link.lagg.lacp.default_strict_mode ```
Although the following vnet SYSCTLs have CTLFLAG_TUN flag, theirs values are re-fetched via TUNABLE_XXX_FETCH, thus are not affected by this change. ``` net.inet.ip.reass_hashsize net.inet.tcp.hostcache.cachelimit net.inet.tcp.hostcache.hashsize net.inet.tcp.hostcache.bucketlimit net.inet.tcp.syncache.bucketlimit net.inet.tcp.syncache.cachelimit net.inet.tcp.syncache.hashsize net.key.spdcache.maxentries net.key.spdcache.threshold ```
In memoriam: hselasky Discussed with: hselasky, glebius Fixes: 3da1cf1e88f8 Extend the meaning of the CTLFLAG_TUN flag ... MFC after: 2 weeks Relnotes: yes Differential Revision: https://reviews.freebsd.org/D39638
show more ...
|
#
685dc743 |
| 16-Aug-2023 |
Warner Losh <imp@FreeBSD.org> |
sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
|
#
105e397e |
| 18-Apr-2023 |
Gordon Bergling <gbe@FreeBSD.org> |
kern_sysctl: Remove double words in source code comments
- s/on on/on/
MFC after: 5 days
|
Revision tags: release/13.2.0 |
|
#
f394d9c0 |
| 27-Jan-2023 |
Gleb Smirnoff <glebius@FreeBSD.org> |
sysctl: use correct types and names in sysctl_*sec_to_sbintime
The functions are intended to report kernel variables that are stored as sbintime_t (pointed to by arg1) as human readable nanoseconds
sysctl: use correct types and names in sysctl_*sec_to_sbintime
The functions are intended to report kernel variables that are stored as sbintime_t (pointed to by arg1) as human readable nanoseconds or milliseconds (reported via sysctl_handle_64). The variable types and names were reversed. I guess there is no functional change here, as all types flipped around were signed 64. Note that these function aren't used yet anywhere in the kernel.
Reviewed by: mav Differential revision: https://reviews.freebsd.org/D38217
show more ...
|
Revision tags: release/12.4.0 |
|
#
e5f93d10 |
| 01-Oct-2022 |
Doug Moore <dougm@FreeBSD.org> |
show_sysctl_all: reduce copying, please coverity
Modify db_show_sysctl_all so that it does not copy more than once the data of the input oid, and so that what it passes to db_show_oid does not alarm
show_sysctl_all: reduce copying, please coverity
Modify db_show_sysctl_all so that it does not copy more than once the data of the input oid, and so that what it passes to db_show_oid does not alarm coverity.
Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D36847
show more ...
|
#
5294bfa7 |
| 28-Sep-2022 |
Doug Moore <dougm@FreeBSD.org> |
sysctl_search_oid: remove all-NULL precondition
The implementation of sysctl_search_oid no longer relies on the initial value of nodes to be all NULL, so remove the comment that demands it and let t
sysctl_search_oid: remove all-NULL precondition
The implementation of sysctl_search_oid no longer relies on the initial value of nodes to be all NULL, so remove the comment that demands it and let the caller stop enforcing it.
Reviewed by: hselasky Differential Revision: https://reviews.freebsd.org/D36768
show more ...
|
#
9f6f9007 |
| 27-Sep-2022 |
Doug Moore <dougm@FreeBSD.org> |
name2oid: use find_oidname
In name2oid, use sysctl _find_oidname instead of re-implementing it. Reviewed by: hselasky Differential Revision: https://reviews.freebsd.org/D36765
|
#
e96ae5cb |
| 27-Sep-2022 |
Doug Moore <dougm@FreeBSD.org> |
sysctl_search_oid: remove useless tests
sysctl_search_old makes several tests in a loop that can be removed.
The first test in the loop is only ever true on the first loop iteration, and is always
sysctl_search_oid: remove useless tests
sysctl_search_old makes several tests in a loop that can be removed.
The first test in the loop is only ever true on the first loop iteration, and is always true on that iteration, so its work can be done before the loop begins.
The upper and lower bounds on the loop variable 'indx' are each tested on each iteration, but 'indx' is changed in one direction or the other only once within the loop, so only one bound needs to be checked.
Two ways remain in the loop that nodes[indx] can change (after one of them is put before the loop start), and one of them applies exactly when indx has been incremented, so no separate test for that case requires testing.
Restructure and add comments that makes clearer that this is a basic depth-first search.
Reviewed by: hselasky Differential Revision: https://reviews.freebsd.org/D36741
show more ...
|
#
ed518345 |
| 27-Sep-2022 |
Doug Moore <dougm@FreeBSD.org> |
register_oid: fix duplicate oid after d3f96f661050
sysctl_register_oid must check the uniqueness of any newly computed oid_number in sysctl_register_oid.
Reviewed by: asomers MFC with: d3f96f661050
register_oid: fix duplicate oid after d3f96f661050
sysctl_register_oid must check the uniqueness of any newly computed oid_number in sysctl_register_oid.
Reviewed by: asomers MFC with: d3f96f661050 Differential Revision: https://reviews.freebsd.org/D36743
show more ...
|
#
c075ea46 |
| 27-Sep-2022 |
Hans Petter Selasky <hselasky@FreeBSD.org> |
sysctl(3): Implement SYSCTL_FOREACH() to iterate all OIDs in a sysctl list.
To avoid using the sysctl list macros directly in external kernel modules.
Reviewed by: asomers, manu and asiciliano Dif
sysctl(3): Implement SYSCTL_FOREACH() to iterate all OIDs in a sysctl list.
To avoid using the sysctl list macros directly in external kernel modules.
Reviewed by: asomers, manu and asiciliano Differential Revision: https://reviews.freebsd.org/D36748 MFC after: 1 week Sponsored by: NVIDIA Networking
show more ...
|
#
d3f96f66 |
| 07-Sep-2022 |
Alan Somers <asomers@FreeBSD.org> |
Fix O(n^2) behavior in sysctl
Sysctl OIDs were internally stored in linked lists, triggering O(n^2) behavior when userland iterates over many of them. The slowdown is noticeable for MIBs that have
Fix O(n^2) behavior in sysctl
Sysctl OIDs were internally stored in linked lists, triggering O(n^2) behavior when userland iterates over many of them. The slowdown is noticeable for MIBs that have > 100 children (for example, vm.uma). But it's unignorable for kstat.zfs when a pool has > 1000 datasets.
Convert the linked lists into RB trees. This produces a ~25x speedup for listing kstat.zfs with 4100 datasets, and no measurable penalty for small dataset counts.
Bump __FreeBSD_version for the KPI change.
Sponsored by: Axcient Reviewed by: mjg Differential Revision: https://reviews.freebsd.org/D36500
show more ...
|
#
258958b3 |
| 05-Jul-2022 |
Mitchell Horne <mhorne@FreeBSD.org> |
ddb: use _FLAGS command macros where appropriate
Some command definitions were forced to use DB_FUNC in order to specify their required flags, CS_OWN or CS_MORE. Use the new macros to simplify these
ddb: use _FLAGS command macros where appropriate
Some command definitions were forced to use DB_FUNC in order to specify their required flags, CS_OWN or CS_MORE. Use the new macros to simplify these.
Reviewed by: markj, jhb MFC after: 3 days Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D35582
show more ...
|
Revision tags: release/13.1.0, release/12.3.0 |
|
#
d8bd949b |
| 22-Nov-2021 |
Brooks Davis <brooks@FreeBSD.org> |
sys___sysctl: regularize argument struct
Let makesyscalls generate the normal struct __sysctl_args structure. It works fine.
Reviewed by: kib
|
#
6c950655 |
| 21-Jul-2021 |
Alan Somers <asomers@FreeBSD.org> |
Escape any '.' characters in sysctl node names
ZFS creates some sysctl nodes that include a pool name, and '.' is an allowed character in pool names. But it's the separator in the sysctl tree, so i
Escape any '.' characters in sysctl node names
ZFS creates some sysctl nodes that include a pool name, and '.' is an allowed character in pool names. But it's the separator in the sysctl tree, so it can't be included in a sysctl name. Replace it with "%25". Handily, "%" is illegal in ZFS pool names, so there's no ambiguity there.
PR: 257316 MFC after: 3 weeks Sponsored by: Axcient Reviewed by: freqlabs Differential Revision: https://reviews.freebsd.org/D31265
show more ...
|
#
4342ba18 |
| 18-Apr-2021 |
Konstantin Belousov <kib@FreeBSD.org> |
sysctl_handle_string: do not malloc when SYSCTL_IN cannot fault
In particular, this avoids malloc(9) calls when from early tunable handling, with no working malloc yet.
Reported and tested by: mav
sysctl_handle_string: do not malloc when SYSCTL_IN cannot fault
In particular, this avoids malloc(9) calls when from early tunable handling, with no working malloc yet.
Reported and tested by: mav Sponsored by: The FreeBSD Foundation MFC after: 1 week
show more ...
|
#
571a1a64 |
| 18-Apr-2021 |
Warner Losh <imp@FreeBSD.org> |
Minor style tidy: if( -> if (
Fix a few 'if(' to be 'if (' in a few places, per style(9) and overwhelming usage in the rest of the kernel / tree.
MFC After: 3 days Sponsored by: Netflix
|
Revision tags: release/13.0.0 |
|
#
8db8bebf |
| 30-Nov-2020 |
Alexander V. Chernikov <melifaro@FreeBSD.org> |
Move inner loop logic out of sysctl_sysctl_next_ls().
Refactor sysctl_sysctl_next_ls(): * Move huge inner loop out of sysctl_sysctl_next_ls() into a separate non-recursive function, returning the n
Move inner loop logic out of sysctl_sysctl_next_ls().
Refactor sysctl_sysctl_next_ls(): * Move huge inner loop out of sysctl_sysctl_next_ls() into a separate non-recursive function, returning the next step to be taken. * Update resulting node oid parts only on successful lookup * Make sysctl_sysctl_next_ls() return boolean success/failure instead of errno, slightly simplifying logic
Reviewed by: freqlabs Differential Revision: https://reviews.freebsd.org/D27029
show more ...
|