-
Notifications
You must be signed in to change notification settings - Fork 256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The sss_nss_mc_destroy_ctx() function will close the TCP socket of the daemon process #6986
Comments
This code ruins internal status of |
but this is the common way of writing daemon process. |
Common thing is to close fd's 0, 1 and 2. Everything else depends on. In particular, calling |
The specifications I found are Now some applications are written according to this specification, which causes conflicts |
What would be your proposal? To make 'libnss_sss' completely stateless? |
I'm not sure if can change it to stateless. |
Why not close "/var/lib/sss/mc/*" fd after mmap? |
Hi, I think it means that you should close all file descriptors that you have opened. You should not tinker with libraries and fds you don't know. How did you come up with number 32? How can I use your code to reproduce the issue? |
Under the following conditions, the TCP socket inherited by process C from process B is closed: |
I did some research following on my previous comments. Some forum posts (e.g. on stackoverflow) suggest to close all file descriptors in a for loop, like you do, but only as a simple solution to clean up after poor application. You should not, by all means, close valid file descriptors that will be used by the fork - in this case SSSD's fds, but it can be even fd that you opened. You should only close fds that you are not going to use anymore.
To reiterate: You should only close file descriptors that your application opened and the child process is not going to use. |
SSSD's fds is not visible to the application, and the application believes that 3~32 fds will no longer be used, so it has been closed. |
I'm reopening ticket due to real example: While I think this is a bug in TigerVNC, it seems we have to deal with this somehow. |
Real life example would be: https://github.com/TigerVNC/tigervnc/blob/effd854bfd19654fa67ff3d39514a91a246b8ae6/unix/xserver/hw/vnc/xvnc.c#L369 - TigerVNC unconditionally overwrites fd=3 Resolves: SSSD#6986
Real life example would be: https://github.com/TigerVNC/tigervnc/blob/effd854bfd19654fa67ff3d39514a91a246b8ae6/unix/xserver/hw/vnc/xvnc.c#L369 - TigerVNC unconditionally overwrites fd=3 Resolves: SSSD#6986
Real life example would be: https://github.com/TigerVNC/tigervnc/blob/effd854bfd19654fa67ff3d39514a91a246b8ae6/unix/xserver/hw/vnc/xvnc.c#L369 - TigerVNC unconditionally overwrites fd=3 Resolves: SSSD#6986
Real life example would be: https://github.com/TigerVNC/tigervnc/blob/effd854bfd19654fa67ff3d39514a91a246b8ae6/unix/xserver/hw/vnc/xvnc.c#L369 - TigerVNC unconditionally overwrites fd=3 Resolves: #6986 Reviewed-by: Alejandro López <[email protected]> Reviewed-by: Sumit Bose <[email protected]> Reviewed-by: Tomáš Halman <[email protected]> (cherry picked from commit 0344c41)
Pushed PR: #7085
|
The main logic of the daemon process is as follows:
1.process A calls the getpwnam() function, and then fork process B;
2.process B close all file descriptors and performs daemonlize,while process B create a TCP socket;
3.process B forks process C and monitors the status of process C. Process C exits and then forks process C again;
4.process C calls the getpwnam() function;
Under the following conditions, the TCP socket inherited by process C from process B is closed:
1.The SSSD service started and shut down again;
2.The
passwd
option in the/etc/nsswitch.conf
file prioritizes using sss;3.Start daemon process;
4.Add a user using the
useradd
command;5.Kill process C and allow B to fork process C again;
6.The TCP socket inherited by process C from process B is closed;
The analysis process is as follows:
1.When starting the SSSD service,
/var/lib/sss/mc/passwd
file will be created;2.process A calling the
getpwnam()
function resulted in dynamic librarylibnss_sss.so.2
's global variablepw_mc_ctx->fd
is 3;3.process B close all file descriptors and create a TCP socket, TCP socket occupies file descriptor 3,
pw_mc_ctx->fd
is also 3;4.the
useradd
command caused the/var/lib/sss/mc/passwd
file to be deleted;5.when process C calls the
getpwnam()
function again, it will trigger the call tosss_nss_mc_destroy_ctx()
function to close file descriptor number 3;6.At this point, the file descriptor number 3 is TCP socket inherited from process B;
The daemon process code is as follows
The text was updated successfully, but these errors were encountered: