mountinfo: correctness improvements#50
Conversation
The previous code would actually ignore IO errors during scanning,
becuase s.Scan() returns false if there was an error (leaving the loop
and never being detected). Indeed the correct way[1] of using the
builtin bufio.Scanner is actually more like:
s := bufio.NewScanner(...)
for s.Scan() {
// use s.Text()
}
if err := s.Err(); err != nil {
return err
}
[1]: https://blog.golang.org/errors-are-values
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
| @@ -18,11 +18,9 @@ import ( | |||
| func GetMountsFromReader(r io.Reader, filter FilterFunc) ([]*Info, error) { | |||
There was a problem hiding this comment.
Added. There were a few for this function already, just not one for the FilterFunc callback.
This is actually documented: sys/mountinfo/mountinfo_filters.go Lines 5 to 16 in 95f2efb so the second commit needs to be amended accordingly. There is also a comment in the code that needs to be removed: sys/mountinfo/mountinfo_linux.go Line 77 in 95f2efb Otherwise LGTM |
kolyshkin
left a comment
There was a problem hiding this comment.
Need to update FilterFunc docs and remove a comment in the code (see above).
Ah, I was looking at the docs of this function not |
Previously, the filter would be run before all of the fields were parsed (this behaviour also was not documented) -- this resulted in users of the function accidentally assuming that fields like fsinfo.Root would actually be filled correctly. It seems that the performance overhead of parsing a few extra fields is not exorbitant, and optimising this just leads to incorrect user code. For a concrete example, this optimisation actually made this runc change[1] regress a security hardening feature because it relied on fsinfo.Root being filled correctly. [1]: opencontainers/runc#2647 Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
e991eae to
41fc4b7
Compare
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
|
@kolyshkin should we tag a new release with this? |
I already did, https://github.com/moby/sys/releases/tag/mountinfo%2Fv0.4.0 Yet there are no users that are affected (runc was, but this is being fixed by opencontainers/runc#2655) |
|
Oh! Somehow didn't get a notification; thanks! |
This fixes two correctness issues with mountinfo (one of which caused opencontainers/runc#2647 to be a security regression):
Signed-off-by: Aleksa Sarai cyphar@cyphar.com