Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1371063 > unrolled thread
| Started by | ebiederm@xmission.com (Eric W. Biederman) |
|---|---|
| First post | 2016-04-05 02:20 +0200 |
| Last post | 2016-04-11 22:20 +0200 |
| Articles | 20 on this page of 70 — 7 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 00/13] devpts: New instances for every mount ebiederm@xmission.com (Eric W. Biederman) - 2016-04-05 02:20 +0200
[PATCH 04/13] devpts: Stop rolling devpts_remount by hand in devpts_mount "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-05 03:50 +0200
[PATCH 05/13] devpts: Fail early (if appropriate) on overmount "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-05 03:50 +0200
[PATCH 08/13] devpts: Make devpts_kill_sb safe if fsi is NULL "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-05 03:50 +0200
[PATCH 03/13] devpts: Cleanup newinstance parsing "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-05 03:50 +0200
[PATCH 06/13] devpts: Use the same default mode for both /dev/ptmx and dev/pts/ptmx "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-05 03:50 +0200
[PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-05 03:50 +0200
[PATCH 09/13] devpts: Move the creation of /dev/pts/ptmx into fill_super "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-05 03:50 +0200
[PATCH 02/13] devpts: More obvious check for the system devpts in pty allocation "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-05 03:50 +0200
[PATCH 13/13] devpts: Kill the DEVPTS_MULTIPLE_INSTANCE config option "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-05 03:50 +0200
[PATCH 07/13] devpts: Move parse_mount_options into fill_super "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-05 03:50 +0200
[PATCH 12/13] devpts: Always return a distinct instance when mounting "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-05 04:00 +0200
[PATCH 11/13] vfs: Implement mount_super_once "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-05 04:00 +0200
[PATCH 10/13] devpts: Simplify devpts_mount by using mount_nodev "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-05 04:00 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Al Viro <viro@ZenIV.linux.org.uk> - 2016-04-05 05:00 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Al Viro <viro@ZenIV.linux.org.uk> - 2016-04-05 05:10 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup ebiederm@xmission.com (Eric W. Biederman) - 2016-04-08 21:10 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Linus Torvalds <torvalds@linux-foundation.org> - 2016-04-07 18:10 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup ebiederm@xmission.com (Eric W. Biederman) - 2016-04-08 21:10 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Linus Torvalds <torvalds@linux-foundation.org> - 2016-04-08 21:10 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup ebiederm@xmission.com (Eric W. Biederman) - 2016-04-08 22:20 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Andy Lutomirski <luto@amacapital.net> - 2016-04-08 22:50 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup ebiederm@xmission.com (Eric W. Biederman) - 2016-04-08 23:50 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Andy Lutomirski <luto@amacapital.net> - 2016-04-09 00:00 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Linus Torvalds <torvalds@linux-foundation.org> - 2016-04-09 00:00 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup ebiederm@xmission.com (Eric W. Biederman) - 2016-04-09 01:20 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk> - 2016-04-09 15:20 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup "H. Peter Anvin" <hpa@zytor.com> - 2016-04-09 16:20 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup ebiederm@xmission.com (Eric W. Biederman) - 2016-04-09 17:00 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup "H. Peter Anvin" <hpa@zytor.com> - 2016-04-10 00:50 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Linus Torvalds <torvalds@linux-foundation.org> - 2016-04-10 02:10 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup "H. Peter Anvin" <hpa@zytor.com> - 2016-04-10 02:20 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Linus Torvalds <torvalds@linux-foundation.org> - 2016-04-10 02:20 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Andy Lutomirski <luto@amacapital.net> - 2016-04-10 02:50 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup "H. Peter Anvin" <hpa@zytor.com> - 2016-04-11 17:10 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Al Viro <viro@ZenIV.linux.org.uk> - 2016-04-12 03:40 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Andy Lutomirski <luto@amacapital.net> - 2016-04-11 22:20 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup "H. Peter Anvin" <hpa@zytor.com> - 2016-04-11 22:30 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup ebiederm@xmission.com (Eric W. Biederman) - 2016-04-12 01:50 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Linus Torvalds <torvalds@linux-foundation.org> - 2016-04-12 02:10 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup ebiederm@xmission.com (Eric W. Biederman) - 2016-04-12 02:30 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Linus Torvalds <torvalds@linux-foundation.org> - 2016-04-12 03:20 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup "H. Peter Anvin" <hpa@zytor.com> - 2016-04-12 03:20 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup ebiederm@xmission.com (Eric W. Biederman) - 2016-04-12 03:40 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Al Viro <viro@ZenIV.linux.org.uk> - 2016-04-12 03:50 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Al Viro <viro@ZenIV.linux.org.uk> - 2016-04-12 03:40 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup ebiederm@xmission.com (Eric W. Biederman) - 2016-04-12 04:30 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup ebiederm@xmission.com (Eric W. Biederman) - 2016-04-11 22:30 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Andy Lutomirski <luto@amacapital.net> - 2016-04-12 19:50 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Linus Torvalds <torvalds@linux-foundation.org> - 2016-04-12 20:20 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup "H. Peter Anvin" <hpa@zytor.com> - 2016-04-12 21:20 +0200
[PATCH 01/16] devpts: Attempting to get it right ebiederm@xmission.com (Eric W. Biederman) - 2016-04-15 17:50 +0200
[PATCH 08/16] devpts: Stop rolling devpts_remount by hand in devpts_mount "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-15 17:50 +0200
[PATCH 05/16] vfs: Allow unlink, and rename on expirable file mounts "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-15 17:50 +0200
[PATCH 04/16] devpts: Teach /dev/ptmx to automount the appropriate devpts via path lookup "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-15 17:50 +0200
[PATCH 09/16] devpts: Fail early (if appropriate) on overmount "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-15 17:50 +0200
[PATCH 10/16] devpts: Move parse_mount_options into fill_super "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-15 17:50 +0200
[PATCH 06/16] devpts: More obvious check for the system devpts in pty allocation "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-15 17:50 +0200
[PATCH 01/16] devpts: Use the same default mode for both /dev/ptmx and dev/pts/ptmx "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-15 17:50 +0200
[PATCH 12/16] devpts: Move the creation of /dev/pts/ptmx into fill_super "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-15 18:00 +0200
[PATCH 11/16] devpts: Make devpts_kill_sb safe if fsi is NULL "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-15 18:00 +0200
[PATCH 16/16] devpts: Kill the DEVPTS_MULTIPLE_INSTANCE config option "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-15 18:00 +0200
[PATCH 15/16] devpts: Always return a distinct instance when mounting "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-15 18:00 +0200
[PATCH 13/16] devpts: Simplify devpts_mount by using mount_nodev "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-15 18:00 +0200
[PATCH 14/16] vfs: Implement mount_super_once "Eric W. Biederman" <ebiederm@xmission.com> - 2016-04-15 18:00 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup ebiederm@xmission.com (Eric W. Biederman) - 2016-04-12 02:10 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Linus Torvalds <torvalds@linux-foundation.org> - 2016-04-12 02:10 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup ebiederm@xmission.com (Eric W. Biederman) - 2016-04-12 02:40 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup Linus Torvalds <torvalds@linux-foundation.org> - 2016-04-12 03:00 +0200
Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup ebiederm@xmission.com (Eric W. Biederman) - 2016-04-11 22:20 +0200
Page 3 of 4 — ← Prev page 1 2 [3] 4 Next page →
| From | ebiederm@xmission.com (Eric W. Biederman) |
|---|---|
| Date | 2016-04-12 02:30 +0200 |
| Subject | Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup |
| Message-ID | <rmUno-6qa-1@gated-at.bofh.it> |
| In reply to | #1376355 |
Linus Torvalds <torvalds@linux-foundation.org> writes: > On Mon, Apr 11, 2016 at 4:37 PM, Eric W. Biederman > <ebiederm@xmission.com> wrote: >> >> My practical concern if we worked through the implementation details >> would be how would it interact with people who bind mount /dev/pts/ptmx >> on top of /dev/ptmx. We might get some strange new errors. > > Yes, please don't let's play "clever" games. The semantics should be > fairly straightforward. Actually for me this is about keeping the semantics simpler, and coming up with a higher performance implementation. A dentry that does an automount is already well defined. Making the rule that accessing /dev/ptmx causes an automount of /dev/pts/ptmx on top of the device node at /dev/ptmx is really simple, with no special games. It also makes it more obvious to userspace what is going on. AKA allows userspace to know which superblock does an open ptmx master tty belongs to (and it happens in a backwards and forwards compatible way). My only concern is with this very minor change in semantics will anything care. I need to implement and test to find out. I think I see an implementation that Al won't grumble too loudly about. Anyway I am going to try this and see what I can see. Eric
[toc] | [prev] | [next] | [standalone]
| From | Linus Torvalds <torvalds@linux-foundation.org> |
|---|---|
| Date | 2016-04-12 03:20 +0200 |
| Subject | Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup |
| Message-ID | <rmV9M-76T-17@gated-at.bofh.it> |
| In reply to | #1376357 |
On Mon, Apr 11, 2016 at 6:06 PM, H. Peter Anvin <hpa@zytor.com> wrote:
>
> Why bother with an automount? You can look up ../ptmx from the devpts get_super method and just do the bind mount once. No fuss, no muss. What's wrong with that?
Ehh. What if somebody wants to mount the same devpts in multiple
places? So now you need to do the bind mount every time devpts is
bindmounted?
None of this makes sense.
Let's just take Eric's patch, and strip out the permission check, and
strip out the code that fakes a new path for it.
That gets rid of 90% of devpts_path_ptmx(): all that remains is pretty
much the "are we already in devpts" and the call to "path_pts()"
thing.
No update_file_path(), no inode_permissions, no fsi->ptmx_dentry
games. Just get a reference to the "pts_fs_info", and it's all done.
(Getting a ref on the pts_fs_info might require us to have a ref to
the superblock, I didn't check that part. But rather than updating the
file path, just save it off in the file data).
Linus
[toc] | [prev] | [next] | [standalone]
| From | "H. Peter Anvin" <hpa@zytor.com> |
|---|---|
| Date | 2016-04-12 03:20 +0200 |
| Subject | Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup |
| Message-ID | <rmV9M-76T-13@gated-at.bofh.it> |
| In reply to | #1376357 |
On April 11, 2016 5:10:47 PM PDT, ebiederm@xmission.com wrote: >Linus Torvalds <torvalds@linux-foundation.org> writes: > >> On Mon, Apr 11, 2016 at 4:37 PM, Eric W. Biederman >> <ebiederm@xmission.com> wrote: >>> >>> My practical concern if we worked through the implementation details >>> would be how would it interact with people who bind mount >/dev/pts/ptmx >>> on top of /dev/ptmx. We might get some strange new errors. >> >> Yes, please don't let's play "clever" games. The semantics should be >> fairly straightforward. > >Actually for me this is about keeping the semantics simpler, and coming >up with a higher performance implementation. > >A dentry that does an automount is already well defined. > >Making the rule that accessing /dev/ptmx causes an automount of >/dev/pts/ptmx on top of the device node at /dev/ptmx is really simple, >with no special games. It also makes it more obvious to userspace what >is going on. AKA allows userspace to know which superblock does an >open >ptmx master tty belongs to (and it happens in a backwards and forwards >compatible way). > >My only concern is with this very minor change in semantics will >anything care. I need to implement and test to find out. > >I think I see an implementation that Al won't grumble too loudly about. > >Anyway I am going to try this and see what I can see. > >Eric Why bother with an automount? You can look up ../ptmx from the devpts get_super method and just do the bind mount once. No fuss, no muss. What's wrong with that? -- Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.
[toc] | [prev] | [next] | [standalone]
| From | ebiederm@xmission.com (Eric W. Biederman) |
|---|---|
| Date | 2016-04-12 03:40 +0200 |
| Subject | Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup |
| Message-ID | <rmVt8-7gi-5@gated-at.bofh.it> |
| In reply to | #1376375 |
"H. Peter Anvin" <hpa@zytor.com> writes: > On April 11, 2016 5:10:47 PM PDT, ebiederm@xmission.com wrote: >>Linus Torvalds <torvalds@linux-foundation.org> writes: >> >>> On Mon, Apr 11, 2016 at 4:37 PM, Eric W. Biederman >>> <ebiederm@xmission.com> wrote: >>>> >>>> My practical concern if we worked through the implementation details >>>> would be how would it interact with people who bind mount >>/dev/pts/ptmx >>>> on top of /dev/ptmx. We might get some strange new errors. >>> >>> Yes, please don't let's play "clever" games. The semantics should be >>> fairly straightforward. >> >>Actually for me this is about keeping the semantics simpler, and coming >>up with a higher performance implementation. >> >>A dentry that does an automount is already well defined. >> >>Making the rule that accessing /dev/ptmx causes an automount of >>/dev/pts/ptmx on top of the device node at /dev/ptmx is really simple, >>with no special games. It also makes it more obvious to userspace what >>is going on. AKA allows userspace to know which superblock does an >>open >>ptmx master tty belongs to (and it happens in a backwards and forwards >>compatible way). >> >>My only concern is with this very minor change in semantics will >>anything care. I need to implement and test to find out. >> >>I think I see an implementation that Al won't grumble too loudly about. >> >>Anyway I am going to try this and see what I can see. >> >>Eric > > Why bother with an automount? You can look up ../ptmx from the devpts > get_super method and just do the bind mount once. No fuss, no muss. > What's wrong with that? Perhaps I am reading the code wrong but as I read it that information is simply not available in get_super. Eric
[toc] | [prev] | [next] | [standalone]
| From | Al Viro <viro@ZenIV.linux.org.uk> |
|---|---|
| Date | 2016-04-12 03:50 +0200 |
| Subject | Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup |
| Message-ID | <rmVCN-7ks-1@gated-at.bofh.it> |
| In reply to | #1376380 |
On Mon, Apr 11, 2016 at 08:23:00PM -0500, Eric W. Biederman wrote: > Perhaps I am reading the code wrong but as I read it that information is > simply not available in get_super. Correct. For a very good reason - the same superblock can bloody well end up in many places; having it tied to _the_ mountpoint is just plain wrong. You know how it would look done right? a) mount --after support b) devpts containing both /ptmx and /pts/1,... c) mount --type devpts --after none /dev That's it. And this would be way, way more useful that overlay-style unions; it would *NOT* recurse into subdirectories. Just a search list done right... Not an option, unfortunately, since it obviously breaks userland setups - even if we go ahead and implement that kind of non-recursive unions. But if we had a chance to design it from scratch, that would've been an interesting option.
[toc] | [prev] | [next] | [standalone]
| From | Al Viro <viro@ZenIV.linux.org.uk> |
|---|---|
| Date | 2016-04-12 03:40 +0200 |
| Subject | Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup |
| Message-ID | <rmVt7-7gi-1@gated-at.bofh.it> |
| In reply to | #1376357 |
On Mon, Apr 11, 2016 at 07:10:47PM -0500, Eric W. Biederman wrote: > Actually for me this is about keeping the semantics simpler, and coming > up with a higher performance implementation. > > A dentry that does an automount is already well defined. > > Making the rule that accessing /dev/ptmx causes an automount of > /dev/pts/ptmx on top of the device node at /dev/ptmx is really simple, > with no special games. It also makes it more obvious to userspace what > is going on. AKA allows userspace to know which superblock does an open > ptmx master tty belongs to (and it happens in a backwards and forwards > compatible way). _What_ dentry? Which filesystem would that be done to? Whatever we have on /dev? Or we suddenly get the fucking dentry operations change when dentry is attached to magical cdev inode?
[toc] | [prev] | [next] | [standalone]
| From | ebiederm@xmission.com (Eric W. Biederman) |
|---|---|
| Date | 2016-04-12 04:30 +0200 |
| Subject | Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup |
| Message-ID | <rmWfv-7YP-1@gated-at.bofh.it> |
| In reply to | #1376379 |
Al Viro <viro@ZenIV.linux.org.uk> writes:
> On Mon, Apr 11, 2016 at 07:10:47PM -0500, Eric W. Biederman wrote:
>> Actually for me this is about keeping the semantics simpler, and coming
>> up with a higher performance implementation.
>>
>> A dentry that does an automount is already well defined.
>>
>> Making the rule that accessing /dev/ptmx causes an automount of
>> /dev/pts/ptmx on top of the device node at /dev/ptmx is really simple,
>> with no special games. It also makes it more obvious to userspace what
>> is going on. AKA allows userspace to know which superblock does an open
>> ptmx master tty belongs to (and it happens in a backwards and forwards
>> compatible way).
>
> _What_ dentry? Which filesystem would that be done to? Whatever we have
> on /dev? Or we suddenly get the fucking dentry operations change when
> dentry is attached to magical cdev inode?
Which dentry? Any dentry that corresponds to the /dev/ptmx inode.
No filesystem changes just magic in init_special_inode that I have
not completely figured out yet.
If we can get an automount method in follow_automount from somewhere
cdev specific then a cdev can perform an automount comparitively
cleanly. file_operations is attractive I am have not yet figured out a
clean method for passing the automount method yet.
For my proof of concept I am hardcoding things based on i_rdev. Ugly
but servicable for testing out the idea.
A snip of my proof of concept code that seems to be working:
diff --git a/fs/inode.c b/fs/inode.c
index 69b8b526c194..d3de77b01a84 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -18,6 +18,7 @@
#include <linux/buffer_head.h> /* for inode_has_buffers */
#include <linux/ratelimit.h>
#include <linux/list_lru.h>
+#include <linux/devpts_fs.h>
#include <trace/events/writeback.h>
#include "internal.h"
@@ -1917,6 +1918,11 @@ void init_special_inode(struct inode *inode, umode_t mode, dev_t rdev)
if (S_ISCHR(mode)) {
inode->i_fop = &def_chr_fops;
inode->i_rdev = rdev;
+#if CONFIG_UNIX98_PTYS
+ if (rdev == MKDEV(TTYAUX_MAJOR, PTMX_MINOR)) {
+ inode->i_flags |= S_AUTOMOUNT;
+ }
+#endif
} else if (S_ISBLK(mode)) {
inode->i_fop = &def_blk_fops;
inode->i_rdev = rdev;
diff --git a/fs/namei.c b/fs/namei.c
index afb5137ca199..8894cf5fb43e 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -35,6 +35,8 @@
#include <linux/fs_struct.h>
#include <linux/posix_acl.h>
#include <linux/hash.h>
+#include <linux/devpts_fs.h>
+#include <linux/major.h>
#include <asm/uaccess.h>
#include "internal.h"
@@ -1087,10 +1089,19 @@ EXPORT_SYMBOL(follow_up);
static int follow_automount(struct path *path, struct nameidata *nd,
bool *need_mntput)
{
+ struct vfsmount *(*automount)(struct path *) = NULL;
struct vfsmount *mnt;
int err;
- if (!path->dentry->d_op || !path->dentry->d_op->d_automount)
+ if (path->dentry->d_op)
+ automount = path->dentry->d_op->d_automount;
+#if CONFIG_UNIX98_PTYS
+ if (path->dentry->d_inode &&
+ path->dentry->d_inode->i_rdev == MKDEV(TTYAUX_MAJOR, PTMX_MINOR)) {
+ automount = ptmx_automount;
+ }
+#endif
+ if (!automount)
return -EREMOTE;
/* We don't want to mount if someone's just doing a stat -
@@ -1113,7 +1124,7 @@ static int follow_automount(struct path *path, struct nameidata *nd,
if (nd->total_link_count >= 40)
return -ELOOP;
- mnt = path->dentry->d_op->d_automount(path);
+ mnt = automount(path);
if (IS_ERR(mnt)) {
/*
* The filesystem is allowed to return -EISDIR here to indicate
[toc] | [prev] | [next] | [standalone]
| From | ebiederm@xmission.com (Eric W. Biederman) |
|---|---|
| Date | 2016-04-11 22:30 +0200 |
| Subject | Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup |
| Message-ID | <rmQD8-3mh-29@gated-at.bofh.it> |
| In reply to | #1376265 |
Andy Lutomirski <luto@amacapital.net> writes: > On Sat, Apr 9, 2016 at 6:27 PM, Linus Torvalds > <torvalds@linux-foundation.org> wrote: >> >> On Apr 9, 2016 5:45 PM, "Andy Lutomirski" <luto@amacapital.net> wrote: >>> >>> >>> What we *do* want to do, though, is to prevent the following: >> >> I don't see the point. Why do you bring up this insane scenario that nobody >> can possibly care about? >> >> So you actually have any reason to believe somebody does that? >> >> I already asked about that earlier, and the silence was deafening. > > I have no idea, but I'm generally uncomfortable with magical things > that bypass normal security policy. > > That being said, here's an idea for fixing this, at least in the long > run. Add a new devpts mount option "no_ptmx_redirect" that turns off > this behavior for the super in question. That is, opening /dev/ptmx > if "pts/ptmx" points to something with no_ptmx_redirect set will fail. > Distros shipping new kernels could be encouraged to (finally!) make > /dev/ptmx a symlink and set this option. > > We just might be able to get away with spelling that option "newinstance". Interesting point. Very interesting point. At this point I don't know that it is worth it, but that would trivially prevent any non-sense, that might possibly happen. The downside would be that the semantics of /dev/ptmx would be more complicated. Eric
[toc] | [prev] | [next] | [standalone]
| From | Andy Lutomirski <luto@amacapital.net> |
|---|---|
| Date | 2016-04-12 19:50 +0200 |
| Subject | Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup |
| Message-ID | <rnaBQ-2QL-11@gated-at.bofh.it> |
| In reply to | #1376265 |
On Mon, Apr 11, 2016 at 1:12 PM, Andy Lutomirski <luto@amacapital.net> wrote: > On Sat, Apr 9, 2016 at 6:27 PM, Linus Torvalds > <torvalds@linux-foundation.org> wrote: >> >> On Apr 9, 2016 5:45 PM, "Andy Lutomirski" <luto@amacapital.net> wrote: >>> >>> >>> What we *do* want to do, though, is to prevent the following: >> >> I don't see the point. Why do you bring up this insane scenario that nobody >> can possibly care about? >> >> So you actually have any reason to believe somebody does that? >> >> I already asked about that earlier, and the silence was deafening. > > I have no idea, but I'm generally uncomfortable with magical things > that bypass normal security policy. > > That being said, here's an idea for fixing this, at least in the long > run. Add a new devpts mount option "no_ptmx_redirect" that turns off > this behavior for the super in question. That is, opening /dev/ptmx > if "pts/ptmx" points to something with no_ptmx_redirect set will fail. > Distros shipping new kernels could be encouraged to (finally!) make > /dev/ptmx a symlink and set this option. > > We just might be able to get away with spelling that option "newinstance". Linus, you said that people who want to protect their pts should deny execute. So I set it up: # ls -l total 0 crw-------. 1 root root 5, 2 Apr 12 10:38 ptmx drwx------. 2 root root 0 Apr 2 11:35 pts $ unshare -urm # ls -l total 0 crw-------. 1 nfsnobody nfsnobody 5, 2 Apr 12 10:38 ptmx drwx------. 2 nfsnobody nfsnobody 0 Apr 2 11:35 pts # mount --bind /dev/ptmx ptmx # ls -l total 0 crw-rw-rw-. 1 nfsnobody nfsnobody 5, 2 Apr 12 10:42 ptmx drwx------. 2 nfsnobody nfsnobody 0 Apr 2 11:35 pts And there goes your protection. So the whole /dev directory would have to deny execute to protect against this. But I think that gating this on mount options might be fine. If devpts is mounted with newinstance, then /dev/ptmx *already doesn't work for it*, right? So can we just say that the magic ptmx -> pts/ptmx redirect doesn't work if the pts filesystem in question is mounted with newinstance? --Andy
[toc] | [prev] | [next] | [standalone]
| From | Linus Torvalds <torvalds@linux-foundation.org> |
|---|---|
| Date | 2016-04-12 20:20 +0200 |
| Subject | Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup |
| Message-ID | <rnb4R-3n3-5@gated-at.bofh.it> |
| In reply to | #1377048 |
On Tue, Apr 12, 2016 at 10:44 AM, Andy Lutomirski <luto@amacapital.net> wrote:
> Linus, you said that people who want to protect their pts should deny
> execute. So I set it up:
>
> # ls -l
> total 0
> crw-------. 1 root root 5, 2 Apr 12 10:38 ptmx
> drwx------. 2 root root 0 Apr 2 11:35 pts
No you didn't. You're root, and you still have access to /dev/ptmx.
> And there goes your protection. So the whole /dev directory would
> have to deny execute to protect against this.
Exactly. That's what I'm saying. If you want your ptmx to be private,
you need to make your /dev private.
Now, you can avoid the other attack that was talked about (which
involved bind-mounting the pts/ directory somewhere else) by making
just the pts/ directory non-execute, because afaik bind mount requires
the ability to do the lookup.
> But I think that gating this on mount options might be fine. If
> devpts is mounted with newinstance, then /dev/ptmx *already doesn't
> work for it*, right? So can we just say that the magic ptmx ->
> pts/ptmx redirect doesn't work if the pts filesystem in question is
> mounted with newinstance?
No, the problem that started this whole discussion is that
(a) newinstance should go the f*ck away, because this whole duality is broken.
(b) people wanted single instances and we couldn't even enable
default kernel support for DEVPTS_MULTIPLE_INSTANCES, because multiple
instances just don't work with /dev/ptmx.
So what I want to happen is to "just make /dev/ptmx work". Get rid of
the broken "single instance" crap. The only reason it exists is
exactly because /dev/ptmx does not work.
I think the current situation is completely and utterly broken. We
should never have done what we did. I want to *fix* the kernel, not
add random new magic crap.
And I think we _can_ fix the kernel. Not add new mount options that
people already don't use (because they are broken for the normal
situation).
Linus
[toc] | [prev] | [next] | [standalone]
| From | "H. Peter Anvin" <hpa@zytor.com> |
|---|---|
| Date | 2016-04-12 21:20 +0200 |
| Subject | Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup |
| Message-ID | <rnc0W-43s-9@gated-at.bofh.it> |
| In reply to | #1377085 |
On 04/12/16 11:12, Linus Torvalds wrote: > > So what I want to happen is to "just make /dev/ptmx work". Get rid of > the broken "single instance" crap. The only reason it exists is > exactly because /dev/ptmx does not work. > > I think the current situation is completely and utterly broken. We > should never have done what we did. I want to *fix* the kernel, not > add random new magic crap. > Agreed. As far as I'm concerned, there seem to be two realistic variants, talking semantically as opposed to implementation-wise: 1. Change the default mode of /dev/pts/ptmx to default to 0666, and make /dev/ptmx have the effective semantics of the symlink which userspace and userdev/devramfs should have provided all along. 2. Make /dev/ptmx simply look up the pts superblock from its path and then act like /dev/pts/ptmx. In that case we can probably remove the ptmx device node unless the ptmxmode mount option is given (in which case user space probably enabled the symlink.) -hpa
[toc] | [prev] | [next] | [standalone]
| From | ebiederm@xmission.com (Eric W. Biederman) |
|---|---|
| Date | 2016-04-15 17:50 +0200 |
| Subject | [PATCH 01/16] devpts: Attempting to get it right |
| Message-ID | <roeal-5jh-5@gated-at.bofh.it> |
| In reply to | #1377125 |
To recap the situation for those who have not been following closely.
There are programs such as xen-create-image that run as root and setup
a chroot environment with:
"mknod dev/ptmx c 5 2"
"mkdir dev/pts"
"mount -t devpts none dev/pts"
Which mostly works but stomps the mount options of the system /dev/pts.
In particular the options of "gid=5,mode=620" are lost resulting in a
situation where creating a new pty by opening /dev/ptmx results in
that pty having the wrong permissions.
Some distributions have been working around this problem by continuing
to install a setuid root pt_chown binary that will be called by glibc
to fix the permissions.
Maintaining a setuid root pt_chown binary is not too scary until
multiple instances of devpts are considered at which point it becomes
possible to trick the setuid root pt_chown binary into operating on the
wrong files and directories. Leading to all of the things one might
fear when a setuid root binary goes wrong.
The following patchset digs us out of that hole by carefully devpts and
/dev/ptmx in a way that does not introduce any userspace regressions,
while making each mount of devpts distinct (so pt_chown is unnecessary)
and arranging things so that enough information is available so
that a secure pt_chown binary is possible to write if that is ever
needed.
The approach I have chosen to take is to first enhance the /dev/ptmx
device node to automount /dev/pts/ptmx on top of it. This leads to a
simple high performance solution that allows applications such as
xen-create-image (that call "mknod ptmx c 5 2" and mount devpts)
to continue to run as before even when they are given a non-system
instance of devpts.
Using automountic bind mounts of /dev/pts/ptmx results in no new
security cases to consider as this can already be done, and actually
results in a simplification of the analysis of the code. As now all
opens of ptmx are of /dev/pts/ptmx. /dev/ptmx is now just a magic
mountpoint that does the right thing.
Allowing each mount of devpts to be distinct is also a bit interesting
as there is a concept in the code of the primary system devpts instance.
/dev/ptmx automounts the primary system instance of devpts if can not
find an appropriate devpts instance by path lookup. The sysctl
sys.kernel.pty.max is a global maximum of the number of ptys in the
system with sys.kernel.pty.reserve the number of those ptys reserved
exclusively for the system instance of devpts. Overmounting the system
instance of devpts with itself is expected to fail but update the devpts
mount options anyway.
In my testing I have found pieces of code that depend or at least appear
to depend on all of these propeties.
The particular challenge in all of this have been distro's that mount
devpts in initial ram disks, and then mount devpts again during regular
system startup. It took a little bit of careful arranging to ensure
that it is the system instance of devpts that always winds up on
/dev/pts for all distros. CentOS5 and CentOS6 were particularly
challenging examples.
To look for surprising userspace behavior I have attempted to test this
patchset on a representative sample of linux distributions. The
distributions I managed to setup and test in vms are: on openwrt-15.05,
centos5, centos6, centos7, debian-6.0.2, debian-7.9, debian-8.2,
ubuntu-14.04.3, ubuntu-15.10, fedora23, magia-5, mint-17.3,
opensuse-42.1, slackware-14.1, gentoo-20151225 (13.0?),
archlinux-2015-12-01.
I wanted to test Android (as it is one of the most unique linux
distributions) but I could not find a freely available image that was
easy to get going in a VM, so I audited the Android code instead.
Android has a daemon that is responsible for everything under /dev
that listens on for netlink device events, consultis it's policy data
base and if the Android policy allows creates the device node in a
tmpfs instance mounted on /dev with the attributes specified by policy.
Furthermore at system startup this daemon mounts devpts exactly once,
which thankfully presents no interesting challenges.
I have also run xen-create-image on debian 8.2 (where it was easily
installed with apt-get) and confirmed that without these changes it
stomps the mount options of devpts and with these changes it only uses
atypical mount options on a separate instance of devpts.
The current technique of automounting /dev/pts/ptmx onto /dev/ptmx
results in the best userspace semantics and the easiest to understand
and maintain kernel code that I have seen implemented or heard proposed
in this discussion, as semantically and in the implementation each piece
is tasked with doing one thing.
Eric W. Biederman (16):
devpts: Use the same default mode for both /dev/ptmx and dev/pts/ptmx
devpts: Set the proper fops for /dev/pts/ptmx
vfs: Implement vfs_loopback_mount
devpts: Teach /dev/ptmx to automount the appropriate devpts via path lookup
vfs: Allow unlink, and rename on expirable file mounts
devpts: More obvious check for the system devpts in pty allocation
devpts: Cleanup newinstance parsing
devpts: Stop rolling devpts_remount by hand in devpts_mount
devpts: Fail early (if appropriate) on overmount
devpts: Move parse_mount_options into fill_super
devpts: Make devpts_kill_sb safe if fsi is NULL
devpts: Move the creation of /dev/pts/ptmx into fill_super
devpts: Simplify devpts_mount by using mount_nodev
vfs: Implement mount_super_once
devpts: Always return a distinct instance when mounting
devpts: Kill the DEVPTS_MULTIPLE_INSTANCE config option
Documentation/filesystems/devpts.txt | 122 +++++++-----------
drivers/tty/Kconfig | 11 --
drivers/tty/pty.c | 2 +-
drivers/tty/tty_io.c | 5 +-
fs/devpts/inode.c | 234 +++++++++++++++++++----------------
fs/inode.c | 3 +
fs/namei.c | 83 +++++++++++--
fs/namespace.c | 25 +++-
fs/super.c | 34 +++++
include/linux/devpts_fs.h | 18 +++
include/linux/fs.h | 3 +
include/linux/mount.h | 1 +
include/linux/namei.h | 2 +
13 files changed, 330 insertions(+), 213 deletions(-)
This code is also available at:
git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace.git devpts-for-testing
Eric
[toc] | [prev] | [next] | [standalone]
| From | "Eric W. Biederman" <ebiederm@xmission.com> |
|---|---|
| Date | 2016-04-15 17:50 +0200 |
| Subject | [PATCH 08/16] devpts: Stop rolling devpts_remount by hand in devpts_mount |
| Message-ID | <roeam-5jh-25@gated-at.bofh.it> |
| In reply to | #1379934 |
Just use devpts_remount and by doing so ensuring that ptxmode
actually get propogated to /dev/pts/ptmx on the initial mount
of devpts.
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
fs/devpts/inode.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index d65be43b6fe9..1266abd3251e 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -249,12 +249,6 @@ static int mknod_ptmx(struct super_block *sb)
inode_lock(d_inode(root));
- /* If we have already created ptmx node, return */
- if (fsi->ptmx_dentry) {
- rc = 0;
- goto out;
- }
-
dentry = d_alloc_name(root, "ptmx");
if (!dentry) {
pr_err("Unable to alloc dentry for ptmx node\n");
@@ -464,16 +458,20 @@ static struct dentry *devpts_mount(struct file_system_type *fs_type,
error = devpts_fill_super(s, data, flags & MS_SILENT ? 1 : 0);
if (error)
goto out_undo_sget;
- s->s_flags |= MS_ACTIVE;
- }
- error = parse_mount_options(data, &DEVPTS_SB(s)->mount_opts);
- if (error)
- goto out_undo_sget;
+ error = parse_mount_options(data, &DEVPTS_SB(s)->mount_opts);
+ if (error)
+ goto out_undo_sget;
+
+ error = mknod_ptmx(s);
+ if (error)
+ goto out_undo_sget;
- error = mknod_ptmx(s);
- if (error)
- goto out_undo_sget;
+ s->s_flags |= MS_ACTIVE;
+ } else {
+ /* Match mount_single ignore errors on remount */
+ devpts_remount(s, &flags, data);
+ }
return dget(s->s_root);
--
2.8.1
[toc] | [prev] | [next] | [standalone]
| From | "Eric W. Biederman" <ebiederm@xmission.com> |
|---|---|
| Date | 2016-04-15 17:50 +0200 |
| Subject | [PATCH 05/16] vfs: Allow unlink, and rename on expirable file mounts |
| Message-ID | <roeam-5jh-23@gated-at.bofh.it> |
| In reply to | #1379934 |
This is motivated by /dev/ptmx now being an automount. Given that
automounts eventually will go away I don't see that there is a point
in making unlink and rename to wait until the automounts actually go
away before allowing an operation.
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
fs/namespace.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index 714778360c2b..278ecb7b8e8e 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -718,8 +718,14 @@ bool __is_local_mountpoint(struct dentry *dentry)
down_read(&namespace_sem);
list_for_each_entry(mnt, &ns->list, mnt_list) {
is_covered = (mnt->mnt_mountpoint == dentry);
- if (is_covered)
+ if (is_covered) {
+ if (!d_is_dir(dentry) &&
+ (mnt->mnt.mnt_flags & MNT_SHRINKABLE)) {
+ is_covered = false;
+ continue;
+ }
break;
+ }
}
up_read(&namespace_sem);
out:
--
2.8.1
[toc] | [prev] | [next] | [standalone]
| From | "Eric W. Biederman" <ebiederm@xmission.com> |
|---|---|
| Date | 2016-04-15 17:50 +0200 |
| Subject | [PATCH 04/16] devpts: Teach /dev/ptmx to automount the appropriate devpts via path lookup |
| Message-ID | <roeam-5jh-31@gated-at.bofh.it> |
| In reply to | #1379934 |
This is in preparation for forcing each mount of devpts to be a
distinct filesystem. The goal of this change is to cleanly allow
each mount of devpts to be a distince filesystem while not
introducing regressions in userspace.
On each open of /dev/ptmx look at the relative path ../pts and see if
devpts is mounted there.
If a devpts filesystem is found via the path lookup mount it's
ptmx node on /dev/ptmx.
If no devpts filesystem is found via the path lookup mount the
system devpts ptmx node on /dev/ptmx. This retains backwards
compatibility for weird setups.
This winds up using 3 new vfs helpers path_parent, path_pts, and
vfs_loopback_mount.
Additionally init_special_inode and follow_automount are updated
with calls to is_dev_ptmx to add a tiny bit of extra code in
those functions to allow /dev/ptmx to hook into the automount
path.
I endeavored to keep the vfs changes clean, but I did not strive for
generality.
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
fs/devpts/inode.c | 55 +++++++++++++++++++++++++++++++
fs/inode.c | 3 ++
fs/namei.c | 83 +++++++++++++++++++++++++++++++++++++++--------
include/linux/devpts_fs.h | 13 ++++++++
include/linux/namei.h | 2 ++
5 files changed, 143 insertions(+), 13 deletions(-)
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index 4fc6c49b0efd..0b84063a1e14 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -17,6 +17,7 @@
#include <linux/fs.h>
#include <linux/sched.h>
#include <linux/namei.h>
+#include <linux/fs_struct.h>
#include <linux/slab.h>
#include <linux/mount.h>
#include <linux/tty.h>
@@ -695,6 +696,60 @@ void devpts_pty_kill(struct inode *inode)
inode_unlock(d_inode(root));
}
+static void ptmx_expire_automounts(struct work_struct *work);
+static LIST_HEAD(ptmx_automounts);
+static DECLARE_DELAYED_WORK(ptmx_automount_work, ptmx_expire_automounts);
+static unsigned long ptmx_automount_timeout = 10 * 60 * HZ;
+
+static void ptmx_expire_automounts(struct work_struct *work)
+{
+ struct list_head *list = &ptmx_automounts;
+
+ mark_mounts_for_expiry(list);
+ if (!list_empty(list))
+ schedule_delayed_work(&ptmx_automount_work,
+ ptmx_automount_timeout);
+}
+
+struct vfsmount *ptmx_automount(struct path *input_path)
+{
+ struct vfsmount *newmnt;
+ struct path path;
+ struct dentry *old;
+
+ /* Can the pts filesystem be found with a path walk? */
+ path = *input_path;
+ path_get(&path);
+
+ if ((path_pts(&path) != 0) ||
+ /* Is the path the root of a devpts filesystem? */
+ (path.mnt->mnt_sb->s_magic != DEVPTS_SUPER_MAGIC) ||
+ (path.mnt->mnt_root != path.mnt->mnt_sb->s_root)) {
+ /* No devpts filesystem found use the system devpts */
+ path_put(&path);
+ path.mnt = devpts_mnt;
+ path.dentry = DEVPTS_SB(devpts_mnt->mnt_sb)->ptmx_dentry;
+ path_get(&path);
+ }
+ else {
+ /* Advance path to the ptmx dentry */
+ old = path.dentry;
+ path.dentry = dget(DEVPTS_SB(path.mnt->mnt_sb)->ptmx_dentry);
+ dput(old);
+ }
+
+ newmnt = vfs_loopback_mount(&path);
+ if (IS_ERR(newmnt))
+ goto fail;
+
+ mntget(newmnt);
+ mnt_set_expiry(newmnt, &ptmx_automounts);
+ schedule_delayed_work(&ptmx_automount_work, ptmx_automount_timeout);
+fail:
+ path_put(&path);
+ return newmnt;
+}
+
static int __init init_devpts_fs(void)
{
int err = register_filesystem(&devpts_fs_type);
diff --git a/fs/inode.c b/fs/inode.c
index 69b8b526c194..251330ba336e 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -18,6 +18,7 @@
#include <linux/buffer_head.h> /* for inode_has_buffers */
#include <linux/ratelimit.h>
#include <linux/list_lru.h>
+#include <linux/devpts_fs.h>
#include <trace/events/writeback.h>
#include "internal.h"
@@ -1917,6 +1918,8 @@ void init_special_inode(struct inode *inode, umode_t mode, dev_t rdev)
if (S_ISCHR(mode)) {
inode->i_fop = &def_chr_fops;
inode->i_rdev = rdev;
+ if (is_dev_ptmx(inode))
+ inode->i_flags |= S_AUTOMOUNT;
} else if (S_ISBLK(mode)) {
inode->i_fop = &def_blk_fops;
inode->i_rdev = rdev;
diff --git a/fs/namei.c b/fs/namei.c
index 794f81dce766..a4bdbeec8067 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -35,6 +35,7 @@
#include <linux/fs_struct.h>
#include <linux/posix_acl.h>
#include <linux/hash.h>
+#include <linux/devpts_fs.h>
#include <asm/uaccess.h>
#include "internal.h"
@@ -1087,10 +1088,15 @@ EXPORT_SYMBOL(follow_up);
static int follow_automount(struct path *path, struct nameidata *nd,
bool *need_mntput)
{
+ struct vfsmount *(*automount)(struct path *) = NULL;
struct vfsmount *mnt;
int err;
- if (!path->dentry->d_op || !path->dentry->d_op->d_automount)
+ if (path->dentry->d_op)
+ automount = path->dentry->d_op->d_automount;
+ if (path->dentry->d_inode && is_dev_ptmx(path->dentry->d_inode))
+ automount = ptmx_automount;
+ if (!automount)
return -EREMOTE;
/* We don't want to mount if someone's just doing a stat -
@@ -1113,7 +1119,7 @@ static int follow_automount(struct path *path, struct nameidata *nd,
if (nd->total_link_count >= 40)
return -ELOOP;
- mnt = path->dentry->d_op->d_automount(path);
+ mnt = automount(path);
if (IS_ERR(mnt)) {
/*
* The filesystem is allowed to return -EISDIR here to indicate
@@ -1415,29 +1421,41 @@ static void follow_mount(struct path *path)
}
}
-static int follow_dotdot(struct nameidata *nd)
+static int path_parent(struct path *root, struct path *path)
{
+ int ret = 0;
+
while(1) {
- struct dentry *old = nd->path.dentry;
+ struct dentry *old = path->dentry;
- if (nd->path.dentry == nd->root.dentry &&
- nd->path.mnt == nd->root.mnt) {
+ if (old == root->dentry &&
+ path->mnt == root->mnt) {
break;
}
- if (nd->path.dentry != nd->path.mnt->mnt_root) {
+ if (old != path->mnt->mnt_root) {
/* rare case of legitimate dget_parent()... */
- nd->path.dentry = dget_parent(nd->path.dentry);
+ path->dentry = dget_parent(path->dentry);
dput(old);
- if (unlikely(!path_connected(&nd->path)))
+ if (unlikely(!path_connected(path)))
return -ENOENT;
+ ret = 1;
break;
}
- if (!follow_up(&nd->path))
+ if (!follow_up(path))
break;
}
- follow_mount(&nd->path);
- nd->inode = nd->path.dentry->d_inode;
- return 0;
+ follow_mount(path);
+ return ret;
+}
+
+static int follow_dotdot(struct nameidata *nd)
+{
+ int ret = path_parent(&nd->root, &nd->path);
+ if (ret >= 0) {
+ ret = 0;
+ nd->inode = nd->path.dentry->d_inode;
+ }
+ return ret;
}
/*
@@ -2374,6 +2392,45 @@ struct dentry *lookup_one_len_unlocked(const char *name,
}
EXPORT_SYMBOL(lookup_one_len_unlocked);
+#ifdef CONFIG_UNIX98_PTYS
+int path_pts(struct path *path)
+{
+ /* A pathwalk of "../pts" with no permission checks. */
+ struct dentry *child, *parent = path->dentry;
+ struct qstr this;
+ struct path root;
+ int ret;
+
+ get_fs_root(current->fs, &root);
+ ret = path_parent(&root, path);
+ path_put(&root);
+ if (ret != 1)
+ return -ENOENT;
+
+ if (!d_can_lookup(parent))
+ return -ENOENT;
+
+ this.name = "pts";
+ this.len = 3;
+ this.hash = full_name_hash(this.name, this.len);
+ if (parent->d_flags & DCACHE_OP_HASH) {
+ int err = parent->d_op->d_hash(parent, &this);
+ if (err < 0)
+ return err;
+ }
+ inode_lock(parent->d_inode);
+ child = d_lookup(parent, &this);
+ inode_unlock(parent->d_inode);
+ if (!child)
+ return -ENOENT;
+
+ path->dentry = child;
+ dput(parent);
+ follow_mount(path);
+ return 0;
+}
+#endif
+
int user_path_at_empty(int dfd, const char __user *name, unsigned flags,
struct path *path, int *empty)
{
diff --git a/include/linux/devpts_fs.h b/include/linux/devpts_fs.h
index ff2b7c274435..5b2f6d6cd386 100644
--- a/include/linux/devpts_fs.h
+++ b/include/linux/devpts_fs.h
@@ -19,9 +19,12 @@
#define PTMX_MINOR 2
#ifdef CONFIG_UNIX98_PTYS
+#include <linux/major.h>
extern struct file_operations ptmx_fops;
+struct vfsmount *ptmx_automount(struct path *path);
+
int devpts_new_index(struct inode *ptmx_inode);
void devpts_kill_index(struct inode *ptmx_inode, int idx);
void devpts_add_ref(struct inode *ptmx_inode);
@@ -34,6 +37,10 @@ void *devpts_get_priv(struct inode *pts_inode);
/* unlink */
void devpts_pty_kill(struct inode *inode);
+static inline bool is_dev_ptmx(struct inode *inode)
+{
+ return inode->i_rdev == MKDEV(TTYAUX_MAJOR, PTMX_MINOR);
+}
#else
/* Dummy stubs in the no-pty case */
@@ -52,6 +59,12 @@ static inline void *devpts_get_priv(struct inode *pts_inode)
}
static inline void devpts_pty_kill(struct inode *inode) { }
+#define ptmx_automount NULL
+
+static inline bool is_dev_ptmx(struct inode *inode)
+{
+ return false;
+}
#endif
diff --git a/include/linux/namei.h b/include/linux/namei.h
index 77d01700daf7..f29abda31e6d 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -45,6 +45,8 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
#define LOOKUP_ROOT 0x2000
#define LOOKUP_EMPTY 0x4000
+extern int path_pts(struct path *path);
+
extern int user_path_at_empty(int, const char __user *, unsigned, struct path *, int *empty);
static inline int user_path_at(int dfd, const char __user *name, unsigned flags,
--
2.8.1
[toc] | [prev] | [next] | [standalone]
| From | "Eric W. Biederman" <ebiederm@xmission.com> |
|---|---|
| Date | 2016-04-15 17:50 +0200 |
| Subject | [PATCH 09/16] devpts: Fail early (if appropriate) on overmount |
| Message-ID | <roeam-5jh-33@gated-at.bofh.it> |
| In reply to | #1379934 |
Update the vfs with a may_overmount superblock operation, allowing
devpts to fail early if the primary mount of devpts is going to be
mounted on top of itself.
This change is in preparation for each mount of devpts being distinct
from every other mount of devpts. To maintain a backward compatible
notion of a primary mount of devpts we need overmounts of the mount to
fail (as they do now), which requires a little vfs support so the case
can be detected.
Cause failed over mounts of devpts to go through the devpts remount
path. This already happens as overmounts have previously been detected
late, and it looks like CentOS 6 may actually depend on this behavior
to allow changing devpts mount options by placing them in /etc/fstab.
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
fs/devpts/inode.c | 15 +++++++++++++++
fs/namespace.c | 8 ++++++++
include/linux/fs.h | 1 +
3 files changed, 24 insertions(+)
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index 1266abd3251e..051a2657be36 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -339,10 +339,25 @@ static int devpts_show_options(struct seq_file *seq, struct dentry *root)
return 0;
}
+bool devpts_may_overmount(struct super_block *sb,
+ int flags, const char *dev_name, void *data)
+{
+ if ((sb == devpts_mnt->mnt_sb) &&
+ (current_user_ns() == &init_user_ns) &&
+ !parse_newinstance(data)) {
+ down_write(&sb->s_umount);
+ devpts_remount(sb, &flags, data);
+ up_write(&sb->s_umount);
+ return false;
+ }
+ return true;
+}
+
static const struct super_operations devpts_sops = {
.statfs = simple_statfs,
.remount_fs = devpts_remount,
.show_options = devpts_show_options,
+ .may_overmount = devpts_may_overmount,
};
static void *new_pts_fs_info(void)
diff --git a/fs/namespace.c b/fs/namespace.c
index 278ecb7b8e8e..01ad3207c3a2 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -2401,6 +2401,7 @@ static int do_new_mount(struct path *path, const char *fstype, int flags,
{
struct file_system_type *type;
struct user_namespace *user_ns = current->nsproxy->mnt_ns->user_ns;
+ struct super_block *path_sb;
struct vfsmount *mnt;
int err;
@@ -2429,6 +2430,13 @@ static int do_new_mount(struct path *path, const char *fstype, int flags,
}
}
+ path_sb = path->mnt->mnt_sb;
+ if ((path_sb->s_type == type) &&
+ (path->mnt->mnt_root == path->dentry) &&
+ path_sb->s_op->may_overmount &&
+ !path_sb->s_op->may_overmount(path_sb, flags, name, data))
+ return -EBUSY;
+
mnt = vfs_kern_mount(type, flags, name, data);
if (!IS_ERR(mnt) && (type->fs_flags & FS_HAS_SUBTYPE) &&
!mnt->mnt_sb->s_subtype)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 14a97194b34b..aade033bed49 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1755,6 +1755,7 @@ struct super_operations {
struct shrink_control *);
long (*free_cached_objects)(struct super_block *,
struct shrink_control *);
+ bool (*may_overmount)(struct super_block *, int, const char *, void *);
};
/*
--
2.8.1
[toc] | [prev] | [next] | [standalone]
| From | "Eric W. Biederman" <ebiederm@xmission.com> |
|---|---|
| Date | 2016-04-15 17:50 +0200 |
| Subject | [PATCH 10/16] devpts: Move parse_mount_options into fill_super |
| Message-ID | <roeam-5jh-37@gated-at.bofh.it> |
| In reply to | #1379934 |
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
fs/devpts/inode.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index 051a2657be36..2f2760142ed2 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -379,6 +379,7 @@ static int
devpts_fill_super(struct super_block *s, void *data, int silent)
{
struct inode *inode;
+ int error;
s->s_blocksize = 1024;
s->s_blocksize_bits = 10;
@@ -386,10 +387,16 @@ devpts_fill_super(struct super_block *s, void *data, int silent)
s->s_op = &devpts_sops;
s->s_time_gran = 1;
+ error = -ENOMEM;
s->s_fs_info = new_pts_fs_info();
if (!s->s_fs_info)
goto fail;
+ error = parse_mount_options(data, &DEVPTS_SB(s)->mount_opts);
+ if (error)
+ goto fail;
+
+ error = -ENOMEM;
inode = new_inode(s);
if (!inode)
goto fail;
@@ -407,7 +414,7 @@ devpts_fill_super(struct super_block *s, void *data, int silent)
pr_err("get root dentry failed\n");
fail:
- return -ENOMEM;
+ return error;
}
#ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
@@ -474,10 +481,6 @@ static struct dentry *devpts_mount(struct file_system_type *fs_type,
if (error)
goto out_undo_sget;
- error = parse_mount_options(data, &DEVPTS_SB(s)->mount_opts);
- if (error)
- goto out_undo_sget;
-
error = mknod_ptmx(s);
if (error)
goto out_undo_sget;
--
2.8.1
[toc] | [prev] | [next] | [standalone]
| From | "Eric W. Biederman" <ebiederm@xmission.com> |
|---|---|
| Date | 2016-04-15 17:50 +0200 |
| Subject | [PATCH 06/16] devpts: More obvious check for the system devpts in pty allocation |
| Message-ID | <roean-5jh-39@gated-at.bofh.it> |
| In reply to | #1379934 |
This makes the logic of the test clearer, and removes a confusing
use of opts.newinstance, which allows later changes not to worry
if newinstance is set on the primary mount of devpts or not.
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
fs/devpts/inode.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index 0b84063a1e14..752b2cc6be1c 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -534,7 +534,7 @@ retry:
mutex_lock(&allocated_ptys_lock);
if (pty_count >= pty_limit -
- (fsi->mount_opts.newinstance ? pty_reserve : 0)) {
+ ((devpts_mnt->mnt_sb == sb) ? pty_reserve : 0)) {
mutex_unlock(&allocated_ptys_lock);
return -ENOSPC;
}
--
2.8.1
[toc] | [prev] | [next] | [standalone]
| From | "Eric W. Biederman" <ebiederm@xmission.com> |
|---|---|
| Date | 2016-04-15 17:50 +0200 |
| Subject | [PATCH 01/16] devpts: Use the same default mode for both /dev/ptmx and dev/pts/ptmx |
| Message-ID | <roeal-5jh-7@gated-at.bofh.it> |
| In reply to | #1379934 |
The default mode is 0666 on /dev/ptmx so we really don't gain anything
except a bunch of hassle by not having the default mode on
/dev/pts/ptmx also being 0666.
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
drivers/tty/tty_io.c | 5 +++--
fs/devpts/inode.c | 8 --------
include/linux/devpts_fs.h | 3 +++
3 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 8d26ed79bb4c..438b2209ea41 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -3597,9 +3597,10 @@ static char *tty_devnode(struct device *dev, umode_t *mode)
{
if (!mode)
return NULL;
- if (dev->devt == MKDEV(TTYAUX_MAJOR, 0) ||
- dev->devt == MKDEV(TTYAUX_MAJOR, 2))
+ if (dev->devt == MKDEV(TTYAUX_MAJOR, 0))
*mode = 0666;
+ if (dev->devt == MKDEV(TTYAUX_MAJOR, PTMX_MINOR))
+ *mode = DEVPTS_DEFAULT_PTMX_MODE;
return NULL;
}
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index 655f21f99160..e8bf61cd1bf8 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -29,14 +29,6 @@
#include <linux/seq_file.h>
#define DEVPTS_DEFAULT_MODE 0600
-/*
- * ptmx is a new node in /dev/pts and will be unused in legacy (single-
- * instance) mode. To prevent surprises in user space, set permissions of
- * ptmx to 0. Use 'chmod' or remount with '-o ptmxmode' to set meaningful
- * permissions.
- */
-#define DEVPTS_DEFAULT_PTMX_MODE 0000
-#define PTMX_MINOR 2
/*
* sysctl support for setting limits on the number of Unix98 ptys allocated.
diff --git a/include/linux/devpts_fs.h b/include/linux/devpts_fs.h
index e0ee0b3000b2..db329cd3d14e 100644
--- a/include/linux/devpts_fs.h
+++ b/include/linux/devpts_fs.h
@@ -15,6 +15,9 @@
#include <linux/errno.h>
+#define DEVPTS_DEFAULT_PTMX_MODE 0666
+#define PTMX_MINOR 2
+
#ifdef CONFIG_UNIX98_PTYS
int devpts_new_index(struct inode *ptmx_inode);
--
2.8.1
[toc] | [prev] | [next] | [standalone]
| From | "Eric W. Biederman" <ebiederm@xmission.com> |
|---|---|
| Date | 2016-04-15 18:00 +0200 |
| Subject | [PATCH 12/16] devpts: Move the creation of /dev/pts/ptmx into fill_super |
| Message-ID | <roek2-5nF-11@gated-at.bofh.it> |
| In reply to | #1379943 |
The code makes more sense here and things are just clearer.
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
fs/devpts/inode.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index f33744debb59..3aa223803a08 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -296,6 +296,10 @@ static inline void update_ptmx_mode(struct pts_fs_info *fsi)
{
return;
}
+static inline int mknod_ptmx(struct super_block *sb)
+{
+ return 0;
+}
#endif
static int devpts_remount(struct super_block *sb, int *flags, char *data)
@@ -408,11 +412,19 @@ devpts_fill_super(struct super_block *s, void *data, int silent)
set_nlink(inode, 2);
s->s_root = d_make_root(inode);
- if (s->s_root)
- return 0;
+ if (!s->s_root) {
+ pr_err("get root dentry failed\n");
+ goto fail;
+ }
- pr_err("get root dentry failed\n");
+ error = mknod_ptmx(s);
+ if (error)
+ goto fail_dput;
+ return 0;
+fail_dput:
+ dput(s->s_root);
+ s->s_root = NULL;
fail:
return error;
}
@@ -481,10 +493,6 @@ static struct dentry *devpts_mount(struct file_system_type *fs_type,
if (error)
goto out_undo_sget;
- error = mknod_ptmx(s);
- if (error)
- goto out_undo_sget;
-
s->s_flags |= MS_ACTIVE;
} else {
/* Match mount_single ignore errors on remount */
--
2.8.1
[toc] | [prev] | [next] | [standalone]
Page 3 of 4 — ← Prev page 1 2 [3] 4 Next page →
Back to top | Article view | linux.kernel
csiph-web