From nobody Thu Feb 19 12:29:34 2026 X-Original-To: dev-commits-src-branches@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 4fGt3y2Y9zz6QRRS for ; Thu, 19 Feb 2026 12:29:34 +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 "R12" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fGt3y1SrRz3TBN for ; Thu, 19 Feb 2026 12:29:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1771504174; 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=lkzTNudMAqnF/C4UJn4lWWpQ7IoJlXhgxbQ7/GSGnvY=; b=xABAZ35TI88GZqMPdyC9eA1fsT7LTValbPBqQv1P3bpGqDeUJODaKdy+nxI8Y20rGgWglM KqemlGGRBrjABaXmqYQ+2xyyPtAwkGoavLP4+6XJVt9F67UNFXgqNME9Nu5ReW18crCd81 fQ0EYuiARibZFLuqON8mOApfJc6CytKWb7a5oNkcCAMbweFggLeFoWja3a/nheptTttR5X ezvbyjxPJdhO3GNZSIPm3wpm/yewvBNvNKOjp90utvDvQO5NKZWi3ebVD+NfXwZxv3XivK B2v+l8U6HIxDgcswusbuKkKI2/fZCNEWk4gtn29x8BVAJhoRajrbUbYltrtLyw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1771504174; a=rsa-sha256; cv=none; b=Lw5h7WiqKazWiFjEFauc9ALu14maruqzmSsVkoEfUrLI8WFq2hFqdS+6FlUSvuddZk7G/8 4v93VIfB5ZFfDB0fCRb0MG4gA+BZjIFZDqR98m5RyJ5/0JP72cPG1rQFAmrLjGJr1Xyj70 KDRveo2af8B6Hdgd8UISIryWi7C3i3iAbe+qq68lh/K3+pgYWOphigCUzF6VFYmKypfWoc b7HFXVfphKydWXf27RO5IFomKqcViI5mJKwxTcpcHPB1q6p9cnFIJkS8G1RCpPxokC8d/a 3fF4kuRnYjadlDZMaEayQr+lH5WXlctwxQGJn284BYhwRjltNhnMYqMiKv+2OQ== 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=1771504174; 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=lkzTNudMAqnF/C4UJn4lWWpQ7IoJlXhgxbQ7/GSGnvY=; b=iiR0yzVxFU1QUSUoqJ7DAOMZzhBRrxQ5wS6rjdg1s71QoecPpPV3q66QhrUHySPzX5cI9V M/fb6ZMfn1rTVJd/Tnxh6rKMGfETQXB3reoP3IIouPItYsKeZs2XxSB+0fCvdwWCgjr9UN hDbPpUJPQS5BIf1GskLPKKqU96HHpWg9tiAQVMhsBRv3BuMvEHVldYgxOfxfnCeVfsVJou AuVmMSwOb7fgvo6oSwyXv55E6PZky2Tu2Y4/UAlXPpXtVDmEMrgXQvkQO0gVqZAyqQBQeV oCjqDhNC/pRLrV2ZBKJSaj27kGPvHk1zBSUzWOS6TAP9GMaJ3pX1dwzfpS7yIQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fGt3y0YkVzj24 for ; Thu, 19 Feb 2026 12:29:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 37b7c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 19 Feb 2026 12:29:34 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: 13f0aa2ad825 - stable/15 - sysctl(9): Booleans: Accept integers to ease knob conversion List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/15 X-Git-Reftype: branch X-Git-Commit: 13f0aa2ad8254c8b0c5f3e9f3c1a8a98d5aae071 Auto-Submitted: auto-generated Date: Thu, 19 Feb 2026 12:29:34 +0000 Message-Id: <6997022e.37b7c.363a4d05@gitrepo.freebsd.org> The branch stable/15 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=13f0aa2ad8254c8b0c5f3e9f3c1a8a98d5aae071 commit 13f0aa2ad8254c8b0c5f3e9f3c1a8a98d5aae071 Author: Olivier Certner AuthorDate: 2026-01-27 09:45:03 +0000 Commit: Olivier Certner CommitDate: 2026-02-19 12:28:52 +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 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); }