[PR #6750] [MERGED] bugfix: fix potential deadlock with flock + SIGTSTP #6151

Closed
opened 2026-05-05 10:51:41 -06:00 by gitea-mirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netblue30/firejail/pull/6750
Author: @jlimor-kl
Created: 5/15/2025
Status: Merged
Merged: 5/21/2025
Merged by: @kmk3

Base: masterHead: master


📝 Commits (1)

  • 2a5dc15 bugfix: fix potential deadlock with flock + SIGTSTP

📊 Changes

1 file changed (+49 additions, -0 deletions)

View changed files

📝 src/firejail/preproc.c (+49 -0)

📄 Description

As reported by @hlein in #6729, if a firejailed process is ^Z'd at the wrong time during startup, other firejail processes will be unable to proceed because they'll wait forever for an flock on /run/firejail/firejail-run.lock.

This fixes that by installing a signal handler to catch SIGTSTP (Ctrl-Z) before acquiring locks. The handler increments a flag to allow for re-sending the SIGTSTP signal after locks have been released.

Deadlock Reproducer

The length of the sleep should be adjusted until the debug output resembles below

$ firejail --debug id & P=$!;sleep 0.0005;kill -TSTP $P
[1] 16130
Looking for kernel processes
Found kthreadd process, we are not running in a sandbox
pid=16130: locking /run/firejail/firejail-run.lock ...
pid=16130: locked /run/firejail/firejail-run.lock

[1]+  Stopped                 firejail --debug id

Further calls to firejail will hang due to the stopped process holding the firejail-run lock.

$ firejail id
^C

After Patch

$ firejail --debug id & P=$!;sleep 0.0005;kill -TSTP $P
[1] 16504
Looking for kernel processes
Found kthreadd process, we are not running in a sandbox
pid=16504: locking /run/firejail/firejail-run.lock ...
pid=16504: locked /run/firejail/firejail-run.lock
pid=16504: caught SIGTSTP while locks are held
pid=16504: unlocking /run/firejail/firejail-run.lock ...
pid=16504: unlocked /run/firejail/firejail-run.lock
pid=16504: resending caught SIGTSTP

[1]+  Stopped                 firejail --debug id

Due to locks being properly released before the process is stopped, new firejail processes will not hang while acquiring the lock.

Fixes #6729.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netblue30/firejail/pull/6750 **Author:** [@jlimor-kl](https://github.com/jlimor-kl) **Created:** 5/15/2025 **Status:** ✅ Merged **Merged:** 5/21/2025 **Merged by:** [@kmk3](https://github.com/kmk3) **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (1) - [`2a5dc15`](https://github.com/netblue30/firejail/commit/2a5dc15602e3d982e10b43a70b633a12b1c5fe2e) bugfix: fix potential deadlock with flock + SIGTSTP ### 📊 Changes **1 file changed** (+49 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/firejail/preproc.c` (+49 -0) </details> ### 📄 Description As reported by @hlein in #6729, if a firejailed process is `^Z`'d at the wrong time during startup, other firejail processes will be unable to proceed because they'll wait forever for an flock on `/run/firejail/firejail-run.lock`. This fixes that by installing a signal handler to catch SIGTSTP (Ctrl-Z) before acquiring locks. The handler increments a flag to allow for re-sending the SIGTSTP signal after locks have been released. #### Deadlock Reproducer The length of the sleep should be adjusted until the debug output resembles below ```sh $ firejail --debug id & P=$!;sleep 0.0005;kill -TSTP $P [1] 16130 Looking for kernel processes Found kthreadd process, we are not running in a sandbox pid=16130: locking /run/firejail/firejail-run.lock ... pid=16130: locked /run/firejail/firejail-run.lock [1]+ Stopped firejail --debug id ``` Further calls to firejail will hang due to the stopped process holding the firejail-run lock. ```sh $ firejail id ^C ``` #### After Patch ```sh $ firejail --debug id & P=$!;sleep 0.0005;kill -TSTP $P [1] 16504 Looking for kernel processes Found kthreadd process, we are not running in a sandbox pid=16504: locking /run/firejail/firejail-run.lock ... pid=16504: locked /run/firejail/firejail-run.lock pid=16504: caught SIGTSTP while locks are held pid=16504: unlocking /run/firejail/firejail-run.lock ... pid=16504: unlocked /run/firejail/firejail-run.lock pid=16504: resending caught SIGTSTP [1]+ Stopped firejail --debug id ``` Due to locks being properly released before the process is stopped, new firejail processes will not hang while acquiring the lock. Fixes #6729. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
gitea-mirror 2026-05-05 10:51:41 -06:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/firejail#6151
No description provided.