Thread View: muc.lists.freebsd.bugs
3 messages
3 total messages
Started by bugzilla-noreply
Thu, 19 Nov 2026 09:24
[Bug 300896] pw_scan(3), getgrent(3), nss_tacplus and pw(8) accept uid/gid 4294967295, which is (uid_t)-1 / (gid_t)-1
Author: 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
[Bug 300896] pw_scan(3), getgrent(3), nss_tacplus and pw(8) accept uid/gid 4294967295, which is (uid_t)-1 / (gid_t)-1
Author: bugzilla-noreply
Date: Thu, 19 Nov 2026 09:25
Date: Thu, 19 Nov 2026 09:25
13 lines
2448 bytes
2448 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300896 --- Comment #1 from Ricardo Branco <rbranco@suse.com> --- Fix: https://github.com/freebsd/freebsd-src/pull/2572 -- 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
[Bug 300896] pw_scan(3), getgrent(3), nss_tacplus and pw(8) accept uid/gid 4294967295, which is (uid_t)-1 / (gid_t)-1
Author: bugzilla-noreply
Date: Thu, 19 Nov 2026 13:25
Date: Thu, 19 Nov 2026 13:25
28 lines
3107 bytes
3107 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300896 --- Comment #2 from Ricardo Branco <rbranco@suse.com> --- Update: - pwd_mkdb: uid or gid 4294967295 is rejected (4294967295 > max uid value (4294967294)); 4294967294 is accepted. - pw groupadd -g / pw useradd -u 4294967295: Bad id '4294967295': too large; 4294967294 works (tested with pw -V on a scratch etc directory). - getgrent via the real /etc/group: gids 4294967295, 8589934591 and 4294967301 are no longer found by getent group, and 4294967294 still is. Before the patch the first three were accepted and wrapped to -1, -1 andΒ 5. - newgrp 4294967301 used to wrap to gid 5 and prompt for that group's password. It now says bad group name. The patch also covers newgrp(1), which I hadn't mentioned before. Not tested: nss_tacplus -- 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads