#3703 Calling getpwnam, etc. leaks file descriptors
Closed: Invalid Opened by jcsible.

Whenever any process calls getpwnam or similar functions, libnss_sss.so opens some files/sockets to get the result, but it doesn't close them when it's done. Minimal test case:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
int main() {
        chdir("/proc/self/fd");
        puts("Before:");
        system("ls -l");
        getpwnam("someuserthatdoesnthavetoexist");
        puts("After getpwnam:");
        system("ls -l");
        getgrnam("somegroupthatdoesnthavetoexist");
        puts("After getgrnam:");
        system("ls -l");
        return 0;
}

Result:

Before:
total 0
lrwx------. 1 jcsible domain users 64 Apr 11 13:14 0 -> /dev/pts/1
lrwx------. 1 jcsible domain users 64 Apr 11 13:14 1 -> /dev/pts/1
lrwx------. 1 jcsible domain users 64 Apr 11 13:14 2 -> /dev/pts/1
After getpwnam:
total 0
lrwx------. 1 jcsible domain users 64 Apr 11 13:14 0 -> /dev/pts/1
lrwx------. 1 jcsible domain users 64 Apr 11 13:14 1 -> /dev/pts/1
lrwx------. 1 jcsible domain users 64 Apr 11 13:14 2 -> /dev/pts/1
lr-x------. 1 jcsible domain users 64 Apr 11 13:14 3 -> /var/lib/sss/mc/passwd
lrwx------. 1 jcsible domain users 64 Apr 11 13:14 4 -> socket:[1064846]
After getgrnam:
total 0
lrwx------. 1 jcsible domain users 64 Apr 11 13:14 0 -> /dev/pts/1
lrwx------. 1 jcsible domain users 64 Apr 11 13:14 1 -> /dev/pts/1
lrwx------. 1 jcsible domain users 64 Apr 11 13:14 2 -> /dev/pts/1
lr-x------. 1 jcsible domain users 64 Apr 11 13:14 3 -> /var/lib/sss/mc/passwd
lrwx------. 1 jcsible domain users 64 Apr 11 13:14 4 -> socket:[1064846]
lr-x------. 1 jcsible domain users 64 Apr 11 13:14 5 -> /var/lib/sss/mc/group

This is a memory cache, it's expected that nss_sss opens those files. I don't know why you see that as a problem, the files are opened just once. I'm afraid we don't have very good user-facing documentation about the memcache, but tl;dr those are files that are mmaped into the memory address space of the application via the nss_sss module, the module can thus read entries without contacting the nss responder at all.

There is a quite low-level documentation about the memory cache here: https://docs.pagure.org/SSSD.sssd/developers/mmap_cache_1.15.html

If there is a reason the memory cache is causing issues, you can disable it with an environment variable, see man sssd.

Metadata Update from @jhrozek:
- Issue close_status updated to: Invalid
- Issue status updated to: Closed (was: Open)

Setting that environment variable fixes the issue with the /var/lib/sss/mc/ files, but not with the socket. It still gets opened and never closed.

I suspect it's the socket to the sssd_nss deamon, that's how the nss_sss module asks sssd about the username.

Yes, but shouldn't it close that after it asks and gets its answer?

The sockets are closed either on error or, in long-running programs, the sssd deamon closes idle sockets after some time-out. Reopening and closing the socket on every request might be costly.

SSSD is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in SSSD's github repository.

This issue has been cloned to Github and is available here:
- https://github.com/SSSD/sssd/issues/4717

If you want to receive further updates on the issue, please navigate to the github issue
and click on subscribe button.

Thank you for understanding. We apologize for all inconvenience.

Metadata