From: Greg KH <gregkh@linuxfoundation.org>
To: DaeRyong Jeong <threeearcat@gmail.com>
Cc: Byoungyoung Lee <byoungyoung@purdue.edu>,
Kyungtae Kim <kt0755@gmail.com>,
LKML <linux-kernel@vger.kernel.org>,
basavesh@purdue.edu
Subject: Re: KASAN: slab-out-of-bounds Write in tty_insert_flip_string_fixed_flag
Date: Thu, 19 Apr 2018 16:07:51 +0200 [thread overview]
Message-ID: <20180419140751.GA19001@kroah.com> (raw)
In-Reply-To: <CACsK=jfmwcLA9bsPAPEgvg72C2Cpc-U1oGhi+fO-rN543RKUbQ@mail.gmail.com>
On Thu, Apr 19, 2018 at 09:25:08PM +0900, DaeRyong Jeong wrote:
> The patch is attached at the end of this email and can be downloaded from here.
> https://kiwi.cs.purdue.edu/static/race-fuzzer/tty_insert_flip_string_fixed_flag.patch
>
> We applied the patch to v4.16 and tested our reproducer. we can't see the
> crash any longer.
>
> Our rationale is
> - Since tty_wakeup() called by __start_tty() sends frames, call
> tty_write_lock() before __start_tty().
> - Since tty_write_lock() might sleep, locate tty_write_lock() before
> spin_lock_irq(&tty->flow_lock).
> - Since wake_up_interruptible_poll() is called by both tty_write_unlock()
> and __start_tty(), Prevent calling wake_up_interruptible_poll() twice by
> adding the wakeup flag to tty_write_unlock()
>
> If there is something that we are missing or we are wrong, please let us know.
>
>
> Thank you.
>
> Best regards,
> Daeryong Jeong
>
>
>
> diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
> index 63114ea..09c76d3 100644
> --- a/drivers/tty/tty_io.c
> +++ b/drivers/tty/tty_io.c
> @@ -873,13 +873,15 @@ static ssize_t tty_read(struct file *file, char
> __user *buf, size_t count,
> return i;
> }
>
> -static void tty_write_unlock(struct tty_struct *tty)
> +void tty_write_unlock(struct tty_struct *tty, int wakeup)
> {
> mutex_unlock(&tty->atomic_write_lock);
> - wake_up_interruptible_poll(&tty->write_wait, EPOLLOUT);
> + if (wakeup) {
> + wake_up_interruptible_poll(&tty->write_wait, EPOLLOUT);
> + }
> }
>
> -static int tty_write_lock(struct tty_struct *tty, int ndelay)
> +int tty_write_lock(struct tty_struct *tty, int ndelay)
> {
> if (!mutex_trylock(&tty->atomic_write_lock)) {
> if (ndelay)
> @@ -973,7 +975,7 @@ static inline ssize_t do_tty_write(
> ret = written;
> }
> out:
> - tty_write_unlock(tty);
> + tty_write_unlock(tty, 1);
> return ret;
> }
>
> @@ -997,7 +999,7 @@ void tty_write_message(struct tty_struct *tty, char *msg)
> if (tty->ops->write && tty->count > 0)
> tty->ops->write(tty, msg, strlen(msg));
> tty_unlock(tty);
> - tty_write_unlock(tty);
> + tty_write_unlock(tty, 1);
> }
> return;
> }
> @@ -1092,7 +1094,7 @@ int tty_send_xchar(struct tty_struct *tty, char ch)
> if (was_stopped)
> stop_tty(tty);
> up_read(&tty->termios_rwsem);
> - tty_write_unlock(tty);
> + tty_write_unlock(tty, 1);
> return 0;
> }
>
> @@ -2395,7 +2397,7 @@ static int send_break(struct tty_struct *tty,
> unsigned int duration)
> msleep_interruptible(duration);
> retval = tty->ops->break_ctl(tty, 0);
> out:
> - tty_write_unlock(tty);
> + tty_write_unlock(tty, 1);
> if (signal_pending(current))
> retval = -EINTR;
> }
> diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
> index d9b561d..f331e99 100644
> --- a/drivers/tty/tty_ioctl.c
> +++ b/drivers/tty/tty_ioctl.c
> @@ -911,12 +911,17 @@ int n_tty_ioctl_helper(struct tty_struct *tty,
> struct file *file,
> spin_unlock_irq(&tty->flow_lock);
> break;
> case TCOON:
> + if (tty_write_lock(tty, 0) < 0)
> + return -ERESTARTSYS;
> +
> spin_lock_irq(&tty->flow_lock);
> if (tty->flow_stopped) {
> tty->flow_stopped = 0;
> __start_tty(tty);
> }
> spin_unlock_irq(&tty->flow_lock);
> +
> + tty_write_unlock(tty, 0);
> break;
> case TCIOFF:
> if (STOP_CHAR(tty) != __DISABLED_CHAR)
> diff --git a/include/linux/tty.h b/include/linux/tty.h
> index 47f8af2..5bdf928 100644
> --- a/include/linux/tty.h
> +++ b/include/linux/tty.h
> @@ -458,6 +458,8 @@ static inline struct tty_struct
> *tty_kref_get(struct tty_struct *tty)
> return tty;
> }
>
> +extern void tty_write_unlock(struct tty_struct *tty, int wakeup);
> +extern int tty_write_lock(struct tty_struct *tty, int ndelay);
> extern const char *tty_driver_name(const struct tty_struct *tty);
> extern void tty_wait_until_sent(struct tty_struct *tty, long timeout);
> extern int __tty_check_change(struct tty_struct *tty, int sig);
>
Can you please submit this in a form that I can properly review it and
apply it if needed? Documentation/SubmittingPatches has all of the
details.
thanks,
greg k-h
next prev parent reply other threads:[~2018-04-19 14:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-19 8:09 KASAN: slab-out-of-bounds Write in tty_insert_flip_string_fixed_flag DaeRyong Jeong
2018-04-19 8:17 ` Greg KH
2018-04-19 12:25 ` DaeRyong Jeong
2018-04-19 14:07 ` Greg KH [this message]
2018-04-25 12:53 ` Greg KH
2018-04-25 13:02 ` DaeRyong Jeong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180419140751.GA19001@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=basavesh@purdue.edu \
--cc=byoungyoung@purdue.edu \
--cc=kt0755@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=threeearcat@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox