]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
devpts: fix error handling in devpts_mntget()
authorEric Biggers <ebiggers@google.com>
Wed, 31 Jan 2018 08:49:18 +0000 (00:49 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 16 Feb 2018 19:07:00 +0000 (20:07 +0100)
commit4d5d5e9612e7af09bb218d0dd2455873b6faca77
tree69ffe4e86d45fc007a9f10ec3cf9caac9e419dd7
parent8ec68ce24fd19bebabed20e3812d1befbd4be4d4
devpts: fix error handling in devpts_mntget()

commit c9cc8d01fb04117928830449388512a5047569c9 upstream.

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>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/devpts/inode.c