From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753395AbcAGO6J (ORCPT ); Thu, 7 Jan 2016 09:58:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37759 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753366AbcAGO6G (ORCPT ); Thu, 7 Jan 2016 09:58:06 -0500 From: Mateusz Guzik To: Greg Kroah-Hartman , Jiri Slaby Cc: stable@vger.kernel.org, linux-kernel@vger.kernel.org, security@kernel.org, milos@redhat.com Subject: [PATCH] tty: plug a use-after-free in TIOCGETD ioctl Date: Thu, 7 Jan 2016 15:58:00 +0100 Message-Id: <1452178680-30284-1-git-send-email-mguzik@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Mateusz Guzik --- 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