Bug 1318890 - glibc: nss_db: long group entries are skipped
Summary: glibc: nss_db: long group entries are skipped
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: glibc
Version: 7.2
Hardware: All
OS: Linux
urgent
high
Target Milestone: rc
: ---
Assignee: Florian Weimer
QA Contact: Sergey Kolosov
URL:
Whiteboard:
Depends On: 1321861
Blocks: 1390370 1388637
TreeView+ depends on / blocked
 
Reported: 2016-03-18 03:59 UTC by Frank Hirtz
Modified: 2020-02-14 17:42 UTC (History)
10 users (show)

Fixed In Version: glibc-2.17-158.el7
Doc Type: Bug Fix
Doc Text:
Cause: The nss_db Name Service Switch module fails to request larger result buffers when parsing group entries. Consequence: Group entries whose size falls into a specific range are skipped. Fix: nss_db now detects that the group list does not fit into the result buffer and requests are larger buffer. Result: Group entries in the affected size range are processed correctly.
Clone Of:
: 1321861 1388637 (view as bug list)
Environment:
Last Closed: 2017-08-01 18:06:55 UTC
Target Upstream Version:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Bugzilla 1213603 0 urgent CLOSED glibc: nss_db: get*ent crashes without preceding set*ent 2021-02-22 00:41:40 UTC
Red Hat Bugzilla 1370630 0 high CLOSED glibc: nss_db: Endless loop in services database processing 2021-02-22 00:41:40 UTC
Red Hat Product Errata RHSA-2017:1916 0 normal SHIPPED_LIVE Moderate: glibc security, bug fix, and enhancement update 2017-08-01 18:05:43 UTC
Sourceware 19837 0 None None None 2019-07-23 09:05:26 UTC

Internal Links: 1213603 1370630

Description Frank Hirtz 2016-03-18 03:59:42 UTC
Description of problem:
The client discovered this when testing with RHEL7 against a sizable groups.db file. The 'getet groups' list was truncated and was missing most entries. Florian had a look and submitted the following upstream patch which was tested to resolve the issue:

https://sourceware.org/bugzilla/show_bug.cgi?id=19837

<snip>
nss_db: No retries for some long lines with a larger buffer
_nss_db_get*ent_r returns the wrong error code if parse_line fails.  As a result, only long lines which are large enough not to fit into the caller-provided buffer result in ERANGE with NSS_STATUS_TRYAGAIN.  If parse_line detects that there is not enough room, NSS_STATUS_NOTFOUND is returned, which stops enumeration.

Patch for later reference (I will post it to libc-alpha as well):

diff --git a/nss/nss_db/db-XXX.c b/nss/nss_db/db-XXX.c
index 03c18d7..125a5e9 100644
--- a/nss/nss_db/db-XXX.c
+++ b/nss/nss_db/db-XXX.c
@@ -288,8 +288,8 @@ CONCAT(_nss_db_get,ENTNAME_r) (struct STRUCTURE *result, char *buffer,
 	    }
 	  if (err < 0)
 	    {
-	      H_ERRNO_SET (HOST_NOT_FOUND);
-	      status = NSS_STATUS_NOTFOUND;
+	      H_ERRNO_SET (NETDB_INTERNAL);
+	      status = NSS_STATUS_TRYAGAIN;
 	      break;
 	    }
</snip>

Version-Release number of selected component (if applicable):
glibc-2.17-106.el7_2.4

How reproducible:

Steps to Reproduce:
1.Have long "group" entries (many users/group) and generate/use NSS_db in nsswitch.

2. List group with "getent group"
3. Note that the listing is truncated

I can't include the client's db file unfortunately that we were using for replication, but this patch was tested and corrected the client issue.

Comment 1 Florian Weimer 2016-03-29 09:30:16 UTC
Upstream commit:

https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=a6033052d08027f745867e5e346852da1959226c

Reproducer (needs to run as root):
    
    perl -e \
      'print "large:x:999:" . join(",", map {"user$_"} (1 .. 135))."\n"' \
      >> /etc/group
    cd /var/db
    make
    getent -s db group
    
After the fix, the last command should list the "large" group.
    
The magic number 135 has been chosen so that the line is shorter than
1024 bytes, but the pointers required to encode the member array will
cross the threshold, triggering the bug.

Comment 17 errata-xmlrpc 2017-08-01 18:06:55 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2017:1916


Note You need to log in before you can comment on or make changes to this bug.