RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1747502 - glibc: Calling getpwent after endpwent should not crash?
Summary: glibc: Calling getpwent after endpwent should not crash?
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: glibc
Version: 8.2
Hardware: All
OS: Linux
medium
medium
Target Milestone: rc
: 8.2
Assignee: DJ Delorie
QA Contact: qe-baseos-tools-bugs
Oss Tikhomirova
URL:
Whiteboard:
Depends On:
Blocks: 1746918
TreeView+ depends on / blocked
 
Reported: 2019-08-30 15:54 UTC by Florian Weimer
Modified: 2023-07-18 14:30 UTC (History)
8 users (show)

Fixed In Version: glibc-2.28-84
Doc Type: Bug Fix
Doc Text:
.`glibc` no longer fails when `getpwent()` is called without calling `setpwent()` If your `/etc/nsswitch.conf` file pointed to the Berkeley DB (`db`) password provider, you could request data using the `getpwent()` function without first calling `setpwent()` only once. When you called the `endpwent()` function, further calls to `getpwent()` without first calling `setpwent()` caused `glibc` to fail because `endpwent()` could not reset the internals to allow a new query. This update fixes the problem. As a result, after you end one query with `endpwent()`, further calls to `getpwent()` will start a new query even if you do not call `setpwent()`.
Clone Of: 1698015
Environment:
Last Closed: 2020-04-28 16:50:14 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Bugzilla 1698015 0 medium CLOSED glibc: Calling getpwent after endpwent should not crash? 2021-02-22 00:41:40 UTC
Red Hat Product Errata RHSA-2020:1828 0 None None None 2020-04-28 16:50:50 UTC
Sourceware 24695 0 P2 RESOLVED nss_db: calling getpwent after endpwent crashes 2021-01-18 00:16:06 UTC
Sourceware 24696 0 P2 RESOLVED endgrent() clobbers errno=ERRNO for 'group: db files' entry in /etc/nsswitch.conf 2021-01-18 00:15:26 UTC

Description Florian Weimer 2019-08-30 15:54:04 UTC
We should backport this upstream commit because it is going to be backported into Red Hat Enterprise Linux 7:

