Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751665AbdHQBYk (ORCPT ); Wed, 16 Aug 2017 21:24:40 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:47277 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751070AbdHQBYj (ORCPT ); Wed, 16 Aug 2017 21:24:39 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Linus Torvalds Cc: Christian Brauner , Christian Brauner , Linux Kernel Mailing List , "Serge E. Hallyn" , Al Viro References: <20170816171211.4021-1-christian.brauner@ubuntu.com> <20170816194805.hnof3aqiqykwki7p@gmail.com> <87pobvruzt.fsf@xmission.com> <87ziazqdfr.fsf@xmission.com> Date: Wed, 16 Aug 2017 20:24:23 -0500 In-Reply-To: (Linus Torvalds's message of "Wed, 16 Aug 2017 17:08:07 -0700") Message-ID: <87o9rfq94o.fsf@xmission.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1di9Xz-0004ds-EW;;;mid=<87o9rfq94o.fsf@xmission.com>;;;hst=in01.mta.xmission.com;;;ip=67.3.200.44;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+COqaO+zJEQh6pT3RGUEBsfFghjNmNxpg= X-SA-Exim-Connect-IP: 67.3.200.44 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 * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_03 6+ unique symbols in subject * 0.0 T_TooManySym_01 4+ unique symbols in subject * 0.0 T_TooManySym_02 5+ unique symbols in subject X-Spam-DCC: XMission; sa07 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Linus Torvalds X-Spam-Relay-Country: X-Spam-Timing: total 5688 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 3.6 (0.1%), b_tie_ro: 2.5 (0.0%), parse: 1.29 (0.0%), extract_message_metadata: 18 (0.3%), get_uri_detail_list: 3.3 (0.1%), tests_pri_-1000: 8 (0.1%), tests_pri_-950: 1.19 (0.0%), tests_pri_-900: 0.97 (0.0%), tests_pri_-400: 30 (0.5%), check_bayes: 29 (0.5%), b_tokenize: 13 (0.2%), b_tok_get_all: 8 (0.1%), b_comp_prob: 2.4 (0.0%), b_tok_touch_all: 3.4 (0.1%), b_finish: 0.69 (0.0%), tests_pri_0: 239 (4.2%), check_dkim_signature: 0.55 (0.0%), check_dkim_adsp: 3.4 (0.1%), tests_pri_500: 5383 (94.6%), poll_dns_idle: 5375 (94.5%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH 0/1] devpts: use dynamic_dname() to generate proc name X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3948 Lines: 125 Linus Torvalds writes: > On Wed, Aug 16, 2017 at 4:51 PM, Eric W. Biederman > wrote: >> >> *Blink* You are right I missed that. >> >> In which case I am concerned about failures that make it to err_release. >> Unless I am missing something (again) failures that jump to err_release >> won't call mntput and will result in a mnt leak. > > Yes, I think you're right. > > Maybe this attached patch is better anyway. It's smaller, because it > keeps more closely to the old code, and just adds a mntput() in all > the exit cases, and depends on the "path_get()" to have incremented > the mnt refcount one extra time. > > Can you find something in this one? My eyeballs don't see any problems with the patch below. Acked-by: "Eric W. Biederman" Eric > ENTIRELY UNTESTED! > > Linus > > drivers/tty/pty.c | 7 +++++-- > fs/devpts/inode.c | 4 +++- > include/linux/devpts_fs.h | 2 +- > 3 files changed, 9 insertions(+), 4 deletions(-) > > diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c > index 284749fb0f6b..1fc80ea87c13 100644 > --- a/drivers/tty/pty.c > +++ b/drivers/tty/pty.c > @@ -793,6 +793,7 @@ static int ptmx_open(struct inode *inode, struct file *filp) > struct tty_struct *tty; > struct path *pts_path; > struct dentry *dentry; > + struct vfsmount *mnt; > int retval; > int index; > > @@ -805,7 +806,7 @@ static int ptmx_open(struct inode *inode, struct file *filp) > if (retval) > return retval; > > - fsi = devpts_acquire(filp); > + fsi = devpts_acquire(filp, &mnt); > if (IS_ERR(fsi)) { > retval = PTR_ERR(fsi); > goto out_free_file; > @@ -849,7 +850,7 @@ static int ptmx_open(struct inode *inode, struct file *filp) > pts_path = kmalloc(sizeof(struct path), GFP_KERNEL); > if (!pts_path) > goto err_release; > - pts_path->mnt = filp->f_path.mnt; > + pts_path->mnt = mnt; > pts_path->dentry = dentry; > path_get(pts_path); > tty->link->driver_data = pts_path; > @@ -866,6 +867,7 @@ static int ptmx_open(struct inode *inode, struct file *filp) > path_put(pts_path); > kfree(pts_path); > err_release: > + mntput(mnt); > tty_unlock(tty); > // This will also put-ref the fsi > tty_release(inode, filp); > @@ -874,6 +876,7 @@ static int ptmx_open(struct inode *inode, struct file *filp) > devpts_kill_index(fsi, index); > out_put_fsi: > devpts_release(fsi); > + mntput(mnt); > out_free_file: > tty_free_file(filp); > return retval; > diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c > index 108df2e3602c..44dfbca9306f 100644 > --- a/fs/devpts/inode.c > +++ b/fs/devpts/inode.c > @@ -133,7 +133,7 @@ static inline struct pts_fs_info *DEVPTS_SB(struct super_block *sb) > return sb->s_fs_info; > } > > -struct pts_fs_info *devpts_acquire(struct file *filp) > +struct pts_fs_info *devpts_acquire(struct file *filp, struct vfsmount **ptsmnt) > { > struct pts_fs_info *result; > struct path path; > @@ -142,6 +142,7 @@ struct pts_fs_info *devpts_acquire(struct file *filp) > > path = filp->f_path; > path_get(&path); > + *ptsmnt = NULL; > > /* Has the devpts filesystem already been found? */ > sb = path.mnt->mnt_sb; > @@ -165,6 +166,7 @@ struct pts_fs_info *devpts_acquire(struct file *filp) > * pty code needs to hold extra references in case of last /dev/tty close > */ > atomic_inc(&sb->s_active); > + *ptsmnt = mntget(path.mnt); > result = DEVPTS_SB(sb); > > out: > diff --git a/include/linux/devpts_fs.h b/include/linux/devpts_fs.h > index 277ab9af9ac2..7883e901f65c 100644 > --- a/include/linux/devpts_fs.h > +++ b/include/linux/devpts_fs.h > @@ -19,7 +19,7 @@ > > struct pts_fs_info; > > -struct pts_fs_info *devpts_acquire(struct file *); > +struct pts_fs_info *devpts_acquire(struct file *, struct vfsmount **ptsmnt); > void devpts_release(struct pts_fs_info *); > > int devpts_new_index(struct pts_fs_info *);