mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Edward Adam Davis <eadavis@qq.com>
To: joseph.qi@linux.alibaba.com
Cc: eadavis@qq.com, jlbec@evilplan.org, l@damenly.org,
	linux-kernel@vger.kernel.org, mark@fasheh.com,
	ocfs2-devel@lists.linux.dev,
	syzbot+81092778aac03460d6b7@syzkaller.appspotmail.com,
	syzkaller-bugs@googlegroups.com
Subject: [PATCH V4] ocfs2: pass u64 to ocfs2_truncate_inline maybe overflow
Date: Wed, 16 Oct 2024 19:43:47 +0800	[thread overview]
Message-ID: <tencent_D48DB5122ADDAEDDD11918CFB68D93258C07@qq.com> (raw)
In-Reply-To: <21d7a0d6-faac-4914-8907-1d7d983953f2@linux.alibaba.com>

Syzbot reported a kernel BUG in ocfs2_truncate_inline.
There are two reasons for this: first, the parameter value passed is greater
than ocfs2_max_inline_data_with_xattr, second, the start and end parameters
of ocfs2_truncate_inline are "unsigned int".

So, we need to add a sanity check for byte_start and byte_len right before
ocfs2_truncate_inline() in ocfs2_remove_inode_range(), if they are greater
than ocfs2_max_inline_data_with_xattr return -EINVAL.

Reported-by: syzbot+81092778aac03460d6b7@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=81092778aac03460d6b7
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
V1 -> V2: move sanity check to ocfs2_remove_inode_range
V2 -> V3: use ocfs2_max_inline_data_with_xattr return value replace UINT_MAX
V3 -> V4: rename variable, modify return value and comments

 fs/ocfs2/file.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index ad131a2fc58e..47121ee4b4df 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -1784,6 +1784,14 @@ int ocfs2_remove_inode_range(struct inode *inode,
 		return 0;
 
 	if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) {
+		int id_count = ocfs2_max_inline_data_with_xattr(inode->i_sb, di);
+
+		if (byte_start > id_count || byte_start + byte_len > id_count) {
+			ret = -EINVAL;
+			mlog_errno(ret);
+			goto out;
+		}
+
 		ret = ocfs2_truncate_inline(inode, di_bh, byte_start,
 					    byte_start + byte_len, 0);
 		if (ret) {
-- 
2.43.0


  reply	other threads:[~2024-10-16 11:48 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-09  6:18 [syzbot] [ocfs2?] kernel BUG in ocfs2_truncate_inline syzbot
2024-10-09  9:00 ` Edward Adam Davis
2024-10-09 14:11   ` [syzbot] " syzbot
2024-10-09 15:05 ` [PATCH] ocfs2: pass u64 to ocfs2_truncate_inline maybe overflow Edward Adam Davis
2024-10-10 12:21   ` Joseph Qi
2024-10-10 14:31     ` [PATCH V2] " Edward Adam Davis
2024-10-11  1:07       ` Su Yue
2024-10-11  2:01         ` Joseph Qi
2024-10-16  2:08           ` Joseph Qi
2024-10-16  3:22             ` [PATCH V3] " Edward Adam Davis
2024-10-16  9:49               ` Joseph Qi
2024-10-16 11:43                 ` Edward Adam Davis [this message]
2024-10-16 11:47                   ` [PATCH V4] " Joseph Qi
2024-10-16 11:54                     ` Joseph Qi
2024-10-10 14:32 ` [ocfs2?] kernel BUG in ocfs2_truncate_inline Edward Adam Davis
2024-10-10 16:31   ` [syzbot] " syzbot
2024-10-16  3:29 ` Edward Adam Davis
2024-10-16  4:59   ` [syzbot] " syzbot

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=tencent_D48DB5122ADDAEDDD11918CFB68D93258C07@qq.com \
    --to=eadavis@qq.com \
    --cc=jlbec@evilplan.org \
    --cc=joseph.qi@linux.alibaba.com \
    --cc=l@damenly.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark@fasheh.com \
    --cc=ocfs2-devel@lists.linux.dev \
    --cc=syzbot+81092778aac03460d6b7@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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

all inboxes | Powered by JetHome®