public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug nss/31791] New: [Regression] nss: memory for >8 elements in nsswitch.conf is not freed
@ 2024-05-22 23:03 m.novosyolov at rosalinux dot ru
  2024-05-22 23:05 ` [Bug nss/31791] " m.novosyolov at rosalinux dot ru
  0 siblings, 1 reply; 2+ messages in thread
From: m.novosyolov at rosalinux dot ru @ 2024-05-22 23:03 UTC (permalink / raw)
  To: glibc-bugs

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

            Bug ID: 31791
           Summary: [Regression] nss: memory for >8 elements in
                    nsswitch.conf is not freed
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: nss
          Assignee: unassigned at sourceware dot org
          Reporter: m.novosyolov at rosalinux dot ru
  Target Milestone: ---

Add >8 elements into any line of /etc/nsswitch.conf , for example:

hosts: files dns m3 m4 m5 m6 m7 m8 m9

Make a simple test program proga.c:

#include <grp.h>
#include <stdio.h>
#include <sys/types.h>

int main (void)
{
    struct group *g = getgrnam("users");
    if (g != NULL) {
        printf("%s\n", g->gr_name);
    }
    return 0;
}

Install gcc and ASAN sanitizer library if it is in a separate package, example
for ROSA Linux:
sudo dnf install gcc lib64asan-devel
for Ubuntu:
sudo apt install gcc

Build that program with ASAN:
gcc -fsanitize=address proga.c -o proga
Run it:
./proga

ASAN will report a memory leak:

==1011==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 208 byte(s) in 1 object(s) allocated from:
    #0 0x7fcf7e4fbb37 in malloc
../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7fcf7e0afde3 in __libc_dynarray_emplace_enlarge
(/lib/x86_64-linux-gnu/libc.so.6+0xafde3) (BuildId:
4d9090d61bf70e6b3225d583f0f08193f54670b2)
    #2 0x7fcf7e152239  (/lib/x86_64-linux-gnu/libc.so.6+0x152239) (BuildId:
4d9090d61bf70e6b3225d583f0f08193f54670b2)
    #3 0x7fcf7e1526f8  (/lib/x86_64-linux-gnu/libc.so.6+0x1526f8) (BuildId:
4d9090d61bf70e6b3225d583f0f08193f54670b2)
    #4 0x7fcf7e15062b in __nss_group_lookup2
(/lib/x86_64-linux-gnu/libc.so.6+0x15062b) (BuildId:
4d9090d61bf70e6b3225d583f0f08193f54670b2)
    #5 0x7fcf7e1562b8 in getgrnam_r (/lib/x86_64-linux-gnu/libc.so.6+0x1562b8)
(BuildId: 4d9090d61bf70e6b3225d583f0f08193f54670b2)
    #6 0x7fcf7e156157 in getgrnam (/lib/x86_64-linux-gnu/libc.so.6+0x156157)
(BuildId: 4d9090d61bf70e6b3225d583f0f08193f54670b2)
    #7 0x7fcf7e4d0520 in getgrnam
../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:1922
    #8 0x55d5ac172223 in main (/root/proga+0x1223) (BuildId:
71a7b40bd7a3e314f7d5bb5819561d156835cd45)
    #9 0x7fcf7e02a1c9  (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId:
4d9090d61bf70e6b3225d583f0f08193f54670b2)
    #10 0x7fcf7e02a28a in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId:
4d9090d61bf70e6b3225d583f0f08193f54670b2)
    #11 0x55d5ac172144 in _start (/root/proga+0x1144) (BuildId:
71a7b40bd7a3e314f7d5bb5819561d156835cd45)

SUMMARY: AddressSanitizer: 208 byte(s) leaked in 1 allocation(s).

Now make <8 elements in that line of /etc/nsswitch.conf:
hosts: files dns m3 m4 m5 m6 m7
And rerun:
./proga
Memory leak will not be reported.

__libc_dynarray_emplace_enlarge is called if default array size is not enough.
But then that additionally allocated memory is not freed.
This happens with all recent versions of glibc, tested reporoduced on 2.33,
2.38 and 2.39.

Tested glibc 2.31, there is NO memory leak there.

I suspect that commit f8847d83e17774ed5e9c0f75ef693680b91bcae4 "nsswitch: use
new internal API (core)" introduced this.
https://github.com/bminor/glibc/commit/f8847d83e17774ed5e9c0f75ef693680b91bcae4

Is it a feature or a bug?

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug nss/31791] [Regression] nss: memory for >8 elements in nsswitch.conf is not freed
  2024-05-22 23:03 [Bug nss/31791] New: [Regression] nss: memory for >8 elements in nsswitch.conf is not freed m.novosyolov at rosalinux dot ru
@ 2024-05-22 23:05 ` m.novosyolov at rosalinux dot ru
  0 siblings, 0 replies; 2+ messages in thread
From: m.novosyolov at rosalinux dot ru @ 2024-05-22 23:05 UTC (permalink / raw)
  To: glibc-bugs

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

Mikhail Novosyolov <m.novosyolov at rosalinux dot ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dj at redhat dot com,
                   |                            |fweimer at redhat dot com,
                   |                            |siddhesh at sourceware dot org

--- Comment #1 from Mikhail Novosyolov <m.novosyolov at rosalinux dot ru> ---
CCing authors of commits fa78feca47fdc226b46e7f6fea4c08c10fccd182 "nss:
Implement <nss_database.h>" and f8847d83e17774ed5e9c0f75ef693680b91bcae4
"nsswitch: use new internal API (core)"

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-22 23:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-22 23:03 [Bug nss/31791] New: [Regression] nss: memory for >8 elements in nsswitch.conf is not freed m.novosyolov at rosalinux dot ru
2024-05-22 23:05 ` [Bug nss/31791] " m.novosyolov at rosalinux dot ru

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).