#2409 On error, libnss_sss can mistakenly close descriptors it doesn't "own"
Closed: Fixed None Opened 9 years ago by nalin.

If sss_nss_mc_init_ctx() fails to open an mcache file (say, because it doesn't exist), at nss_mc_common.c:125, it jumps to the "done" label, which clears the passed-in sss_cli_mc_ctx structure and returns the error code which open() returned as the function's result.

When sss_nss_mc_init_ctx() returns, sss_nss_mc_get_ctx() compares the descriptor in the context (which has just been cleared, so it's 0) to -1, and then passes it to close(). In my case, it was closing standard input in 'tar', but it probably happens elsewhere, too.


ouch!

priority: major => blocker

Nice catch.
By default, fd is initialized to -1.

src/sss_client/nss_mc_group.c:struct sss_cli_mc_ctx gr_mc_ctx = { false, -1, 0, NULL, 0, NULL, 0, NULL, 0 };
src/sss_client/nss_mc_passwd.c:struct sss_cli_mc_ctx pw_mc_ctx = { false, -1, 0, NULL, 0, NULL, 0, NULL, 0 };

This clean up section was there from beginning.

commit 5f216c753dbd2f2b25a011c5f705ee4f8ad924e6
Author: Simo Sorce <simo@redhat.com>
Date:   Mon Jan 2 15:33:16 2012 -0500

Nalin, could you attach git formatted patch or send it to sssd-devel?

I would like to know. How did you find this issue? because fd should have either initial value -1 or file descriptor opened by sssd-client code.

cc: => lslebodn@redhat.com

Replying to [comment:3 lslebodn]:

I would like to know. How did you find this issue? because fd should have either initial value -1 or file descriptor opened by sssd-client code.

The nightly IPA builds are built in under mock, which is in an environment where the client stubs are installed but SSSD has never been run. The builds were failing because tar, expecting to read the source tarball on stdin, was getting stdin closed out from under it after extracting only a couple of files (and attempting to look up their owners, falling over from 'files' to 'sss' per nsswitch.conf).

A patch which fixes it on my system, probably only one of several possible fixes.
close.patch

Fields changed

patch: 0 => 1

Thank you very much for the patch, Nalin.

milestone: NEEDS_TRIAGE => SSSD 1.11.7
resolution: => fixed
status: new => closed

Metadata Update from @nalin:
- Issue set to the milestone: SSSD 1.11.7

7 years ago

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/3451

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.

Login to comment on this ticket.

Metadata