Page MenuHomeFreeBSD

Fix handling of 'user' mib in sysctl(3)
ClosedPublic

Authored by pkelsey on Jun 29 2015, 4:54 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Apr 30, 4:52 PM
Unknown Object (File)
Tue, Apr 30, 4:52 PM
Unknown Object (File)
Tue, Apr 30, 4:52 PM
Unknown Object (File)
Tue, Apr 30, 10:13 AM
Unknown Object (File)
Fri, Apr 26, 6:38 AM
Unknown Object (File)
Fri, Apr 26, 6:23 AM
Unknown Object (File)
Feb 22 2024, 7:00 PM
Unknown Object (File)
Feb 19 2024, 8:48 AM
Subscribers

Details

Summary

While testing the example code in the sysctl(3) man page,
sbruno noticed user.cs_path was empty (see
https://lists.freebsd.org/pipermail/freebsd-hackers/2015-June/047901.html).

It turns out sysctl(3) has been broken (returning empy/zero for all
'user.' names) since r240176 (that is, for nearly three
years). r240176 assumed that because all values in the user mib are
being supplied by sysctl(3), the __sysctl() call would result in
ENOENT for all user mib names. However, this is not the case, as
there is a dummy entry in the sysctl tree for every valid user mib
name to support name lookups and enumeration.

Another bug (hidden by the first one) was also introduced by r240176.
In using __sysctl() to validate that the supplied name was not NULL or
zero length, in the case of a valid user mib name, the length supplied
by the caller in oldlenp is overwritten with the length of the dummy
entry. When the user mib name is of string type, this always results
in a zero length in oldlenp in the value retrieval logic that follows,
causing sysctl(3) to fail with ENOMEM regardless of how much space the
caller provides.

These bugs are fixed by this patch.

I grepped base and ports for occurences of '[[:space:]'"]user' on the
same line as 'sysctl', as well as for any occurrences of CTL_USER.
The only hit was in usr.bin/whereis, whose behavior would be affected
by these bugs if PATH had been modified to not include the default
path contained in user.cs_path. It is of course possible that there
are indirect retrievals of user mib names that would not be found by
the above searches.

Test Plan

On 11-CURRENT, without the patch:
$ sysctl user
user.cs_path:
user.bc_base_max: 0
user.bc_dim_max: 0
user.bc_scale_max: 0
user.bc_string_max: 0
user.coll_weights_max: 0
user.expr_nest_max: 0
user.line_max: 0
user.re_dup_max: 0
user.posix2_version: 0
user.posix2_c_bind: 0
user.posix2_c_dev: 0
user.posix2_char_term: 0
user.posix2_fort_dev: 0
user.posix2_fort_run: 0
user.posix2_localedef: 0
user.posix2_sw_dev: 0
user.posix2_upe: 0
user.stream_max: 0
user.tzname_max: 0

On 11-CURRENT, with the patch:
$sysctl user
user.cs_path: /usr/bin:/bin:/usr/sbin:/sbin
user.bc_base_max: 99
user.bc_dim_max: 2048
user.bc_scale_max: 99
user.bc_string_max: 1000
user.coll_weights_max: 0
user.expr_nest_max: 32
user.line_max: 2048
user.re_dup_max: 255
user.posix2_version: 199212
user.posix2_c_bind: 0
user.posix2_c_dev: 0
user.posix2_char_term: 0
user.posix2_fort_dev: 0
user.posix2_fort_run: 0
user.posix2_localedef: 0
user.posix2_sw_dev: 0
user.posix2_upe: 0
user.stream_max: 20
user.tzname_max: 255

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

pkelsey retitled this revision from to Fix handling of 'user' mib in sysctl(3).
pkelsey updated this object.
pkelsey edited the test plan for this revision. (Show Details)
pkelsey added a reviewer: sbruno.

This definitely makes the user sysctl entries appear. The descriptions are amusing.

sysctl user

user.cs_path: /usr/bin:/bin:/usr/sbin:/sbin
user.bc_base_max: 99
user.bc_dim_max: 2048
user.bc_scale_max: 99
user.bc_string_max: 1000
user.coll_weights_max: 0
user.expr_nest_max: 32
user.line_max: 2048
user.re_dup_max: 255
user.posix2_version: 199212
user.posix2_c_bind: 0
user.posix2_c_dev: 0
user.posix2_char_term: 0
user.posix2_fort_dev: 0
user.posix2_fort_run: 0
user.posix2_localedef: 0
user.posix2_sw_dev: 0
user.posix2_upe: 0
user.stream_max: 20
user.tzname_max: 255
root@tasty.ysv:/usr/src # sysctl -d user
user: user-level
user.cs_path: PATH that finds all the standard utilities
user.bc_base_max: Max ibase/obase values in bc(1)
user.bc_dim_max: Max array size in bc(1)
user.bc_scale_max: Max scale value in bc(1)
user.bc_string_max: Max string length in bc(1)
user.coll_weights_max: Maximum number of weights assigned to an LC_COLLATE locale entry
user.expr_nest_max:
user.line_max: Max length (bytes) of a text-processing utility's input line
user.re_dup_max: Maximum number of repeats of a regexp permitted
user.posix2_version: The version of POSIX 1003.2 with which the system attempts to comply
user.posix2_c_bind: Whether C development supports the C bindings option
user.posix2_c_dev: Whether system supports the C development utilities option
user.posix2_char_term:
user.posix2_fort_dev: Whether system supports FORTRAN development utilities
user.posix2_fort_run: Whether system supports FORTRAN runtime utilities
user.posix2_localedef: Whether system supports creation of locales
user.posix2_sw_dev: Whether system supports software development utilities
user.posix2_upe: Whether system supports the user portability utilities
user.stream_max: Min Maximum number of streams a process may have open at one time
user.tzname_max: Min Maximum number of types supported for timezone names

sbruno edited edge metadata.

Unrelated to this patch:

Missing descriptions:
user.expr_nest_max:
user.posix2_char_term:

stlgtm

This revision is now accepted and ready to land.Jul 1 2015, 8:32 PM
This revision was automatically updated to reflect the committed changes.