Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755638AbcDLC1Q (ORCPT ); Mon, 11 Apr 2016 22:27:16 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:58739 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755194AbcDLC1P (ORCPT ); Mon, 11 Apr 2016 22:27:15 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Al Viro Cc: Linus Torvalds , "H. Peter Anvin" , Andy Lutomirski , security@debian.org, "security\@kernel.org" , "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 References: <877fg3emy7.fsf@x220.int.ebiederm.org> <87oa9fbsag.fsf@x220.int.ebiederm.org> <20160412013436.GN25498@ZenIV.linux.org.uk> Date: Mon, 11 Apr 2016 21:16:41 -0500 In-Reply-To: <20160412013436.GN25498@ZenIV.linux.org.uk> (Al Viro's message of "Tue, 12 Apr 2016 02:34:36 +0100") Message-ID: <8737qr8tbq.fsf@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-AID: U2FsdGVkX1/CDmvGaVx7vsJthwuf+PuTbSfc/fi+BmQ= X-SA-Exim-Connect-IP: 67.3.249.252 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.7 XMSubLong Long Subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa05 1397; Body=1 Fuz1=1 Fuz2=1] * 1.0 T_XMDrugObfuBody_04 obfuscated drug references * 0.5 XM_Body_Dirty_Words Contains a dirty word X-Spam-DCC: XMission; sa05 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ***;Al Viro X-Spam-Relay-Country: X-Spam-Timing: total 2821 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 4.8 (0.2%), b_tie_ro: 3.5 (0.1%), parse: 1.54 (0.1%), extract_message_metadata: 16 (0.6%), get_uri_detail_list: 3.9 (0.1%), tests_pri_-1000: 6 (0.2%), tests_pri_-950: 1.16 (0.0%), tests_pri_-900: 0.95 (0.0%), tests_pri_-400: 32 (1.1%), check_bayes: 31 (1.1%), b_tokenize: 10 (0.4%), b_tok_get_all: 11 (0.4%), b_comp_prob: 2.8 (0.1%), b_tok_touch_all: 3.9 (0.1%), b_finish: 0.73 (0.0%), tests_pri_0: 306 (10.9%), check_dkim_signature: 0.53 (0.0%), check_dkim_adsp: 2.8 (0.1%), tests_pri_500: 2448 (86.8%), poll_dns_idle: 2437 (86.4%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Wed, 24 Sep 2014 11:00:52 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3786 Lines: 101 Al Viro 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 /* for inode_has_buffers */ #include #include +#include #include #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 #include #include +#include +#include #include #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