linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Siddh Raman Pant <code@siddh.me>
To: Gao Xiang <xiang@kernel.org>, Chao Yu <chao@kernel.org>,
	Yue Hu <huyue2@coolpad.com>,
	Jeffle Xu <jefflexu@linux.alibaba.com>
Cc: linux-erofs <linux-erofs@lists.ozlabs.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: [RFC PATCH] erofs/zmap.c: Bail out when no further region remains
Date: Mon, 14 Nov 2022 17:33:49 +0530	[thread overview]
Message-ID: <20221114120349.472418-1-code@siddh.me> (raw)

The following calculation of iomap->length on line 798 in
z_erofs_iomap_begin_report() can yield 0:
	if (iomap->offset >= inode->i_size)
		iomap->length = length + map.m_la - offset;

This triggers a WARN_ON in iomap_iter_done() (see line 34 of
fs/iomap/iter.c).

Hence, return error when this scenario is encountered.

============================================================

This was reported as a crash by syzbot under an issue about
warning encountered in iomap_iter_done(), but unrelated to
erofs. Hence, not adding issue hash in Reported-by line.

C reproducer: https://syzkaller.appspot.com/text?tag=ReproC&x=1037a6b2880000
Kernel config: https://syzkaller.appspot.com/text?tag=KernelConfig&x=e2021a61197ebe02
Dashboard link: https://syzkaller.appspot.com/bug?extid=a8e049cd3abd342936b6

Reported-by: syzbot@syzkaller.appspotmail.com
Signed-off-by: Siddh Raman Pant <code@siddh.me>
---
 fs/erofs/zmap.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c
index 0bb66927e3d0..bad852983eb9 100644
--- a/fs/erofs/zmap.c
+++ b/fs/erofs/zmap.c
@@ -796,6 +796,9 @@ static int z_erofs_iomap_begin_report(struct inode *inode, loff_t offset,
 		 */
 		if (iomap->offset >= inode->i_size)
 			iomap->length = length + map.m_la - offset;
+
+		if (iomap->length == 0)
+			return -EINVAL;
 	}
 	iomap->flags = 0;
 	return 0;
-- 
2.35.1



             reply	other threads:[~2022-11-14 12:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-14 12:03 Siddh Raman Pant [this message]
2022-11-15  3:24 ` [RFC PATCH] erofs/zmap.c: Bail out when no further region remains Gao Xiang
2022-11-15 10:09   ` Siddh Raman Pant
2022-11-15 10:50     ` Gao Xiang
2022-12-09  4:50       ` Gao Xiang
2022-12-09  8:29         ` Siddh Raman Pant

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=20221114120349.472418-1-code@siddh.me \
    --to=code@siddh.me \
    --cc=chao@kernel.org \
    --cc=huyue2@coolpad.com \
    --cc=jefflexu@linux.alibaba.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xiang@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;
as well as URLs for NNTP newsgroup(s).