From nobody Sat Jul 26 06:12:14 2025 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 4bpvXZ6d8Vz637DB; Sat, 26 Jul 2025 06:12:14 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bpvXZ50Kjz3pXD; Sat, 26 Jul 2025 06:12:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753510334; 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=0Jtlai08NqyDBCUm7qgQjuyJVUaNNczEBPvItoj88ak=; b=O3gBM0jC+MNeW/nWRJKsUGT0b5Rzy2qgrkeKWjlok5BfNFR/fib7dojr5WhHXx4dvs1Bn6 fk6MfTGPkaeo6jX4U32zWG0nv7iZ21CULTejMPHz6DPJ0aOYBfv4hQ7ZF3V1Hj+9zMI0eT nOM8oL+4qTWqKjlq4Arr8YAouHNqi4j2w3gjyPvOAwCHO2wrvk5ljAWFcwvY/QqP94AgQM PcDb4kR1HWxCz6g2MZH+YYnoTgCBdtWo3xTGYz24bW0PdG2N4lMlKn456o2duX9c7CENOo j1oZN1Vdd8swVA/nYQkWZU6hY4hT2BkyjLuVvvCLzQKaa0t0yPt6lFJW2dELEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753510334; 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=0Jtlai08NqyDBCUm7qgQjuyJVUaNNczEBPvItoj88ak=; b=KDj8Z74xK1cPoWuSnnkU8RYg2/qeWqNx/hj2XN2+osXgoHzj7T3lUvdtcMueNDaWN1V/0B MZSMsxEt7AQ/2mF2k+eoeoXtAqhG88hhlY2EfZaOfIsxcKqUtRebhLEoNKMDLurPHU6ReZ fdDJ+LBH58Yr/5XrMZaS7tqOMPG1SE7gFTfUXYI/dg130sIWtd+Xq3X7Qe5egLVmA75KxY UgOKKbAmcNzykB6/q24gTeuFtr5DxIuHZ94w23u9pPesbQLZqC9Pj+dUJxhcfZZQw82ml7 RrMgDsSoHJQdMZK2L0KDkSl9UQCdxGPz/aGM6fXpmASiqUHskcPOd2aC4RHsjQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1753510334; a=rsa-sha256; cv=none; b=fZcef5owW1DgGJVml1JPv4c+jepd+uC6s8tN9IYmVMr1m2mB/KaGL50sDe/aVWP5+XSTCj 0rH1aPsZkQu1AvXOX1nCb1Tu2Yy0LjPSY7WHAKtUH2P/xISH0CyLDRjHfSWuiiC7lx9oWB 7r31JNU3AQ8DfxJvULPYS9VCe5qKf9NUcjANsq5fqapps912idT0zx9B90Jjl3cJoHTl+7 dn9xapXJGy+sOIm7EwkmmypUa+lc1OyAFt+44KNVr31YJHv84YEVDgKpzp7/GdyxkTFd60 lABrNCjCK1qpHh0GBtdaCGiW1mhLDkNEPHvtUJHI/oSs/8rGlX7TZ0IfUT8dhg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4bpvXZ4VWKz38M; Sat, 26 Jul 2025 06:12:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 56Q6CEYZ036898; Sat, 26 Jul 2025 06:12:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 56Q6CETY036890; Sat, 26 Jul 2025 06:12:14 GMT (envelope-from git) Date: Sat, 26 Jul 2025 06:12:14 GMT Message-Id: <202507260612.56Q6CETY036890@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 1286fd8eccb7 - main - base: do a sweep of setgroups() that mean to clear the supplementaries 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1286fd8eccb78e540aae0b03c3a3f6d1865bdb81 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=1286fd8eccb78e540aae0b03c3a3f6d1865bdb81 commit 1286fd8eccb78e540aae0b03c3a3f6d1865bdb81 Author: Kyle Evans AuthorDate: 2025-07-26 06:11:58 +0000 Commit: Kyle Evans CommitDate: 2025-07-26 06:11:58 +0000 base: do a sweep of setgroups() that mean to clear the supplementaries In the future, this will be beneficial as we move the egid out of the groups list; there's no need to track the egid explicitly in our supplemental groups, and doing so could become a security issue if setgid() would not end up switching groups[0] as it does today and we end up wanting to change our egid. The rwhod diff is a little gratuitious, but I like patterns and setgroups() -> setgid() -> setuid() is a lot more common than setgid() -> setgroups() -> setuid(). This is sweep is not exhaustive and intentionally did not include contrib/, crypto/ or tools/. Reviewed by: olce Differential Revision: https://reviews.freebsd.org/D51510 --- sbin/dhclient/dhclient.c | 2 +- usr.sbin/rwhod/rwhod.c | 8 ++++---- usr.sbin/ypldap/ldapclient.c | 2 +- usr.sbin/ypldap/ypldap.c | 2 +- usr.sbin/ypldap/ypldap_dns.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index cbab3fa2973c..5d2a7453578b 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -539,7 +539,7 @@ main(int argc, char *argv[]) setproctitle("%s", ifi->name); /* setgroups(2) is not permitted in capability mode. */ - if (setgroups(1, &pw->pw_gid) != 0) + if (setgroups(0, NULL) != 0) error("can't restrict groups: %m"); if (caph_enter_casper() < 0) diff --git a/usr.sbin/rwhod/rwhod.c b/usr.sbin/rwhod/rwhod.c index 237663eef74d..b99e4ea74b5a 100644 --- a/usr.sbin/rwhod/rwhod.c +++ b/usr.sbin/rwhod/rwhod.c @@ -246,12 +246,12 @@ main(int argc, char *argv[]) syslog(LOG_ERR, "bind: %m"); exit(1); } - if (setgid(unpriv_gid) != 0) { - syslog(LOG_ERR, "setgid: %m"); + if (setgroups(0, NULL) != 0) { + syslog(LOG_ERR, "setgroups: %m"); exit(1); } - if (setgroups(1, &unpriv_gid) != 0) { /* XXX BOGUS groups[0] = egid */ - syslog(LOG_ERR, "setgroups: %m"); + if (setgid(unpriv_gid) != 0) { + syslog(LOG_ERR, "setgid: %m"); exit(1); } if (setuid(unpriv_uid) != 0) { diff --git a/usr.sbin/ypldap/ldapclient.c b/usr.sbin/ypldap/ldapclient.c index acd4410d939f..a246a25a9605 100644 --- a/usr.sbin/ypldap/ldapclient.c +++ b/usr.sbin/ypldap/ldapclient.c @@ -385,7 +385,7 @@ ldapclient(int pipe_main2client[2]) ypldap_process = PROC_CLIENT; #ifndef DEBUG - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid)) fatal("cannot drop privileges"); diff --git a/usr.sbin/ypldap/ypldap.c b/usr.sbin/ypldap/ypldap.c index 01b5955aa822..b9e938227831 100644 --- a/usr.sbin/ypldap/ypldap.c +++ b/usr.sbin/ypldap/ypldap.c @@ -602,7 +602,7 @@ main(int argc, char *argv[]) fatal("getpwnam"); #ifndef DEBUG - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid)) fatal("cannot drop privileges"); diff --git a/usr.sbin/ypldap/ypldap_dns.c b/usr.sbin/ypldap/ypldap_dns.c index 09ce636ebdc8..9dbbf26d237b 100644 --- a/usr.sbin/ypldap/ypldap_dns.c +++ b/usr.sbin/ypldap/ypldap_dns.c @@ -91,7 +91,7 @@ ypldap_dns(int pipe_ntp[2], struct passwd *pw) setproctitle("dns engine"); close(pipe_ntp[0]); - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid)) fatal("can't drop privileges");