mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@kernel.org>
To: Sabyrzhan Tasbolatov <snovitoll@gmail.com>, gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org,
	syzbot+3d2c27c2b7dc2a94814d@syzkaller.appspotmail.com
Subject: Re: [PATCH v2] tty: fix when iov_iter_count() returns 0 in tty_write()
Date: Fri, 19 Feb 2021 10:17:55 +0100	[thread overview]
Message-ID: <e94a2ce5-3329-1c4f-3919-8db125da83d3@kernel.org> (raw)
In-Reply-To: <20210217155536.2986178-1-snovitoll@gmail.com>

On 17. 02. 21, 16:55, Sabyrzhan Tasbolatov wrote:
> syzbot found WARNING in iov_iter_revert[1] when iov_iter_count() returns 0,
> therefore INT_MAX is passed to iov_iter_revert() causing > MAX_RW_COUNT
> warning.
> 
> static inline ssize_t do_tty_write()
> {
> ..
> 	size_t count = iov_iter_count(from);
> ..
> 		size_t size = count;
> 		if (ret != size)
> 			iov_iter_revert(from, size-ret);
> 
> [1] WARNING: lib/iov_iter.c:1090
> Call Trace:
>   do_tty_write drivers/tty/tty_io.c:967 [inline]
>   file_tty_write.constprop.0+0x55f/0x8f0 drivers/tty/tty_io.c:1048
>   call_write_iter include/linux/fs.h:1901 [inline]
>   new_sync_write+0x426/0x650 fs/read_write.c:518
>   vfs_write+0x791/0xa30 fs/read_write.c:605
>   ksys_write+0x12d/0x250 fs/read_write.c:658
> 
> Fixes: 9bb48c82aced ("tty: implement write_iter")
> Reported-by: syzbot+3d2c27c2b7dc2a94814d@syzkaller.appspotmail.com
> Signed-off-by: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
> ---
> 
> v2: Fixed "Fixed" tag to proper commit and changed write return to -EFAULT
> as this statement is valid, tested via strace:
> 
> write(3, NULL, 0)                       = -1 EFAULT (Bad address)
> 
> Updated to -EFAULT, should be a valid exit code as
> copy_from_iter(.., .., from) returns -EFAULT as well if *from is invalid
> address.

Exactly, EFAULT is for invalid memory accesses. But this should be IMO 
EINVAL as it's an invalid argument.

BTW what's the reason vfs calls ->write with zero count of iter?

>> Nit, you need a ' ' before your '(' character here, otherwise the
>> linux-next scripts will complain.
> 
>> Also, you got the git commit id wrong, so this needs to be fixed up
>> anyway.  You are pointing to a merge point, I doubt that's what you want
>> to point to here, right?
> 
> Thanks!
> ---
>   drivers/tty/tty_io.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
> index 816e709afa56..e1460cad8b7d 100644
> --- a/drivers/tty/tty_io.c
> +++ b/drivers/tty/tty_io.c
> @@ -905,6 +905,9 @@ static inline ssize_t do_tty_write(
>   	ssize_t ret, written = 0;
>   	unsigned int chunk;
>   
> +	if (!count)
> +		return -EFAULT;
> +
>   	ret = tty_write_lock(tty, file->f_flags & O_NDELAY);
>   	if (ret < 0)
>   		return ret;
> 


-- 
js

      reply	other threads:[~2021-02-19  9:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-17 14:43 [PATCH] " Sabyrzhan Tasbolatov
2021-02-17 15:13 ` Greg KH
2021-02-17 15:15   ` Greg KH
2021-02-17 15:55     ` [PATCH v2] " Sabyrzhan Tasbolatov
2021-02-19  9:17       ` Jiri Slaby [this message]

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=e94a2ce5-3329-1c4f-3919-8db125da83d3@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=snovitoll@gmail.com \
    --cc=syzbot+3d2c27c2b7dc2a94814d@syzkaller.appspotmail.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

Powered by JetHome