svn commit: r357614 - in head/sys: kern sys

John Baldwin jhb at FreeBSD.org
Sat Mar 21 00:00:15 UTC 2020


On 2/6/20 4:45 AM, Pawel Biernacki wrote:
> Author: kaktus
> Date: Thu Feb  6 12:45:58 2020
> New Revision: 357614
> URL: https://svnweb.freebsd.org/changeset/base/357614
> 
> Log:
>   sysctl(9): add CTLFLAG_NEEDGIANT flag
>   
>   Add CTLFLAG_NEEDGIANT flag (modelled after D_NEEDGIANT) that will be used to
>   mark sysctls that still require locking Giant.
>   
>   Rewrite sysctl_handle_string() to use internal locking instead of locking
>   Giant.

This broke CTLFLAG_RDTUN strings such as hw.cxgbe.config_file.  This is supposed
to be writable by setting the associated environment variable via loader.conf
or kenv:

>From sys/dev/cxgbe/t4_main.c:

/*
 * Configuration file.  All the _CF names here are special.
 */
#define DEFAULT_CF	"default"
#define BUILTIN_CF	"built-in"
#define FLASH_CF	"flash"
#define UWIRE_CF	"uwire"
#define FPGA_CF		"fpga"
static char t4_cfg_file[32] = DEFAULT_CF;
SYSCTL_STRING(_hw_cxgbe, OID_AUTO, config_file, CTLFLAG_RDTUN, t4_cfg_file,
    sizeof(t4_cfg_file), "Firmware configuration file");

However, CTLFLAG_RDTUN does not include CTLFLAG_WR, so when the kernel attempts
to "write" to this node (the "TUN" part) to apply the associated kenv variable
when loading the kernel module, your changes here now treat it as a ro_string
and set 'arg2' to the length of the actual string.  In my case I was setting
the value to a longer string that still fit in the allocated space, and the
value now fails to set giving me the following error on the console:

Setting sysctl hw.cxgbe.config_file failed: 22

You can reproduce by doing the following:

# kenv hw.cxgbe.config_file="kern_tls"
# kldload if_cxgbe

That should give you the error, and then checking the hw.cxgbe.config_file
sysctl afterwards will show "default" instead of "kern_tls".  Note that you
don't need any cxgbe hardware to reproduce this as a fix would result in
the value of the sysctl after the kldload being "kern_tls".

-- 
John Baldwin


More information about the svn-src-all mailing list