-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Cope with double quotes in Linux Mountinfo #4325
Cope with double quotes in Linux Mountinfo #4325
Conversation
Build succeeded.
|
mount/mountinfo_linux_test.go
Outdated
@@ -439,6 +439,9 @@ const ( | |||
|
|||
mountInfoWithSpaces = `486 28 252:1 / /mnt/foo\040bar rw,relatime shared:243 - ext4 /dev/vda1 rw,data=ordered | |||
31 21 0:23 / /DATA/foo_bla_bla rw,relatime - cifs //foo/BLA\040BLA\040BLA/ rw,sec=ntlm,cache=loose,unc=\\foo\BLA BLA BLA,username=my_login,domain=mydomain.com,uid=12345678,forceuid,gid=12345678,forcegid,addr=10.1.30.10,file_mode=0755,dir_mode=0755,nounix,rsize=61440,wsize=65536,actimeo=1` | |||
|
|||
mountInfoWithDoubleQuotes = `1046 30 253:1 /tmp/bar /var/lib/kubelet/pods/98d150a4-d814-4d52-9068-b10f62d7a895/volumes/kubernetes.io~empty-dir/tmp-dir/"var rw,relatime shared:1 - ext4 /dev/mapper/ubuntu--vg-root rw,errors=remount-ro |
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.
Please also test with a path that contains \"
(backslash + quote)?
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.
Mounting a directory containing a backslash will display it ascii escaped in /proc/self/mountinfo
:
mkdir '/tmp/\"bar\"'
mkdir /tmp/bar
sudo mount --bind /tmp/bar '/tmp/\"bar\"'
cat /proc/self/mountinfo | grep bar
1100 30 253:1 /tmp/bar /tmp/\134"bar\134" rw,relatime shared:1 - ext4 /dev/mapper/ubuntu--vg-root rw,errors=remount-ro
So I added a testcase that receives the backslash ascii character. Did you mean it this way? It seems that a literal \"
cannot show up in the output of /proc/self/mountinfo
.
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, thanks
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.
Just to double-check; the field (as a whole) is never quoted? ("/var/lib/....."
), so no exception is needed for leading/trailing quote?
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.
oh (sorry for the noise); would single quotes have the same problem?
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.
No problem, valid questions 😉. For the latter I added some more test cases.
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.
It seems that a literal " cannot show up in the output of /proc/self/mountinfo
It's not really clear to me then why it is using unquote at all
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.
It's not really clear to me then why it is using unquote at all
So, mountinfo entries quote the following characters, using escape sequences with their octal ascii codes:
\040
\t
(i.e. tab) -- as\011
\n
(i.e. newline) -- as\012
\\
(i.e. backslash) -- as\134
The unquote
was added (by @thaJeztah AFAIR) to convert these escape sequences back to spaces, tabs etc. It does that but messes up double quotes.
I think the solution is to manually interpret the above sequences.
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.
I think the solution is to manually interpret the above sequences.
I mean, write our own function to de-escape \040
, \011
, \012
and \134
instead of using strconv.Unquite
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.
yeah, I agree with that. Looking at the implementation of strconv.Unquote
makes it seem like it is unnecessary to quote then use that. If these are the case we need to test against, then we should add them to the tests.
If you look at the strconv.Unquote
function you will see it first just does some checks whether it contains some of these special characters. This could probably do the same thing and if there is no backslash, just return.
Build succeeded.
|
8f23ce2
to
33d6abc
Compare
Build succeeded.
|
/cc @kolyshkin ptal |
Signed-off-by: Johannes Frey <me@johannes-frey.de>
Signed-off-by: Johannes Frey <me@johannes-frey.de>
Signed-off-by: Johannes Frey <me@johannes-frey.de>
33d6abc
to
8897e15
Compare
Build succeeded.
|
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.
LGTM
if err != nil { | ||
return nil, errors.Wrapf(err, "parsing '%s' failed: unable to unquote root field", fields[3]) | ||
} | ||
p.Mountpoint, err = strconv.Unquote(`"` + fields[4] + `"`) | ||
p.Mountpoint, err = strconv.Unquote(`"` + strings.Replace(fields[4], `"`, `\"`, -1) + `"`) |
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.
Would switching to backquote solve this out the extra replace. https://golang.org/pkg/strconv/#Unquote
`"` -> "`"
Unless of course backquote also needs to be supported...
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.
It seems so:
› cat /proc/self/mountinfo | grep "foo\|bar"
1047 30 253:1 /tmp/`foo` /tmp/bar rw,relatime shared:1 - ext4 /dev/mapper/ubuntu--vg-root rw,errors=remount-ro
I added a test case containing backticks as well.
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.
with backticks, \040
is not expanded and this brings back the bug that the initial unquote
solves.
Build succeeded.
|
Signed-off-by: Johannes Frey <me@johannes-frey.de>
5d09a5b
to
ee734e8
Compare
Build succeeded.
|
Left a suggestion (#4325 (comment)) on how to fix this effectively. WRT test cases -- I would separate out the filename unquote function and write test cases for it. In general, I would love this repo to switch to using |
Fixed the same bug in It would be beneficial to reuse that repo here; if not, the fix can be ported. |
Doing a direct escape seems like the right thing to do here. Adding a dependency doesn't make much sense for this change, especially since we have avoided bringing in this dependency in the past. @kolyshkin is there any documentation you can link to related to that set of characters or just the use of octal encoding in that file? |
I am not proposing the use of moby/sys/mountinfo for this particular change, but rather for overall simplification and easement of maintenance burden. containerd's mountinfo is a fork of the one in moby, and now every bugfix, feature, or improvement needs to be done in two places.
You're probably talking about moby/moby. Using packages from moby/moby is not possible, as it will lead to circular dependencies. This was one of the main reasons why moby/sys was born -- it does not have any outside deps and can be used by any project. After cross-porting some stuff from moby and containerd and back, I think the best solution long-term is to have a single place for such stuff. I remember @crosbymichael at least considered the idea of using moby/sys in containerd earlier.
Probably not (there's proc(5) man page that describes mountinfo, but it does not mention escaping). The source for what I wrote earlier is kernel source code, specifically, |
In addition to source code references above, today I found https://www.kernel.org/doc/Documentation/filesystems/seq_file.txt (look for seq_escape) which might add some more context. |
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.
LGTM
This is a small PR with mostly tests, let's get this merged then moving away from Unquote
can be a follow up
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.
LGTM
This adds tests for handling paths containing double quotes, and is the equivalent to the changes made in containerd/containerd#4325 to fix the problem described in containerd/containerd#4257 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This adds tests for handling paths containing double quotes, and is the equivalent of the tests added in containerd/containerd#4325 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This PR resolves the double quote problem described in issue #4257