Skip to content

Setuid/setgid/sticky bits are silently stripped from rewritten files #18

Description

@dolph

Summary

rewriteFile calls os.Chmod(tmpName, mode.Perm()) to restore the original mode, but Mode.Perm() only retains the low 9 bits (rwxrwxrwx). The setuid (S_ISUID), setgid (S_ISGID), and sticky (S_ISVTX) bits are discarded.

After rename, those bits are not present on the destination inode either (Linux strips them on rename across uids).

Impact (Security: Low/Medium)

  • Setuid binaries rewritten by find-replace silently lose their setuid bit. If a user mistakenly runs find-replace over /usr/local/bin, scripts that depend on setuid stop working.
  • Setgid directories — used to enforce group ownership inheritance — lose that bit if accidentally renamed/rewritten through this path. (Directories are not rewritten, but if a setgid bit is on a file, it would be stripped.)

Suggested Fix

Detect the special bits before rewriting and either:

Files

  • file_handling.go:60-149 (rewriteFile)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions