Article View: muc.lists.freebsd.bugs
Article #540[Bug 300896] pw_scan(3), getgrent(3), nss_tacplus and pw(8) accept uid/gid 4294967295, which is (uid_t)-1 / (gid_t)-1
From: bugzilla-noreply
Date: Thu, 19 Nov 2026 09:24
Date: Thu, 19 Nov 2026 09:24
101 lines
5488 bytes
5488 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300896
Bug ID: 300896
Summary: pw_scan(3), getgrent(3), nss_tacplus and pw(8) accept
uid/gid 4294967295, which is (uid_t)-1 / (gid_t)-1
Product: Base System
Version: 16.0-CURRENT
Hardware: Any
OS: Any
Status: New
Severity: Affects Only Me
Priority: ---
Component: bin
Assignee: bugs@FreeBSD.org
Reporter: rbranco@suse.com
Note: This was fixed in OpenBSD in:
https://ftp.openbsd.org/pub/OpenBSD/patches/7.9/common/030_uidrange.patch.sig
UID_MAX and GID_MAX are UINT_MAX (sys/sys/limits.h). That is the same value as
(uid_t)-1 and (gid_t)-1. Several id parsers reject only values greater than
that maximum, so id 4294967295 is accepted.
The kernel treats -1 as "leave unchanged" in setreuid, setresuid, setregid,
setresgid and chown (sys/kern/kern_prot.c). An account with that id is
therefore not a valid identity. Code that passes it to one of those calls gets
a silent no-op.
Affected code
- lib/libc/gen/pw_scan.c: the uid and gid checks use > UID_MAX and > GID_MAX.
This path is used by getpwent and pwd_mkdb.
- lib/libc/gen/getgrent.c (__gr_parse_entry): any strtoul() result is cast to
gid_t with no range check. A value of 2^32 or more wraps, so 8589934591 becomes
-1.
- lib/nss_tacplus/nss_tacplus.c: the same > bounds on ids returned by a
remote TACACS+ server.
- usr.sbin/pw: pw_checkid(), the min_uid, max_uid, min_gid and max_gid config
parsing in pw_conf.c, and one lookup in pw_user.c.
Other parsers have the same pattern but lower impact, and the patch does not
change them: chroot, mdo, ps, chkgrp, tarfs and ypldap. chown is deliberately
unchanged, because -1 is meaningful there.
How to reproduce (16.0-CURRENT amd64)
$ printf '%s\n' 'root:*:0:0::0:0:Root:/root:/bin/sh' \
'test:*:4294967295:4294967295::0:0:Test:/home/test:/bin/sh' > mp
$ mkdir db && pwd_mkdb -d db -p mp; echo $?
0 # accepted; pwd.db and spwd.db are written
A uid of 4294967296 is rejected with 4294967296 > max uid value (4294967295),
so the check is off by one.
Impact
I have found no exploit. Creating such an entry needs control of a passwd or
group source. That is normally root-only, but it can come from a remote source
such as NIS or TACACS+ via nss_tacplus.
- A value that means "no change" is accepted as an id.
- getgrent silently wraps out-of-range gids, possibly to -1.
- Privilege-dropping code that uses setresuid or setresgid and does not check
the result would keep its privileges. OpenSSH's permanently_set_uid does check
and aborts. I have not audited other consumers.
Fix
The patch is in <PR URL>. It rejects ids >= UID_MAX and >= GID_MAX in the
parsers above, and it range-checks the gid in __gr_parse_entry.
Testing
- I built the old and new pw_scan.c into a harness that calls __pw_scan.
4294967295 as a uid or gid is rejected after the patch and accepted before.
4294967294 is accepted in both, and 4294967296 is rejected in both.
- The five changed files pass cc -fsyntax-only on the host.
- Not tested: pw(8) itself, nss_tacplus at runtime, the getgrent check, and a
full world build.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID:
<bug-300896-227@https.bugs.freebsd.org/bugzilla/>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail From: bugzilla-noreply@freebsd.org Newsgroups: muc.lists.freebsd.bugs Subject: [Bug 300896] pw_scan(3), getgrent(3), nss_tacplus and pw(8) accept uid/gid 4294967295, which is (uid_t)-1 / (gid_t)-1 Date: Thu, 19 Nov 2026 09:24:37 +0000 Organization: Newsgate at muc.de e.V. Approved: news-admin@muc.de Distribution: world Message-ID: <bug-300896-227@https.bugs.freebsd.org/bugzilla/> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2"; logging-data="65053"; mail-complaints-to="news-admin@muc.de" X-Original-To: bugs@mlmmj.nyi.freebsd.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795080277; 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=eYBRZgUkHEJklAzwjvJ3EcqQkcRwtJjRFuVMdcigXkU=; b=AMaroSzu2qFRW0Hb4CTyulDKSpvwEX9hHzqtN9XeWCOgG2lbiX03U+XdgEXgnGhySUMjFy fc2VtFSPOi5y12auMd/rf9D6PLWodIM3HEXPYNbCbWdgDfDFGhbLzlgQr0NyuM4fUtWuvt tm7hevDFum6p4aZmbAdssHFcAeW5guKCO452/5j09sqCQPm91NHVMKXKG+uto7G+MvqQmy XYs/xqfGMZbhBsXaNqY0ON0ZEyvKp1qZY6cstbMAabfJHeahWJfRhtDTHyZ87VCN1X0h+r SgXA/0Iq+ZexZFVHStrrwBlvWbOO6dIIN90El84T6UHwqvO4QV1UnOT8tvwqxA== X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f Auto-Submitted: auto-generated Precedence: list X-Newsgate-Id: f02c70b8849f+ X-No-Archive: Yes