mount.2: Add EINVAL error condition when MS_BINDing MNT_LOCKED submounts
PATCH 1/1 mount.2: Add EINVAL error condition when MS_BINDing MNT_LOCKED submounts
When the user creates an unpriviledged mount namespace, the linux kernel sets the MNT_LOCKED flag [1] on any submounts to prevent such mounts from being unmounted inside the mount namespace. Such an unmount would reveal the filesystem tree behind the mount, which is not otherwise possible from an unpriviledge vantage point.
Attempting to unmount such a mount will fail with EINVAL. However, less obvious implication is that attempting a bind mount without MS_REC, where the tree being bound contains locked sub-mounts, will also fail with EINVAL, because, without MS_REC, such submounts are effectively being unmounted.
Cursory googling shows several instances of people running into this problem, so I felt it advantageous to have it documented in the man page.
--- man2/mount.2 | 8 ++++++++ 1 file changed, 8 insertions(+)
man2/mount.2 +8 -0
@@ -650,6 +650,14 @@ or .BR EINVAL An attempt was made to bind mount an unbindable mount. .TP +.BR EINVAL +In an unpriviledged mount namespace, a bind operation +.RB ( MS_BIND ) +was attempted without specifying +.RB ( MS_REC ), +which would have revealed the filesytem tree underneath one of +the submounts of the directory being bound. +.TP .B ELOOP Too many links encountered during pathname resolution. .TP
Signature · 6 lines
2.8.1 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 20171127224417.GA5122-9DCaDmOhoh+8M3too/[email protected]
Hello Keno,
Question below....
Quoted 26 lines · Keno Fischer
When the user creates an unpriviledged mount namespace, the linux kernel sets the
MNT_LOCKEDflag [1] on any submounts to prevent such mounts from being unmounted inside the mount namespace. Such an unmount would reveal the filesystem tree behind the mount, which is not otherwise possible from an unpriviledge vantage point.Attempting to unmount such a mount will fail with EINVAL. However, less obvious implication is that attempting a bind mount without
MS_REC, where the tree being bound contains locked sub-mounts, will also fail with EINVAL, because, withoutMS_REC, such submounts are effectively being unmounted.Cursory googling shows several instances of people running into this problem, so I felt it advantageous to have it documented in the man page.
--- man2/mount.2 | 8 ++++++++ 1 file changed, 8 insertions(+)man2/mount.2 +0
-0
man2/mount.2 or · line 654
Quoted 5 lines
man2/mount.2 +2
-0@@ -650,6 +650,14 @@ or .BR EINVAL An attempt was made to bind mount an unbindable mount. .TP +.BR EINVAL +In an unpriviledged mount namespace, a bind operation
What is meant by "an unprivileged mount namespace"?
Thanks,
Michael
Quoted 10 lines
man2/mount.2 +6
-0+.RB ( MS_BIND ) +was attempted without specifying +.RB ( MS_REC ), +which would have revealed the filesytem tree underneath one of +the submounts of the directory being bound. +.TP .B ELOOP Too many links encountered during pathname resolution. .TP
Signature · 7 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): b35b0de4-ef4c-702e-b2d0-a78608fe745b-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 4 lines · Michael Kerrisk (man-pages)
Hello Keno,
Question below....
Quoted 12 lines
man2/mount.2 or · line 654
Quoted 10 lines
man2/mount.2 +2
-0@@ -650,6 +650,14 @@ or .BR EINVAL An attempt was made to bind mount an unbindable mount. .TP +.BR EINVAL +In an unpriviledged mount namespace, a bind operationWhat is meant by "an unprivileged mount namespace"?
Hi Michael,
I believe the only way to create an unprivileged mount namespace is to do so from a user namespace
created by an unprivileged user (that's how I ran into it).
Thanks,
Keno
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hello Keno,
Quoted 19 lines · Keno Fischer
Quoted 4 lines · Michael Kerrisk (man-pages)
Hello Keno,
Question below....
Quoted 12 lines
man2/mount.2 or · line 654
Quoted 10 lines
man2/mount.2 +2
-0@@ -650,6 +650,14 @@ or .BR EINVAL An attempt was made to bind mount an unbindable mount. .TP +.BR EINVAL +In an unpriviledged mount namespace, a bind operationWhat is meant by "an unprivileged mount namespace"?
Quoted 5 lines
Hi Michael,
I believe the only way to create an unprivileged mount namespace is to do so from a user namespace
created by an unprivileged user (that's how I ran into it).
Thanks. I applied your patch, and added some words to clarify the term "unprivileged mount namespace":
(i.e., a mount namespace owned by a user namespace that was created by a unprivileged user)
Cheers,
Michael
Signature · 7 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html