Suppress setuid and setgid on shebang scripts#199
Merged
Conversation
jserv
requested changes
Jul 15, 2026
jserv
left a comment
Contributor
There was a problem hiding this comment.
Refined based on the review from @cubic-dev-ai . If you disagree with any of its feedback, discuss it with the reviewer to reach a consensus and consolidate the shared knowledge base.
doanbaotrung
force-pushed
the
setuid-setgid
branch
2 times, most recently
from
July 15, 2026 15:25
6f1545e to
48a67e2
Compare
The Linux kernel (fs/exec.c bprm_fill_uid) deliberately ignores setuid/setgid bits on interpreted scripts to prevent privilege escalation via interpreter manipulation. elfuse had no such guard: exec_is_script was never tracked, so the setuid/setgid check was effectively always true for all executables. Fix by: - Snapshotting the directly-executed file's stat() before the shebang resolution loop overwrites path_host with the final interpreter path. - Setting exec_is_script = true on the first confirmed shebang (rc > 0 from elf_read_shebang), so deeply nested chains also trip the flag. - After elf_load, applying S_ISUID/S_ISGID only when the directly-executed file was a regular non-script ELF. - Honouring the kernel's S_ISGID-requires-S_IXGRP rule to distinguish mandatory-locking GIDs from setgid execution. Fix sysprog21#138
doanbaotrung
force-pushed
the
setuid-setgid
branch
from
July 15, 2026 15:33
48a67e2 to
e862632
Compare
Collaborator
Author
|
Fixed all the comments |
Contributor
|
Thank @doanbaotrung for contributing! |
henrybear327
pushed a commit
to henrybear327/elfuse
that referenced
this pull request
Jul 17, 2026
The Linux kernel (fs/exec.c bprm_fill_uid) deliberately ignores setuid/setgid bits on interpreted scripts to prevent privilege escalation via interpreter manipulation. elfuse had no such guard: exec_is_script was never tracked, so the setuid/setgid check was effectively always true for all executables. Fix by: - Snapshotting the directly-executed file's stat() before the shebang resolution loop overwrites path_host with the final interpreter path. - Setting exec_is_script = true on the first confirmed shebang (rc > 0 from elf_read_shebang), so deeply nested chains also trip the flag. - After elf_load, applying S_ISUID/S_ISGID only when the directly-executed file was a regular non-script ELF. - Honouring the kernel's S_ISGID-requires-S_IXGRP rule to distinguish mandatory-locking GIDs from setgid execution. Close sysprog21#138 Close sysprog21#139 Co-authored-by: Trung <trung_bao.d@kbtgvn.tech>
henrybear327
pushed a commit
to henrybear327/elfuse
that referenced
this pull request
Jul 17, 2026
The Linux kernel (fs/exec.c bprm_fill_uid) deliberately ignores setuid/setgid bits on interpreted scripts to prevent privilege escalation via interpreter manipulation. elfuse had no such guard: exec_is_script was never tracked, so the setuid/setgid check was effectively always true for all executables. Fix by: - Snapshotting the directly-executed file's stat() before the shebang resolution loop overwrites path_host with the final interpreter path. - Setting exec_is_script = true on the first confirmed shebang (rc > 0 from elf_read_shebang), so deeply nested chains also trip the flag. - After elf_load, applying S_ISUID/S_ISGID only when the directly-executed file was a regular non-script ELF. - Honouring the kernel's S_ISGID-requires-S_IXGRP rule to distinguish mandatory-locking GIDs from setgid execution. Close sysprog21#138 Close sysprog21#139 Co-authored-by: Trung <trung_bao.d@kbtgvn.tech>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Linux kernel (fs/exec.c bprm_fill_uid) deliberately ignores setuid/setgid bits on interpreted scripts to prevent privilege escalation via interpreter manipulation. elfuse had no such guard: exec_is_script was never tracked, so the setuid/setgid check was effectively always true for all executables.
Fix by:
Fix #138
Fix #139
Summary by cubic
Suppress setuid/setgid on shebang scripts to match Linux and prevent privilege escalation. Switch exec to fd-based loading/mapping with execute-permission checks to avoid TOCTOU.
Fixes #138.
Written for commit e862632. Summary will update on new commits.