Skip to content
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

Zellij leaks file descriptors to the running processes/shell #796

Closed
tailhook opened this issue Oct 21, 2021 · 1 comment
Closed

Zellij leaks file descriptors to the running processes/shell #796

tailhook opened this issue Oct 21, 2021 · 1 comment

Comments

@tailhook
Copy link

Basic information

zellij --version: 0.8.1
tput lines: irrelevant
tput cols: irrelevant
uname -av or ver(Windows): Linux nixos 5.14.10 #1-NixOS SMP Thu Oct 7 05:53:20 UTC 2021 x86_64 GNU/Linux
alacritty --version: alacritty 0.9.0

Further information
Here is what I get in lsof -p $$ of the shell started from zellij:

zsh     189291   pc    0u   CHR              136,7       0t0      10 /dev/pts/7
zsh     189291   pc    1u   CHR              136,7       0t0      10 /dev/pts/7
zsh     189291   pc    2u   CHR              136,7       0t0      10 /dev/pts/7
zsh     189291   pc    5u  unix 0x0000000000000000       0t0   22962 /run/user/1000/zellij/0.18.1/session1 type=STREAM (LISTEN)
zsh     189291   pc    6u  unix 0x0000000000000000       0t0   22963 /run/user/1000/zellij/0.18.1/session1 type=STREAM (CONNECTED)
zsh     189291   pc    7u  unix 0x0000000000000000       0t0   22963 /run/user/1000/zellij/0.18.1/session1 type=STREAM (CONNECTED)
zsh     189291   pc    8u  unix 0x0000000000000000       0t0   22084 /run/user/1000/zellij/0.18.1/session1 type=STREAM (CONNECTED)
zsh     189291   pc    9u  unix 0x0000000000000000       0t0   22084 /run/user/1000/zellij/0.18.1/session1 type=STREAM (CONNECTED)
zsh     189291   pc   10u   CHR              136,7       0t0      10 /dev/pts/7
zsh     189291   pc   11u   CHR                5,2       0t0      85 /dev/ptmx
zsh     189291   pc   14u  unix 0x0000000000000000       0t0   22098 /run/user/1000/zellij/0.18.1/session1 type=STREAM (CONNECTED)
zsh     189291   pc   15u  unix 0x0000000000000000       0t0   22098 /run/user/1000/zellij/0.18.1/session1 type=STREAM (CONNECTED)
zsh     189291   pc   17r  FIFO               0,13       0t0  637219 pipe
zsh     189291   pc   18w  FIFO               0,13       0t0  637219 pipe
zsh     189291   pc   19u   CHR                5,2       0t0      85 /dev/ptmx
zsh     189291   pc   20u   CHR                5,2       0t0      85 /dev/ptmx
zsh     189291   pc   21u   CHR                5,2       0t0      85 /dev/ptmx

This is the same shell running from alacritty directly:

zsh     515006   pc    0u   CHR 136,12      0t0      15 /dev/pts/12
zsh     515006   pc    1u   CHR 136,12      0t0      15 /dev/pts/12
zsh     515006   pc    2u   CHR 136,12      0t0      15 /dev/pts/12
zsh     515006   pc   10u   CHR 136,12      0t0      15 /dev/pts/12

So unix sockets are clearly leaking to the child, but probably pipes and ptmx is too.

To fix it you have to either consistently set cloexec flag on all files/sockets or close all sockets after fork (by iterating from 3 to ulimit, or using closefrom/close_range on systems that support that). Preferably doing both, because cloexec saves from leaking to processes run by any method (say zellij use a library that spawns a process), and closing after fork saves you from libraries that use file descriptors but didn't implement cloexec.

@tailhook tailhook changed the title Zellij leaks file descriptors the running processes/shell Zellij leaks file descriptors to the running processes/shell Oct 21, 2021
@tailhook
Copy link
Author

tailhook commented Nov 1, 2021

Looks like it's been addressed by #830

@tailhook tailhook closed this as completed Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant