Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932298AbcDTBYV (ORCPT ); Tue, 19 Apr 2016 21:24:21 -0400 Received: from mail-ig0-f196.google.com ([209.85.213.196]:33074 "EHLO mail-ig0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932084AbcDTBYS (ORCPT ); Tue, 19 Apr 2016 21:24:18 -0400 MIME-Version: 1.0 In-Reply-To: References: <877ffyzy1j.fsf_-_@x220.int.ebiederm.org> <1460734532-20134-1-git-send-email-ebiederm@xmission.com> <1460734532-20134-14-git-send-email-ebiederm@xmission.com> <8737qhpifz.fsf@x220.int.ebiederm.org> Date: Tue, 19 Apr 2016 18:24:12 -0700 X-Google-Sender-Auth: 7hY1jBwfUwY_6nG73nw-RDiuOpI Message-ID: Subject: Re: [PATCH 14/16] vfs: Implement mount_super_once From: Linus Torvalds To: "Eric W. Biederman" Cc: "H. Peter Anvin" , Andy Lutomirski , security@debian.org, "security@kernel.org" , Al Viro , "security@ubuntu.com >> security" , Peter Hurley , Serge Hallyn , Willy Tarreau , Aurelien Jarno , One Thousand Gnomes , Jann Horn , Greg KH , Linux Kernel Mailing List , Jiri Slaby , Florian Weimer Content-Type: multipart/mixed; boundary=047d7b45128283ffa80530e073e7 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9568 Lines: 169 --047d7b45128283ffa80530e073e7 Content-Type: text/plain; charset=UTF-8 On Tue, Apr 19, 2016 at 4:29 PM, Linus Torvalds wrote: > > I _violently_ oppose the stupid DEVPTS_MULTIPLE_INSTANCES config option. So just to show what I want to actually happen, here's the hacky patch on top of my (now merged) cleanup patch that actually does what I want devpts to do. I say it's hacky, because the "follow_mount()" thing there really is pretty hacky. Al - suggestions for how to do this *right*? But this actually forcibly removes the whole "newinstance" thing, and makes every pts mount a new instance, and just relies on "ptmx" doing the right thing. In other words, with this patch, you can *literally* do just this (as root, obviously): mkdir test-dir cd test-dir mknod ptmx c 5 2 mkdir pts mount -t devpts pts pts and after that it all just works. You can do this: ls -l pts which shows just the other ptmx noode (that is unused and pointless - I'd actually like to just remove it, but whatever), and then you can do sleep 100 < ptmx & sleep 100 < ptmx & ls -l pts and you will magically see those new 0/1 entries in that pts subdirectory.. It's entirely independent of /dev/pts/, and there's no magic connection or any magic dis-connection. It all JustWorks(tm). Note how this works even *outside* of /dev. But it works inside of /dev equally well. Now, a *real* patch would - solve that "follow_mount()" issue some other way - not remove the newinstance code immediately (I did it to show that even the bootup works with a unmodified distro) - actually remove the whole "DEVPTS_MULTIPLE_INSTANCES" config option - I'm not happy with devpts_pty_kill(). I would want to clean that up a bit somehow. I think this is at least partly what Peter Hurley was talking about. That thing is not pretty. so this attached patch is by no means meant to be applied as-is. But it's meant to show what (a) the new organization allows and (b) what I was going for. Linus --047d7b45128283ffa80530e073e7 Content-Type: text/plain; charset=US-ASCII; name="patch.diff" Content-Disposition: attachment; filename="patch.diff" Content-Transfer-Encoding: base64 X-Attachment-Id: f_in86c9zx0 IGRyaXZlcnMvdHR5L3B0eS5jICAgICAgICAgfCAgIDIgKy0KIGZzL2RldnB0cy9pbm9kZS5jICAg ICAgICAgfCAxMDcgKysrKysrKysrKysrKysrKysrKysrKysrKysrKystLS0tLS0tLS0tLS0tLS0t LQogZnMvbmFtZWkuYyAgICAgICAgICAgICAgICB8ICAgMiArLQogaW5jbHVkZS9saW51eC9kZXZw dHNfZnMuaCB8ICAgMiArLQogNCBmaWxlcyBjaGFuZ2VkLCA3MCBpbnNlcnRpb25zKCspLCA0MyBk ZWxldGlvbnMoLSkKCmRpZmYgLS1naXQgYS9kcml2ZXJzL3R0eS9wdHkuYyBiL2RyaXZlcnMvdHR5 L3B0eS5jCmluZGV4IDAwNThkOWZiZjkzMS4uMmE1NjdkMDQzM2EyIDEwMDY0NAotLS0gYS9kcml2 ZXJzL3R0eS9wdHkuYworKysgYi9kcml2ZXJzL3R0eS9wdHkuYwpAQCAtNjcsNyAr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