From nobody Sat Nov 14 16:25:02 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 4jRfby50kVz71Lrs for ; Sat, 14 Nov 2026 16:25:02 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jRfby3n2Qz4f7t for ; Sat, 14 Nov 2026 16:25:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794673502; 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=oD/d+tpwhfhM0f5sgwxa32CSyXCKL/9HyEqZ4kkW3u4=; b=geNjx3n06V5ksi6tBg+zLGT4UjL5cvrpwYPnVgXqcFHxp+/Sf5GfmQOHWHHCnLL7LgrcAK CVmCpY+sRfPGvWLwp2s6cM1QQW5T5PL2tm7HIwqbYdgZYdWesJUmu8DmdbGAPu5W9fyPyf p+oiRBRkeicnfrX4fJLaYI9br9tb3CK892oq9OqNF7FqjLC81o4445sm879GrDzpb1X3Ai Em0NIb/RpddGku3p/CHSzAOPnGyJRgfmTn5s0LACiqjBhnzFquVAuOVkEP5J+iU393GWlV rXtDcGGfx2ti4OiZSf2Vcy+VNo//3mqQqgVx6wtEBRqvjv5JQbupwfa4ORdrFg== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794673502; b=UV7Wmvh6eXiGXGNwhY8D0J63hfAIuRVTsS4Gg3eT3CWy4j3uHOaxD2iqkrKLXkYJ52rJWq LxdVtDUceCtOljD60xFwnc2LOqyKOnZotCmaYExnCPc9QFiy0KlJpQEsuaz6PmbopT+0LP wunJf00nn89BfuV9TcC3tsZ6yucLYX2NiK9RGEvlfA5+C1PvxMJIW2kaVlH6cikc29ype9 7QNO8tEjX58xFJCgt+YFhdw2KLPj7k+Tg5u4ecPXDKwEDoq56nnGU2alqN4NtkH1JwcFUf d54wImJdR3aFxHMfW7mlyKxsE5UbOGh22st1tLENaBKzgpj5S6xd3Am1RgE62A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794673502; 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=oD/d+tpwhfhM0f5sgwxa32CSyXCKL/9HyEqZ4kkW3u4=; b=jQC279aY1oOxXpt3DgzptrooJdN5nUEdbjqN0X/dUn3PuLO9PN9Eggnz4jd/dPVo84ZteI WPsvbEY2x0E8NnSQGQFRstMQvIiAspy8+7ZdNAUbB0aMCmuVg8XHIxOjG9H26iKjEWLf4w spmQSJiEo9FCm/XgwBZVkkBrrGa8v/+bB1PsvSK8lACyOz023MrzgeAQiKDoGB9iLYGFYB L1mI3SyBh3R9L30Zo1PT0XrV7Wdx6j688yfJUxvGJ0U1uw0hLjijyiit6Q94Wyx2ZBrfja O/xGohio+VR6ei9DNVrIKlQZqbZHFB8bohHKZZh5VGtMHidcR3MrdFOt3TKU3A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jRfby3KKHzRyb for ; Sat, 14 Nov 2026 16:25:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 17898 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 14 Nov 2026 16:25:02 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav Subject: git: 408a1ec93fac - main - geom: Check file flags before handling control request List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository 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: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 408a1ec93facc8a02f4f7515fb4e036cce85fa39 Auto-Submitted: auto-generated Date: Sat, 14 Nov 2026 16:25:02 +0000 Message-Id: <6af88b5e.17898.ff156ab@gitrepo.freebsd.org> The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=408a1ec93facc8a02f4f7515fb4e036cce85fa39 commit 408a1ec93facc8a02f4f7515fb4e036cce85fa39 Author: Dag-Erling Smørgrav AuthorDate: 2026-11-14 16:24:45 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2026-11-14 16:24:45 +0000 geom: Check file flags before handling control request Pass fflag down to g_ctl_req() and: * Refuse all requests unless fflag has the FREAD bit set * Refuse all but getxml unless fflag also has the FWRITE bit set This should allow us to restore read access to /dev/geom.ctl for group operator; they will then be able to run `gpart list` or `gpart backup` but not commands that actually modify the table. For backward compatibility, we set the FWRITE bit if it is not already set and the calling thread has the PRIV_GEOM privilege, which is automatically granted to a jailed or unjailed superuser. This should cover the case of older binaries (which open /dev/geom.ctl read-only) running as root on a newer kernel. Since we intend to merge this to stable/15, the compatibility code is conditional on COMPAT_FREEBSD14. MFC after: 1 week Event: EuroBSDCon 2026 DevSummit Reviewed by: imp, markj Differential Revision: https://reviews.freebsd.org/D59591 --- sys/geom/geom_ctl.c | 46 ++++++++++++++++++++++++++++++++++++++-------- sys/sys/priv.h | 1 + 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/sys/geom/geom_ctl.c b/sys/geom/geom_ctl.c index 61756508ab43..64a56908e0ea 100644 --- a/sys/geom/geom_ctl.c +++ b/sys/geom/geom_ctl.c @@ -39,7 +39,9 @@ #include #include #include +#include #include +#include #include #include @@ -552,18 +554,29 @@ g_ctl_getxml(struct gctl_req *req, struct g_class *mp) g_free(gps); } +struct g_ctl_req_args { + struct gctl_req *req; + int fflag; +}; + static void g_ctl_req(void *arg, int flag __unused) { + struct g_ctl_req_args *args = arg; + struct gctl_req *req = args->req; struct g_class *mp; - struct gctl_req *req; char const *verb; + int fflag = args->fflag; g_topology_assert(); - req = arg; mp = gctl_get_class(req, "class"); if (mp == NULL) return; + if ((fflag & FREAD) == 0) { + req->nerror = EPERM; + gctl_error(req, "Read access required"); + return; + } verb = gctl_get_param(req, "verb", NULL); if (verb == NULL) { gctl_error(req, "Verb missing"); @@ -574,18 +587,23 @@ g_ctl_req(void *arg, int flag __unused) } else if (mp->ctlreq == NULL) { gctl_error(req, "Class takes no requests"); } else { + if ((fflag & FWRITE) == 0) { + req->nerror = EPERM; + gctl_error(req, "Write access required"); + return; + } mp->ctlreq(req, mp, verb); } g_topology_assert(); } static int -g_ctl_ioctl_ctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td) +g_ctl_ioctl_ctl(struct cdev *dev, u_long cmd, void *data, int fflag, struct thread *td) { - struct gctl_req *req; + struct g_ctl_req_args args = { .req = data, .fflag = fflag }; + struct gctl_req *req = data; int nerror; - req = (void *)data; req->nerror = 0; /* It is an error if we cannot return an error text */ if (req->lerror < 2) @@ -606,7 +624,7 @@ g_ctl_ioctl_ctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct th gctl_dump(req, "request"); if (!req->nerror) { - g_waitfor_event(g_ctl_req, req, M_WAITOK, NULL); + g_waitfor_event(g_ctl_req, &args, M_WAITOK, NULL); if (g_debugflags & G_F_CTLDUMP) gctl_dump(req, "result"); @@ -631,9 +649,21 @@ g_ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread { int error; - switch(cmd) { +#ifdef COMPAT_FREEBSD14 + /* + * Prior to FreeBSD 15, read-only access to geom.ctl granted + * unrestricted access to all GEOM verbs, and libgeom opened + * geom.ctl read-only. To avoid putting the user in a situation + * where their older binaries cannot configure GEOM on a newer + * kernel, we set the FWRITE bit if unset, but only for an + * already-privileged process (e.g. geli(8) during boot). + */ + if ((fflag & FWRITE) == 0 && priv_check(td, PRIV_GEOM) == 0) + fflag |= FWRITE; +#endif /* COMPAT_FREEBSD14 */ + switch (cmd) { case GEOM_CTL: - error = g_ctl_ioctl_ctl(dev, cmd, data, fflag, td); + error = g_ctl_ioctl_ctl(dev, cmd, (void *)data, fflag, td); break; default: error = ENOIOCTL; diff --git a/sys/sys/priv.h b/sys/sys/priv.h index 87775632f8a8..3b46625734d7 100644 --- a/sys/sys/priv.h +++ b/sys/sys/priv.h @@ -81,6 +81,7 @@ #define PRIV_SETTIMEOFDAY 18 /* Can call settimeofday. */ #define _PRIV_SETHOSTID 19 /* Removed. */ #define _PRIV_SETDOMAINNAME 20 /* Removed. */ +#define PRIV_GEOM 21 /* Can modify GEOM configuration. */ /* * Audit subsystem privileges.