From nobody Tue Feb 3 17:20:20 2026 X-Original-To: dev-commits-src-main@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 4f59Gr5zQwz6QS1w for ; Tue, 03 Feb 2026 17:20:20 +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 "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4f59Gr3wvlz3G3J for ; Tue, 03 Feb 2026 17:20:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1770139220; 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=wFj5dxZgBI6cCDLIem2RuNR8yAtTkj+p6HylzuRUY2w=; b=n08hmnAJ5cTY3jdeTkrbQwcycAKljaatfxkNkxWG0HGwfEQ2hoGzpdin+4xznfseGQYVDH T2Z9bfG5aZ3rppsUXP7j8i2vexpxR9zn7cNJ4J+bLlCW2KdmOiCINmOgZQMuWH6I9KKOUT F7pt307Gdfx2BUqt5BRKhKLxDlE7Sqp38og1gJNYV6hiiZ4IL7TuyN92kyS8sUagdkdfcY B99UbxMS/cq+Qb6yOY+t+gc0XzLZ9q5N4P56E4R4MNxzjqz6D3XoUNhDGu5k/wf1pVwzZ6 uiNoKPmg/sjUCwe1OYXJHNeZYWRmbSckDWktw55ORFyrjH0CB7fw/ADj2ECPAQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1770139220; a=rsa-sha256; cv=none; b=iONrF036+iMzIxukUjpWQtNCyOnByhApNeO1L3W0qM7NtZo/x1jrVKdKxtSYEMjcBBQtoZ Nd8oYkTB8mL2DLq1UZP606aeGtLd0QlsjqN00Gdl9F+uUKdMxaV0Ue+OpFQ5rpVzMQZVMm COtT75JQZO9IoTwSGYO1+g67iVnRkkrXAL07FMJcDnleIMsIt+FWptc+gvzTb03tcbalCE 9cVacHKqbg1U835eyFsZuEj98TScvXBlKKEBgcTk4G5KpAu2fLo5CufspbOKaDwbzdHFkQ pWwEOdOHEGn620I/4UL3rrxwoQrG5Ij8rbDkMGeagpWHRZeOCE+mRQA4cT7zRg== 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=1770139220; 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=wFj5dxZgBI6cCDLIem2RuNR8yAtTkj+p6HylzuRUY2w=; b=yWEu0p7FPObU/273dau5dCigwthdfgfKnTSPb7rKWaa8FP5C6fOEQYMJMpv0+9Th1r8MCc +rqvo6kdoBdGeO8jVte2jmNd22d6EIUvp8lSkDvbqlGp4meswuTH+/TpBwrW38UNRmYyvO 6pKVhHv76Vjbm8R6CqHpgcLcf+K4ETZ0DzjToal+SN/BCdVEE5/NHSnCcl8yPCs8bdl2Eu wROc7JAJYy8sZejQ/0LrqcE4qgQc2qsgO76bnNgFAa5OyQivivq1loS326ePV9x37PQwDW V+K5nySY2GP5tjcurZT1Q/wZVFTICEiyXIFzyKOH3PWzsGMuGyu952/HuYBTdw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4f59Gr39mMz6qj for ; Tue, 03 Feb 2026 17:20:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1f818 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 03 Feb 2026 17:20:20 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Certner Subject: git: 406da392ef8d - main - sysctl(9): Booleans: Accept integers to ease knob conversion List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org 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/main X-Git-Reftype: branch X-Git-Commit: 406da392ef8d77b39fe9bfd36bdb440eb3e5ae0a Auto-Submitted: auto-generated Date: Tue, 03 Feb 2026 17:20:20 +0000 Message-Id: <69822e54.1f818.5f1cdc5e@gitrepo.freebsd.org> The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=406da392ef8d77b39fe9bfd36bdb440eb3e5ae0a commit 406da392ef8d77b39fe9bfd36bdb440eb3e5ae0a Author: Olivier Certner AuthorDate: 2026-01-27 09:45:03 +0000 Commit: Olivier Certner CommitDate: 2026-02-03 17:19:07 +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 --- 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 25da134661e9..dbe509b3e8e2 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1619,8 +1619,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. @@ -1630,16 +1630,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); }