Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Mar 2020 17:00:13 -0700
From:      John Baldwin <jhb@FreeBSD.org>
To:        Pawel Biernacki <kaktus@FreeBSD.org>, src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r357614 - in head/sys: kern sys
Message-ID:  <8b55858a-ff7a-fd7d-a425-a9543f484be7@FreeBSD.org>
In-Reply-To: <202002061245.016CjwTi096374@repo.freebsd.org>
References:  <202002061245.016CjwTi096374@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8b55858a-ff7a-fd7d-a425-a9543f484be7>