Skip to content

Commit

Permalink
mountinfo: linux: use /proc/thread-self/mountinfo
Browse files Browse the repository at this point in the history
In a Go program with many threads, which goroutine is running on the
thread-group leader thread is not something programs can controls. Thus,
even if you use runtime.LockOSThread() for threads that have different
mount namespaces, it's possible that /proc/self will refer to the
"wrong" thread.

The solution is to simply use /proc/thread-self, which will always
provide the correct result for the calling thread.

The usage of /proc/self/mountinfo caused isuses for a patch to runc
which creates a thread to create id-mapped mounts (which requires
joining the container mount namespace).

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
  • Loading branch information
cyphar committed Aug 24, 2023
1 parent eac9a7f commit 7049be0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mountinfo/mountinfo_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func GetMountsFromReader(r io.Reader, filter FilterFunc) ([]*Info, error) {
}

func parseMountTable(filter FilterFunc) ([]*Info, error) {
f, err := os.Open("/proc/self/mountinfo")
f, err := os.Open("/proc/thread-self/mountinfo")
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 7049be0

Please sign in to comment.