From nobody Thu Jul 23 10:00:29 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4h5RSs5JLrz6lVmM for ; Thu, 23 Jul 2026 10:00:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4h5RSs37c7z3VZD for ; Thu, 23 Jul 2026 10:00:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1784800829; 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=f0LbPua35GzucPMjcd/tXSQLd9+k3kYj7TzrWiW60rg=; b=WRJR0BAIhW8XEiT0zMf+K4ivlT+pbDUgmVTO5tgZZoHIc+FpUaCNkV2iQXAyyRPjtnyjqw wO4zfxtK/+Y6D/2I3Z+vM92SN32EGbtowKaHnF983Obv8nqamgdcB7V/O1tCwDpoZneMi5 85CIdE4WBwDbUu/9ddYAGYS7OznhIif+BIZrGttfvXXE4xAovG2Ff5wsnfvGnPU2wm289a 6BpG4eUASVvcTHs5ewdSuqKqQEYSHSzAvfyDkVbsfCNruu8OffdxuUuGuDh2opSU/ZRVni 5YFYYHg6JCkRWjvd/fGlsUUkmSapoKCvBaK4QiFHcY0MHEHigYUEZtEuyBsYmQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1784800829; a=rsa-sha256; cv=none; b=wlXrkj+z/Fj/k+bQT/o3vFQ6eO1MRFWH4T4ncIpfPLfDb3tngr/ZQOfRFiVyliSKkCx+Tc 9tWrvhokHnjwfhn1lwcOnCRfVIfZ3Xy1Boi+ZIbVzdxLittcg9XGiZv6tVUts6eOPQl+g4 5QCU4ZgDCTI0jzjz6O+UzNS83l1XzsZsdf99mKkwraXnUvzgMGchbZyX23q3EXOY8Cky2a Mu84CHRcQRC+lV4Hg73kWWRzZJ9rSE1ScWQRoDcRsz6GuSLjqMeUMNvEdWFf2cKhENUW4H 39v9G6l2qEWURCcZMqGM45Stjr8Oa999zB+N6sSe2ODsgf1Hoe0N+A8VCXzBag== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1784800829; 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=f0LbPua35GzucPMjcd/tXSQLd9+k3kYj7TzrWiW60rg=; b=NS4QWn4a1nX3VxFe+kWTQ1pBN1QRH3QmhM/wX34+7n8RLLcpLghakk7I1wjIpPQW4ijFma 73D8Qma3FlPQa5GAtpTfdTFcKf7hXmYFW6mnoxmNXq8AUtRHQX+hwSDlhK7bO8oZmmn21p TzcnupH0idqdmnNxw/iWKAf2BQJf/GzNljqC+aT52PlfzrmKYfH33St5pMmnwsGde4HGPz u3u8BQ1T0mCLnKjr/psczYdKDjWafPshf5wugEMwVJp4x9Niv62MV6yafutOkjz14l+0gh gWlT3wDbBsjJa+5IVLR7kpP8QksP7T24FnsLoONLbI5mNveQb66Z7DmyRkItOg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4h5RSs1vN2z10xV for ; Thu, 23 Jul 2026 10:00:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3cd9c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 23 Jul 2026 10:00:29 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: 4018a762498a - stable/14 - sysctl(9): Booleans: Accept integers to ease knob conversion List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 4018a762498ab20c6545942faaaefd6371728f48 Auto-Submitted: auto-generated Date: Thu, 23 Jul 2026 10:00:29 +0000 Message-Id: <6a61e63d.3cd9c.7613cf69@gitrepo.freebsd.org> The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=4018a762498ab20c6545942faaaefd6371728f48 commit 4018a762498ab20c6545942faaaefd6371728f48 Author: Olivier Certner AuthorDate: 2026-01-27 09:45:03 +0000 Commit: Olivier Certner CommitDate: 2026-07-23 09:59:01 +0000 sysctl(9): Booleans: Accept integers to ease knob conversion In sysctl_handle_bool(), if the output buffer (for the old value) has room for exactly 4 bytes (sizeof(int)), then output the current boolean value as an integer rather than a 'uint8_t'. Conversely, if 4 bytes exactly remain in the input buffer (for the new value), treat them as an integer and derive the new boolean value from it. Doing so allows to convert existing integer syscstl knobs that are interpreted as a boolean into true boolean ones while staying backwards-compatible. That brings no drawback as no code currently uses sysctl_handle_bool() as part of a series of calls to sysctl_handle_*() functions for (de)serialization of some compound structure. If that case ever materializes, it can be easily solved, e.g., by creating a sysctl_handle_bool_strict() variant. In the future, we might want to go further and generally be more liberal in the external type of integers we accept and output, by tolerating any kind of supported integers (8-bit to 64-bit), enabling integer type changes of knob's internal representations without breaking the ABI for consumers hardcoding the passed integers (instead of relying on sysctl knob type information). Reviewed by: jhb MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D54925 (cherry picked from commit 406da392ef8d77b39fe9bfd36bdb440eb3e5ae0a) --- sys/kern/kern_sysctl.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 29438e882297..f65e8506abd8 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1519,8 +1519,8 @@ static SYSCTL_NODE(_sysctl, CTL_SYSCTL_OIDLABEL, oidlabel, CTLFLAG_RD | int sysctl_handle_bool(SYSCTL_HANDLER_ARGS) { - uint8_t temp; int error; + uint8_t temp; /* * Attempt to get a coherent snapshot by making a copy of the data. @@ -1530,16 +1530,44 @@ sysctl_handle_bool(SYSCTL_HANDLER_ARGS) else temp = arg2 ? 1 : 0; - error = SYSCTL_OUT(req, &temp, sizeof(temp)); + /* + * In order to support backwards-compatible conversion of integer knobs + * that are used as booleans to true boolean knobs, whose internal state + * is stored as a 'bool' and not an 'int', if exactly 4 bytes remain in + * the output buffer, we assume that the caller expected an 'int' + * instead of a 'uint8_t'. + */ + if (req->oldidx >= req->oldlen) + return (ENOMEM); + if (req->oldlen - req->oldidx == sizeof(int)) { + int temp_int = temp; + + error = SYSCTL_OUT(req, &temp_int, sizeof(temp_int)); + } else + error = SYSCTL_OUT(req, &temp, sizeof(temp)); if (error || !req->newptr) return (error); if (!arg1) error = EPERM; else { - error = SYSCTL_IN(req, &temp, sizeof(temp)); - if (!error) - *(bool *)arg1 = temp ? 1 : 0; + /* + * Conversely, if the input buffer has exactly 4 bytes to read, + * use them all to produce a bool. + */ + if (req->newidx >= req->newlen) + return (ENOMEM); + if (req->newlen - req->newidx == sizeof(int)) { + int temp_int; + + error = SYSCTL_IN(req, &temp_int, sizeof(temp_int)); + if (error == 0) + *(bool *)arg1 = temp_int != 0 ? 1 : 0; + } else { + error = SYSCTL_IN(req, &temp, sizeof(temp)); + if (error == 0) + *(bool *)arg1 = temp != 0 ? 1 : 0; + } } return (error); }