diff options
| -rw-r--r-- | drivers/tty/pty.c | 85 |
1 files changed, 42 insertions, 43 deletions
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c index d1399aac05a1..284749fb0f6b 100644 --- a/drivers/tty/pty.c +++ b/drivers/tty/pty.c | |||
| @@ -448,48 +448,6 @@ err: | |||
| 448 | return retval; | 448 | return retval; |
| 449 | } | 449 | } |
| 450 | 450 | ||
| 451 | /** | ||
| 452 | * pty_open_peer - open the peer of a pty | ||
| 453 | * @tty: the peer of the pty being opened | ||
| 454 | * | ||
| 455 | * Open the cached dentry in tty->link, providing a safe way for userspace | ||
| 456 | * to get the slave end of a pty (where they have the master fd and cannot | ||
| 457 | * access or trust the mount namespace /dev/pts was mounted inside). | ||
| 458 | */ | ||
| 459 | static struct file *pty_open_peer(struct tty_struct *tty, int flags) | ||
| 460 | { | ||
| 461 | if (tty->driver->subtype != PTY_TYPE_MASTER) | ||
| 462 | return ERR_PTR(-EIO); | ||
| 463 | return dentry_open(tty->link->driver_data, flags, current_cred()); | ||
| 464 | } | ||
| 465 | |||
| 466 | static int pty_get_peer(struct tty_struct *tty, int flags) | ||
| 467 | { | ||
| 468 | int fd = -1; | ||
| 469 | struct file *filp = NULL; | ||
| 470 | int retval = -EINVAL; | ||
| 471 | |||
| 472 | fd = get_unused_fd_flags(0); | ||
| 473 | if (fd < 0) { | ||
| 474 | retval = fd; | ||
| 475 | goto err; | ||
| 476 | } | ||
| 477 | |||
| 478 | filp = pty_open_peer(tty, flags); | ||
| 479 | if (IS_ERR(filp)) { | ||
| 480 | retval = PTR_ERR(filp); | ||
| 481 | goto err_put; | ||
| 482 | } | ||
| 483 | |||
| 484 | fd_install(fd, filp); | ||
| 485 | return fd; | ||
| 486 | |||
| 487 | err_put: | ||
| 488 | put_unused_fd(fd); | ||
| 489 | err: | ||
| 490 | return retval; | ||
| 491 | } | ||
| 492 | |||
| 493 | static void pty_cleanup(struct tty_struct *tty) | 451 | static void pty_cleanup(struct tty_struct *tty) |
| 494 | { | 452 | { |
| 495 | tty_port_put(tty->port); | 453 | tty_port_put(tty->port); |
| @@ -646,9 +604,50 @@ static inline void legacy_pty_init(void) { } | |||
| 646 | 604 | ||
| 647 | /* Unix98 devices */ | 605 | /* Unix98 devices */ |
| 648 | #ifdef CONFIG_UNIX98_PTYS | 606 | #ifdef CONFIG_UNIX98_PTYS |
| 649 | |||
| 650 | static struct cdev ptmx_cdev; | 607 | static struct cdev ptmx_cdev; |
| 651 | 608 | ||
| 609 | /** | ||
| 610 | * pty_open_peer - open the peer of a pty | ||
| 611 | * @tty: the peer of the pty being opened | ||
| 612 | * | ||
| 613 | * Open the cached dentry in tty->link, providing a safe way for userspace | ||
| 614 | * to get the slave end of a pty (where they have the master fd and cannot | ||
| 615 | * access or trust the mount namespace /dev/pts was mounted inside). | ||
| 616 | */ | ||
| 617 | static struct file *pty_open_peer(struct tty_struct *tty, int flags) | ||
| 618 | { | ||
| 619 | if (tty->driver->subtype != PTY_TYPE_MASTER) | ||
| 620 | return ERR_PTR(-EIO); | ||
| 621 | return dentry_open(tty->link->driver_data, flags, current_cred()); | ||
| 622 | } | ||
| 623 | |||
| 624 | static int pty_get_peer(struct tty_struct *tty, int flags) | ||
| 625 | { | ||
| 626 | int fd = -1; | ||
| 627 | struct file *filp = NULL; | ||
| 628 | int retval = -EINVAL; | ||
| 629 | |||
| 630 | fd = get_unused_fd_flags(0); | ||
| 631 | if (fd < 0) { | ||
| 632 | retval = fd; | ||
| 633 | goto err; | ||
| 634 | } | ||
| 635 | |||
| 636 | filp = pty_open_peer(tty, flags); | ||
| 637 | if (IS_ERR(filp)) { | ||
| 638 | retval = PTR_ERR(filp); | ||
| 639 | goto err_put; | ||
| 640 | } | ||
| 641 | |||
| 642 | fd_install(fd, filp); | ||
| 643 | return fd; | ||
| 644 | |||
| 645 | err_put: | ||
| 646 | put_unused_fd(fd); | ||
| 647 | err: | ||
| 648 | return retval; | ||
| 649 | } | ||
| 650 | |||
| 652 | static int pty_unix98_ioctl(struct tty_struct *tty, | 651 | static int pty_unix98_ioctl(struct tty_struct *tty, |
| 653 | unsigned int cmd, unsigned long arg) | 652 | unsigned int cmd, unsigned long arg) |
| 654 | { | 653 | { |
