-
Notifications
You must be signed in to change notification settings - Fork 18.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix parseInfoFile does not handle spaces in filenames #38977
Conversation
ping @kolyshkin @cpuguy83 PTAL |
c668e38
to
d17e07a
Compare
pkg/mount/mountinfo_linux.go
Outdated
@@ -52,8 +56,17 @@ func parseInfoFile(r io.Reader, filter FilterFunc) ([]*Info, error) { | |||
p.Major, _ = strconv.Atoi(mm[0]) | |||
p.Minor, _ = strconv.Atoi(mm[1]) | |||
|
|||
p.Root = fields[3] | |||
p.Mountpoint = fields[4] | |||
r, err := strconv.Unquote(`"` + fields[3] + `"`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to kernel sources, the only characters replaced by \nnn
are space, tab, newline, and backslash (\
).
Initially I was opposed to using strconv.Unquote()
but it seems if \
is always escaped, Unquote
can do no harm.
BTW, note that Linux file paths can indeed contain newlines, tabs, and backslashes :=0
pkg/mount/mountinfo_linux.go
Outdated
} | ||
p.Root = r | ||
|
||
mp, err := strconv.Unquote(`"` + fields[4] + `"`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to have a temp variable here, since you exit on error anyway, so maybe
root.Mountpoint, err := strconv.Unquote(`"` + fields[4] + `"`)
if err != nil {
 return nil, errors.Wrapf(err, "Can't parse mount point %q", fields[4])
}
(I have also made error message smaller, but it's up to you)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I wanted to do a follow up to fix the error messages (also make them lowercase); for this fix, I went for consistency with the existing ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few comments, but it's all very minor nitpicks so LGTM
BTW this needs to be ported to containerd, too. (as a side note, I am puzzled why I haven't fixed this as part of https://github.com/moby/moby/pull/36091as I was very much aware of the issue) |
d17e07a
to
57de474
Compare
Codecov Report
@@ Coverage Diff @@
## master #38977 +/- ##
=========================================
Coverage ? 36.89%
=========================================
Files ? 614
Lines ? 45414
Branches ? 0
=========================================
Hits ? 16756
Misses ? 26365
Partials ? 2293 |
Updated; removed the intermediate variable (no other changes) |
`/proc/self/mountinfo` uses `\040` for spaces, however, `parseInfoFile()` did not decode those spaces in paths, therefore attempting to use `\040` as a literal part of the path. This patch un-quotes the `root` and `mount point` fields to fix situations where paths contain spaces. Note that the `mount source` field is not modified, given that this field is documented (man `PROC(5)`) as: filesystem-specific information or "none" Which I interpreted as "the format in this field is undefined". Reported-by: Daniil Yaroslavtsev <daniilyar@users.noreply.github.com> Reported-by: Nathan Ringo <remexre@gmail.com> Based-on-patch-by: Diego Becciolini <itizir@users.noreply.github.com> Based-on-patch-by: Sergei Utinski <sergei-utinski@users.noreply.github.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
57de474
to
58d8625
Compare
Moby PR #38977 [1] and containerd PR #3159 [2] added the handing of escape sequences in mountinfo paths (root and mountpoint fields). Unfortunately, it also broke the handling of paths containing double quotes, as it was pointed out in [3]. The solution is to stop using strconv.Unquote and write our own specialized function to deal with escape sequences. Unit tests added. [1] moby/moby#38977 [2] containerd/containerd#3159 [3] containerd/containerd#4257 Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Moby PR #38977 [1] and containerd PR #3159 [2] added the handing of escape sequences in mountinfo paths (root and mountpoint fields). Unfortunately, it also broke the handling of paths containing double quotes, as it was pointed out in [3]. The solution is to stop using strconv.Unquote and write our own specialized function to deal with escape sequences. Unit tests added. [1] moby/moby#38977 [2] containerd/containerd#3159 [3] containerd/containerd#4257 Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Moby PR #38977 [1] and containerd PR #3159 [2] added the handing of escape sequences in mountinfo paths (root and mountpoint fields). Unfortunately, it also broke the handling of paths containing double quotes, as it was pointed out in [3]. The solution is to stop using strconv.Unquote and write our own specialized function to deal with escape sequences. Unit tests added. [1] moby/moby#38977 [2] containerd/containerd#3159 [3] containerd/containerd#4257 Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
fixes #38458
addresses kubernetes/kubernetes#35062
/proc/self/mountinfo
uses\040
for spaces, however,parseInfoFile()
did not decode those spaces in paths, therefore attempting to use
\040
as a literal part of the path.
This patch un-quotes the
root
andmount point
fields to fixsituations where paths contain spaces.
Note that the
mount source
field is not modified, given thatthis field is documented (man
PROC(5)
) as:Which I interpreted as "the format in this field is undefined".
Thanks to @remexre for reporting, and @itizir, @sergei-utinski for suggesting the patch.