linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] devpts: fix error handling in devpts_mntget()
       [not found] <94eb2c05a3807b84210560f4a1fd@google.com>
@ 2018-01-31  8:49 ` Eric Biggers
  2018-01-31 16:49   ` Linus Torvalds
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Biggers @ 2018-01-31  8:49 UTC (permalink / raw)
  To: ebiederm, torvalds
  Cc: Christian Brauner, Stefan Lippers-Hollmann, linux-kernel,
	syzkaller-bugs, linux-fsdevel, Eric Biggers

From: Eric Biggers <ebiggers@google.com>

If devpts_ptmx_path() returns an error code, then devpts_mntget()
dereferences an ERR_PTR():

    BUG: unable to handle kernel paging request at fffffffffffffff5
    IP: devpts_mntget+0x13f/0x280 fs/devpts/inode.c:173

Fix it by returning early in the error paths.

Reproducer:

    #define _GNU_SOURCE
    #include <fcntl.h>
    #include <sched.h>
    #include <sys/ioctl.h>
    #define TIOCGPTPEER _IO('T', 0x41)

    int main()
    {
        for (;;) {
            int fd = open("/dev/ptmx", 0);
            unshare(CLONE_NEWNS);
            ioctl(fd, TIOCGPTPEER, 0);
        }
    }

Fixes: 311fc65c9fb9 ("pty: Repair TIOCGPTPEER")
Reported-by: syzbot <syzkaller@googlegroups.com>
Cc: <stable@vger.kernel.org> # v4.13+
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 fs/devpts/inode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index 7eae33ffa3fcc..e31d6ed3ec327 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -168,11 +168,11 @@ struct vfsmount *devpts_mntget(struct file *filp, struct pts_fs_info *fsi)
 	dput(path.dentry);
 	if (err) {
 		mntput(path.mnt);
-		path.mnt = ERR_PTR(err);
+		return ERR_PTR(err);
 	}
 	if (DEVPTS_SB(path.mnt->mnt_sb) != fsi) {
 		mntput(path.mnt);
-		path.mnt = ERR_PTR(-ENODEV);
+		return ERR_PTR(-ENODEV);
 	}
 	return path.mnt;
 }
-- 
2.16.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] devpts: fix error handling in devpts_mntget()
  2018-01-31  8:49 ` [PATCH] devpts: fix error handling in devpts_mntget() Eric Biggers
@ 2018-01-31 16:49   ` Linus Torvalds
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Torvalds @ 2018-01-31 16:49 UTC (permalink / raw)
  To: Eric Biggers
  Cc: Eric W. Biederman, Christian Brauner, Stefan Lippers-Hollmann,
	Linux Kernel Mailing List, syzkaller-bugs, linux-fsdevel,
	Eric Biggers

On Wed, Jan 31, 2018 at 12:49 AM, Eric Biggers <ebiggers3@gmail.com> wrote:
>
> If devpts_ptmx_path() returns an error code, then devpts_mntget()
> dereferences an ERR_PTR():

Thanks, applied.

            Linus

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-31 16:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <94eb2c05a3807b84210560f4a1fd@google.com>
2018-01-31  8:49 ` [PATCH] devpts: fix error handling in devpts_mntget() Eric Biggers
2018-01-31 16:49   ` Linus Torvalds

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).