public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mukesh Ojha <mojha@codeaurora.org>
To: Colin King <colin.king@canonical.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jslaby@suse.com>
Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] n_tty: check for negative and zero space return from tty_write_room
Date: Fri, 29 Mar 2019 01:04:02 +0530	[thread overview]
Message-ID: <e5f8282c-60e0-cefe-8ee6-2690a24e3b60@codeaurora.org> (raw)
In-Reply-To: <20190328171005.5822-1-colin.king@canonical.com>


On 3/28/2019 10:40 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> The return from tty_write_room could potentially be negative if
> a tty write_room driver returns an error number (not that any seem
> to do). Rather than just check for a zero return, also check for
> a -ve return. This avoids the unsigned nr being set to a large unsigned
> value on the assignment from variable space and can lead to overflowing
> the buffer buf.  Better to be safe than assume all write_room
> implementations in tty drivers are going to do the right thing.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>


Looks reasonable to me.


Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>

-Mukesh.


> ---
>   drivers/tty/n_tty.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
> index 9cdb0fa3c4bf..66630787fbf9 100644
> --- a/drivers/tty/n_tty.c
> +++ b/drivers/tty/n_tty.c
> @@ -550,7 +550,7 @@ static ssize_t process_output_block(struct tty_struct *tty,
>   	mutex_lock(&ldata->output_lock);
>   
>   	space = tty_write_room(tty);
> -	if (!space) {
> +	if (space <= 0) {
>   		mutex_unlock(&ldata->output_lock);
>   		return 0;
>   	}

  reply	other threads:[~2019-03-28 19:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-28 17:10 [PATCH] n_tty: check for negative and zero space return from tty_write_room Colin King
2019-03-28 19:34 ` Mukesh Ojha [this message]
2019-03-29  7:43 ` Dan Carpenter

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=e5f8282c-60e0-cefe-8ee6-2690a24e3b60@codeaurora.org \
    --to=mojha@codeaurora.org \
    --cc=colin.king@canonical.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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