commit 99135114ba23c3110b7e4e650fabdc5e639746b7
Author: DJ Delorie <dj>
Date:   Fri Jun 28 18:30:00 2019 -0500

    nss_db: fix endent wrt NULL mappings [BZ #24695] [BZ #24696]
    
    nss_db allows for getpwent et al to be called without a set*ent,
    but it only works once.  After the last get*ent a set*ent is
    required to restart, because the end*ent did not properly reset
    the module.  Resetting it to NULL allows for a proper restart.
    
    If the database doesn't exist, however, end*ent erroniously called
    munmap which set errno.
    
    The test case runs "makedb" inside the testroot, so needs selinux
    DSOs installed.

Comment 1 Carlos O'Donell 2019-10-22 14:12:52 UTC
Please also verify upstream branch backports:

release/2.30/master - May be required. Please check.
release/2.29/master - May be required. Please check.
release/2.28/master - May be required. Please check.

Comment 3 Sergey Kolosov 2020-02-21 07:42:34 UTC
Verified with glibc tests: nss/tst-nss-db-endpwent, nss/tst-nss-db-endgrent.

Comment 4 Oss Tikhomirova 2020-03-23 13:48:44 UTC
Hi, DJ, thank you for providing the perfect future-release-note text.
Will you please review the suggested text since I had to modify it the tiniest bit to comply with the style guides?

I also got 1 question: is “db” a password storage type or some specific library (like BSD `db` library)? It’s about choosing between “db” and `db`.

Thank you in advance.



- - - suggested release note text - - -

.`glibc` no longer fails when getpwent() is called without calling setpwent()

Previously, calling getpwent() without calling setpwent() worked only once if one of the password providers was "db". The second call resulted in a `glibc` failure. This update fixes the problem. Calling endpwent() now correctly resets the internals to allow a new query without explicitly resetting it with setpwent().

Comment 5 DJ Delorie 2020-03-23 15:59:42 UTC
Adding the string "db" to the "passwd" line in /etc/nsswitch.conf (other strings like "files", "dns", and "ldap" may be present, look at yours and see ;) causes the Berkeley DB backend to be used to lookup data.  In the context of this bug, it's the string in /etc/nsswitch.conf that I'm referring to, but it could be reworded either way.

And to clarify the "second time" phrase... the usual sequence of these calls is:

setpwent()
getpwent() returns first record
getpwent() returns second record
. . .
getpwent() returns "NO MORE DATA"
endpwent()

You can perform this *sequence* one time without the "setpwent()" call (but you shouldn't), but if you try to perform the sequence a second time, without calling setpwent() to restart it, it fails.

So it's not the "second call to getpwent()" it's the second time you do the sequence of getpwent() calls.

Comment 7 errata-xmlrpc 2020-04-28 16:50:14 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-2020:1828

Comment 8 Oss Tikhomirova 2020-05-14 19:39:15 UTC
Hi DJ, I apologize for coming back to this release note only now. Will you please review the rewritten text so that I could publish this RN?
Thank you a lot in advance.


.`glibc` no longer fails when getpwent() is called without calling setpwent()

If your `/etc/nsswitch.conf` file pointed to the Berkeley DB (`db`) as a password provider, you could request data using getpwent() without first calling setpwent() only once. Repeated calls of getpwent() without first calling setpwent() caused `glibc` to fail because endpwent() could not reset the internals to allow a new query. This update fixes the problem. As a result, you can now request data using getpwent() without resetting queries with setpwent().

Comment 9 DJ Delorie 2020-05-14 20:58:38 UTC
Suggestions:

Replace "as a password provider" with "password provider" - I think the grammar works better that way.

Replace "Repeated calls of getpwent()" with "Once you call endpwent(), further calls to getpwent()"

Replace "you can now request data" with "now, once you end one query with endpwent(), further calls to getpwent() will start a new query even if setpwent() is not called."

For background:  a typical query for all records is "call setpwent, then call getpwent a lot until it returns NULL, then call endpwent".  That iterates through every record.  If you want to iterate a second time, starting from the beginning, you're supposed to setpwent/lots of getpwent/endpwent again.  Omitting the setpwent at the beginning of the series of calls is technically wrong, but happens to work, except for the db backend.

The wording of the RN needs to be careful to differentiate between "call setpwent after getpwent" and "call setpwent after endpwent, so that getpwent starts from the beginning".  It's the "setpwent after endpwent" that's the key one.

Maybe "As a result, you can now start a new query after calling endpwent() without needing to call setpwent()"

Comment 10 Oss Tikhomirova 2020-05-15 20:12:44 UTC
Thank you, DJ, for great suggestions, especially for the last sentence, which is tricky.

Do you think providing the "proper" sequence of commands could clarify things for the customers? The sequence similar to the one you posted here before:

setpwent()
getpwent() returns first record
getpwent() returns second record
. . .
getpwent() returns "NO MORE DATA"
endpwent()


If you believe the text is enough, I'd publish the following (added your changes):

.`glibc` no longer fails when getpwent() is called without calling setpwent()

If your `/etc/nsswitch.conf` file pointed to the Berkeley DB (`db`) password provider, you could request data using getpwent() without first calling setpwent() only once. When you call endpwent(), further calls to getpwent() without first calling setpwent() caused `glibc` to fail because endpwent() could not reset the internals to allow a new query. This update fixes the problem. As a result, now, once you end one query with endpwent(), further calls to getpwent() will start a new query even if setpwent() is not called.

Comment 11 DJ Delorie 2020-05-15 20:50:34 UTC
I think anyone reading that release note already has a general idea of how these functions work, it's more a matter of explaining the fix in terms of what they already know.  I think your latest text is fine.

Comment 12 Oss Tikhomirova 2020-05-18 11:28:15 UTC
Thank you a lot, DJ, for your time, your feedback is always very helpful.

Comment 14 Oss Tikhomirova 2020-05-20 14:00:57 UTC
Thank you for polishing it, Lenka! Yes, it's all correct, I only removed one definite article before `setpwent()`.


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