Skip to content

mountinfo: linux procfs traversing method may leads to mountinfo loss #161

@zhaodiaoer

Description

@zhaodiaoer

Currently, on Linux, the way to obtain mount information entirely depends on traversing the procfs (such as /proc/self/mountinfo, /proc/<pid>/mountinfo, etc.). However, this method is not safe. An ongoing unmount event from other process on the system may cause the current read request to be subject to a race condition, especially when the mountinfo content is relatively large or the traversal process is relatively slow, this is because the procfs file interface for mountinfo implemented in linux can only guarantee atomicity within a single read syscall, although theses read calls are still within the context of a single open call.

I have tried to avoid this problem by increasing the read size to try to read all contents of mountinfo in just once-only read call. However, each read call can only read data up to the size of one pagesize at most. This is also a limitation of the implementation principle of procfs.

I have also noticed the two new interfaces listmount(2)/statmount(2) provided in the new kernel mentioned in #139 . However, the listmount interface can only return a list of all mount IDs. If we want to achieve an effect equivalent to traversing the mountinfo file, we may need to rely on adding many new system calls, and these two new interfaces rely on a kernel version that is too new, It is difficult to promote their full popularity in a short time, so I want to know if there are currently any other possible solutions worthy of expectation (such as use eBPF to inject some filter into kernel space? but i haven't thought when and how to trigger it)

Due to this problem, we have encountered a mount leak issue in the runc. Therefore, I did not add these informations in #139 . Instead, I opened a separate issue because I think this problem is more suitable to be treated as a bug compared to performance improvement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions