Skip to content

Conversation

starius
Copy link
Collaborator

@starius starius commented Sep 1, 2025

Change Description

Root can bypass read-only file permissions, which made the test failure confusing: a file was overwritten even though it shouldn't have been. This is caused by process capability CAP_DAC_OVERRIDE which root processes often have in Linux. To workaround this, the owner of the file is changed to uid=1000 and gid=1000 (root can do it). If a file belongs to a world-writable sticky dir (like /tmp where the tested file is created) and fs.protected_regular kernel feature is enabled (a common practice on modern Linux distros), such file can't be overwritten by root.

Steps to Test

$ cd fn/

$ go test -v -run TestWriteFile
=== RUN   TestWriteFile
=== PAUSE TestWriteFile
=== RUN   TestWriteFileRemove
=== PAUSE TestWriteFileRemove
=== CONT  TestWriteFile
=== CONT  TestWriteFileRemove
--- PASS: TestWriteFileRemove (0.03s)
--- PASS: TestWriteFile (0.04s)
PASS
ok      github.com/lightningnetwork/lnd/fn/v2   0.040s

$ sudo su
# go test -v -run TestWriteFile
=== RUN   TestWriteFile
=== PAUSE TestWriteFile
=== RUN   TestWriteFileRemove
=== PAUSE TestWriteFileRemove
=== CONT  TestWriteFile
=== CONT  TestWriteFileRemove
--- PASS: TestWriteFile (0.01s)
--- PASS: TestWriteFileRemove (0.01s)
PASS
ok      github.com/lightningnetwork/lnd/fn/v2   0.017s
# 

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

Root can bypass read-only file permissions, which made the test failure
confusing: a file was overwritten even though it shouldn't have been. This is
caused by process capability CAP_DAC_OVERRIDE which root processes often have in
Linux. To workaround this, the owner of the file is changed to uid=1000 and
gid=1000 (root can do it). If a file belongs to a world-writable sticky dir
(like /tmp where the tested file is created) and fs.protected_regular kernel
feature is enabled (a common practice on modern Linux distros), such file can't
be overwritten by root.
@starius starius marked this pull request as ready for review September 2, 2025 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant