Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1303632

[PATCH] tty: plug a use-after-free in TIOCGETD ioctl

From Mateusz Guzik <mguzik@redhat.com>
Newsgroups linux.kernel
Subject [PATCH] tty: plug a use-after-free in TIOCGETD ioctl
Date 2016-01-07 16:00 +0100
Message-ID <qOkcG-137-3@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


When the line discipline is being changed, the old one is freed.
However, the handler for TIOCGETD would dereference it without taking
any locks, in effect possibly reading freed memory.

Line discipline changes are protected with tty lock. Use it on reader
side as well.

CVE: CVE-2016-0723
Found-by: Milos Vyletel <milos@redhat.com>
Signed-off-by: Mateusz Guzik <mguzik@redhat.com>
---
 drivers/tty/tty_io.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 892c923..1b10469 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -2626,6 +2626,27 @@ static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t _
 }
 
 /**
+ *	tiocgetd	-	get line discipline
+ *	@tty: tty device
+ *	@p: pointer to returned line discipline
+ *
+ *	Get the line discipline associated with the tty.
+ *
+ *	Locking: none
+ */
+
+static int tiocgetd(struct tty_struct *tty, int __user *p)
+{
+	int ldisc;
+
+	tty_lock(tty);
+	ldisc = tty->ldisc->ops->num;
+	tty_unlock(tty);
+
+	return put_user(ldisc, p);
+}
+
+/**
  *	tiocsetd	-	set line discipline
  *	@tty: tty device
  *	@p: pointer to user data
@@ -2874,7 +2895,7 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 	case TIOCGSID:
 		return tiocgsid(tty, real_tty, p);
 	case TIOCGETD:
-		return put_user(tty->ldisc->ops->num, (int __user *)p);
+		return tiocgetd(tty, p);
 	case TIOCSETD:
 		return tiocsetd(tty, p);
 	case TIOCVHANGUP:
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] tty: plug a use-after-free in TIOCGETD ioctl Mateusz Guzik <mguzik@redhat.com> - 2016-01-07 16:00 +0100
  Re: [PATCH] tty: plug a use-after-free in TIOCGETD ioctl Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-01-07 16:40 +0100
    Re: [PATCH] tty: plug a use-after-free in TIOCGETD ioctl Mateusz Guzik <mguzik@redhat.com> - 2016-01-07 17:30 +0100
      Re: [PATCH] tty: plug a use-after-free in TIOCGETD ioctl Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-01-07 18:20 +0100
  Re: [PATCH] tty: plug a use-after-free in TIOCGETD ioctl Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-01-07 17:20 +0100
    Re: [PATCH] tty: plug a use-after-free in TIOCGETD ioctl Peter Hurley <peter@hurleysoftware.com> - 2016-01-07 17:40 +0100
      Re: [PATCH] tty: plug a use-after-free in TIOCGETD ioctl Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-01-07 18:10 +0100
        Re: [PATCH] tty: plug a use-after-free in TIOCGETD ioctl Peter Hurley <peter@hurleysoftware.com> - 2016-01-07 18:40 +0100
          Re: [PATCH] tty: plug a use-after-free in TIOCGETD ioctl Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-01-07 19:30 +0100

csiph-web