nss_cache: implement initgroups_dyn - #113
Open
kmjohansen wants to merge 1 commit into
Open
kmjohansen wants to merge 1 commit into
kmjohansen wants to merge 1 commit into
Conversation
glibc's libnss has a callback for initgroups(3) which it uses preferentially to getgrent_r. The getgrent_r fallback is used if initgroups_dyn is not implemented, but glibc does not have any serialization around the callback. This means that if multiple threads call initgroups simultaneously and the nss backend does not implment initgroups_dyn, then it's possible the supplemental group lists will become truncated as multiple getgrent_r calls race with one another. Fix this in libnss_cache by implementing an initgroups_dyn callback. This callback is written in the style of nss-files but with the libnss-cache idioms. It holds the cache lock across the getgrent_r iteration to ensure no supplemental group calls are truncated. This was tested by reproducing the truncation race with an fresh nscd that is bombarded with id -G calls. Without this fix present, it's possible to observe truncated results. However, with initgroups_dyn users always get their correct supplemental groups.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
glibc's libnss has a callback for initgroups(3) which it uses preferentially to getgrent_r. The getgrent_r fallback is used if initgroups_dyn is not implemented, but glibc does not have any serialization around the callback. This means that if multiple threads call initgroups simultaneously and the nss backend does not implment initgroups_dyn, then it's possible the supplemental group lists will become truncated as multiple getgrent_r calls race with one another.
Fix this in libnss_cache by implementing an initgroups_dyn callback. This callback is written in the style of nss-files but with the libnss-cache idioms. It holds the cache lock across the getgrent_r iteration to ensure no supplemental group calls are truncated.
This was tested by reproducing the truncation race with an fresh nscd that is bombarded with id -G calls. Without this fix present, it's possible to observe truncated results. However, with initgroups_dyn users always get their correct supplemental groups.