public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Christian Brauner <christian.brauner@canonical.com>,
	Christian Brauner <christian.brauner@ubuntu.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	Al Viro <viro@zeniv.linux.org.uk>
Subject: Re: [PATCH 0/1] devpts: use dynamic_dname() to generate proc name
Date: Wed, 16 Aug 2017 20:24:23 -0500	[thread overview]
Message-ID: <87o9rfq94o.fsf@xmission.com> (raw)
In-Reply-To: <CA+55aFwssaZpapQdc2iVVmMt0KxTHYdeo71Xbp4Ex-pYP_MpMw@mail.gmail.com> (Linus Torvalds's message of "Wed, 16 Aug 2017 17:08:07 -0700")

Linus Torvalds <torvalds@linux-foundation.org> writes:

> On Wed, Aug 16, 2017 at 4:51 PM, Eric W. Biederman
> <ebiederm@xmission.com> 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" <ebiederm@xmission.com>


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 *);

  reply	other threads:[~2017-08-17  1:24 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-16 17:12 [PATCH 0/1] devpts: use dynamic_dname() to generate proc name Christian Brauner
2017-08-16 17:12 ` [PATCH 1/1] " Christian Brauner
2017-08-16 18:26 ` [PATCH 0/1] " Linus Torvalds
2017-08-16 18:48   ` Linus Torvalds
2017-08-16 19:48     ` Christian Brauner
2017-08-16 19:56       ` Linus Torvalds
2017-08-16 20:19         ` Linus Torvalds
2017-08-16 20:30           ` Linus Torvalds
2017-08-16 21:03             ` Linus Torvalds
2017-08-16 21:37               ` Christian Brauner
2017-08-16 21:45                 ` Linus Torvalds
2017-08-16 21:55                   ` Linus Torvalds
2017-08-16 22:05                     ` Christian Brauner
2017-08-16 22:28                   ` Christian Brauner
2017-08-23 15:31                     ` Eric W. Biederman
2017-08-23 21:15                       ` Christian Brauner
2017-08-16 22:46               ` Eric W. Biederman
2017-08-16 22:58                 ` Linus Torvalds
2017-08-16 23:51                   ` Eric W. Biederman
2017-08-17  0:08                     ` Linus Torvalds
2017-08-17  1:24                       ` Eric W. Biederman [this message]
2017-08-24  0:24                       ` Stefan Lippers-Hollmann
2017-08-24  0:42                         ` Linus Torvalds
2017-08-24  1:16                           ` Linus Torvalds
2017-08-24  1:25                           ` Eric W. Biederman
2017-08-24  1:32                             ` Linus Torvalds
2017-08-24  1:49                               ` Linus Torvalds
2017-08-24  2:01                                 ` Linus Torvalds
2017-08-24  3:11                                   ` Eric W. Biederman
2017-08-24  3:24                                     ` Linus Torvalds
2017-08-24 15:51                                       ` Eric W. Biederman
2017-08-24  4:24                                     ` Stefan Lippers-Hollmann
2017-08-24 15:54                                       ` Eric W. Biederman
2017-08-24 17:52                                         ` Linus Torvalds
2017-08-24 18:06                                           ` Linus Torvalds
2017-08-24 18:13                                             ` Linus Torvalds
2017-08-24 18:31                                               ` Linus Torvalds
2017-08-24 18:36                                                 ` Linus Torvalds
2017-08-24 20:24                                                   ` Stefan Lippers-Hollmann
2017-08-24 20:27                                                     ` Linus Torvalds
2017-08-24 18:40                                               ` Eric W. Biederman
2017-08-24 18:51                                                 ` Linus Torvalds
2017-08-24 19:23                                                   ` Eric W. Biederman
2017-08-24 20:13                                                   ` [PATCH v3] pty: Repair TIOCGPTPEER Eric W. Biederman
2017-08-24 21:01                                                     ` Stefan Lippers-Hollmann
     [not found]                                                 ` <CAPP7u0WHqDfxTW6hmc=DsmHuoALZcrWdU-Odu=FfoTX26SGHQg@mail.gmail.com>
2017-08-24 19:22                                                   ` [PATCH 0/1] devpts: use dynamic_dname() to generate proc name Linus Torvalds
2017-08-24 19:25                                                     ` Linus Torvalds
2017-08-24 20:43                                                     ` Eric W. Biederman
2017-08-24 21:07                                                       ` Linus Torvalds
2017-08-24 23:01                                                         ` Eric W. Biederman
2017-08-24 23:27                                                           ` Linus Torvalds
2017-08-24 23:37                                                           ` Christian Brauner
2017-08-26  1:00                                                             ` Linus Torvalds
2017-08-24 19:48                                                   ` Eric W. Biederman
2017-08-17  1:37           ` Eric W. Biederman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o9rfq94o.fsf@xmission.com \
    --to=ebiederm@xmission.com \
    --cc=christian.brauner@canonical.com \
    --cc=christian.brauner@ubuntu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=serge@hallyn.com \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox