BSD mountinfo implementation is unsound
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 101
- Forks
- 61
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 5
Description
There are two problems:
-
According to the documentation of
reflect.SliceHeaderit's never safe to modify or otherwise make use of the contents ofSliceHeader:SliceHeader is the runtime representation of a slice. It cannot be used safely or portably and its representation may change in a later release. Moreover, the Data field is not sufficient to guarantee the data it references will not be garbage collected, so programs must keep a separate, correctly typed pointer to the underlying data.
I'm sure that this is more of a CYA statement than anything else, but it does mean that technically our usage of this is unsound -- and ultimately the fix is just to switch to a C-style loop over the pointers.
-
getmntinfomodifies a global variable, which means that if multiple goroutines try to get mountinfo at the same time we will end up potentially modifying the global structure during iteration. We could work around this by mutexing it or something, but a simpler solution would be to just usegetfsstat(2)which allows us to pass our own allocated array.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the BSD mountinfo implementation and its use of getmntinfo and reflect.SliceHeader. Review the SliceHeader documentation and the getfsstat(2) interface, then verify the result with the existing tests or mountinfo checks. Done means avoiding SliceHeader access and preventing concurrent iteration over a shared mountinfo structure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100