Bug 13761 - [PATCH] Fix allocation in nss_compat for large number of memberships to a group
Summary: [PATCH] Fix allocation in nss_compat for large number of memberships to a group
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: nis (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Carlos O'Donell
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-27 06:09 UTC by Siddhesh Poyarekar
Modified: 2016-10-31 15:49 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2012-04-12 00:00:00
fweimer: security+


Attachments
Patch for another unbound allocate in nscd group handling (1.41 KB, patch)
2012-04-12 15:43 UTC, law
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Siddhesh Poyarekar 2012-02-27 06:09:47 UTC
nss_compat allocates buffer space on stack using alloca (and
extend_alloca) for initgroup and keeps extending it to fit in larger
lines. This breaks for cases where the number of members in a gorup
are very large, causing the alloca reference to go beyond thread stack
boundary. I have posted a patch on libc-alpha that implements a fallback to malloc/free if the buffer size needed is beyond __libc_alloca_cutoff:

http://sourceware.org/ml/libc-alpha/2012-02/msg00503.html

How reproducible:
Always

Steps to Reproduce:
1. In /etc/nsswitch.conf:

group: compat
group_compat: files

2. Create a large number of users for a single group

for i in $(seq 1 70000); do
 useradd -M -N -s /sbin/nologin -G foo somelongusernameaaaaaaaaaaaa$i
 echo Created somelongusername$i
done

3. Start nscd
4. groups somelongusernameaaaaaaaaaaaa100

Actual results:
nscd crashes

Expected results:
nscd does not crash

Additional info:

This is also possible with ldap (the original case is with ldap):

group: files compat
group_compat: ldap
Comment 1 Siddhesh Poyarekar 2012-02-27 06:16:45 UTC
Updated patch here:

http://sourceware.org/ml/libc-alpha/2012-02/msg00664.html
Comment 2 Carlos O'Donell 2012-02-28 03:42:14 UTC
I'm reviewing this issue.
Comment 3 Siddhesh Poyarekar 2012-03-30 07:28:41 UTC
Fixed upstream with 984a42374ce2055836f580c2240306171757ea72.
Comment 4 law 2012-04-12 15:43:35 UTC
Created attachment 6339 [details]
Patch for another unbound allocate in nscd group handling

Additional QE testing showed another unbounded alloca in the nscd group handling; specifically the allocation of DATASET within cache_addgr.  Using the testing procedures in this BZ nscd would coredump after blowing out the stack.

Attached is a follow up-patch we're using to address the additional unbound alloca.
Comment 5 law 2012-04-12 15:44:44 UTC
nscd is still segfaulting due to unbound alloca uses using the testing procedures originally reported in this bug.
Comment 6 law 2012-11-29 17:48:07 UTC
2012-11-28  Jeff Law  <law@redhat.com>

        [BZ #13761]
        * nscd/grpcache.c (cache_addgr): Rename alloca_used to
        dataset_temporary.  Track alloca usage into alloca_used.
        If dataset is large allocate and release it via malloc/free.