Skip to contentSkip to conversation

general protection fault in ocfs2_prepare_dir_for_insert

syzbot Superseded syzbot 5 participants 11 messages Aug 20, 2024 – Aug 21, 2024 OCFS2

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

syzbot

author syzbot
#0 lore raw

Hello,

syzbot found the following issue on:

HEAD commit:    b0da640826ba Merge tag 'printk-for-6.11-rc5' of git://git...
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=10d2076b980000
kernel config:  https://syzkaller.appspot.com/x/.config?x=df2f0ed7e30a639d
dashboard link: https://syzkaller.appspot.com/bug?extid=5a64828fcc4c2ad9b04f
compiler:       Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=1680ffcb980000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=153aec05980000

Downloadable assets:
disk image (non-bootable): https://storage.googleapis.com/syzbot-assets/7bc7510fe41f/non_bootable_disk-b0da6408.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/f630005f615b/vmlinux-b0da6408.xz
kernel image: https://storage.googleapis.com/syzbot-assets/4e3e4edbec91/bzImage-b0da6408.xz
mounted in repro: https://storage.googleapis.com/syzbot-assets/1a3cbd9c01e6/mount_0.gz

IMPORTANT: if you fix the issue, please add the following tag to the commit:

Reported-by [email protected]

loop0: detected capacity change from 0 to 32768
JBD2: Ignoring recovery information on journal
ocfs2: Mounting device (7,0) on (node local, slot 0) with ordered data mode.

Oops: general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] PREEMPT SMP KASAN NOPTI
KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
CPU: 0 UID: 0 PID: 5096 Comm: syz-executor792 Not tainted 6.11.0-rc4-syzkaller-00002-gb0da640826ba #0
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
RIP: 0010:ocfs2_find_dir_space_id fs/ocfs2/dir.c:3406 [inline]
RIP: 0010:ocfs2_prepare_dir_for_insert+0x3309/0x5c70 fs/ocfs2/dir.c:4280
Code: 00 00 e8 2a 25 13 fe e9 ba 06 00 00 e8 20 25 13 fe e9 4f 01 00 00 e8 16 25 13 fe 49 8d 7f 08 49 8d 5f 09 48 89 f8 48 c1 e8 03 <42> 0f b6 04 20 84 c0 0f 85 bd 23 00 00 48 89 d8 48 c1 e8 03 42 0f
RSP: 0018:ffffc9000af9f020 EFLAGS: 00010202
RAX: 0000000000000001 RBX: 0000000000000009 RCX: ffff88801e27a440
RDX: 0000000000000000 RSI: 0000000000000400 RDI: 0000000000000008
RBP: ffffc9000af9f830 R08: ffffffff8380395b R09: ffffffff838090a7
R10: 0000000000000002 R11: ffff88801e27a440 R12: dffffc0000000000
R13: ffff88803c660878 R14: f700000000000088 R15: 0000000000000000
FS:  000055555a677380(0000) GS:ffff888020800000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000560bce569178 CR3: 000000001de5a000 CR4: 0000000000350ef0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
 ocfs2_mknod+0xcaf/0x2b40 fs/ocfs2/namei.c:292
 vfs_mknod+0x36d/0x3b0 fs/namei.c:4088
 do_mknodat+0x3ec/0x5b0
 __do_sys_mknodat fs/namei.c:4166 [inline]
 __se_sys_mknodat fs/namei.c:4163 [inline]
 __x64_sys_mknodat+0xa7/0xc0 fs/namei.c:4163
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f2dafda3a99
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 f1 17 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffe336a6658 EFLAGS: 00000246 ORIG_RAX: 0000000000000103
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f2dafda3a99
RDX: 00000000000021c0 RSI: 0000000020000040 RDI: 00000000ffffff9c
RBP: 00007f2dafe1b5f0 R08: 0000000000004480 R09: 000055555a6784c0
R10: 0000000000000103 R11: 0000000000000246 R12: 00007ffe336a6680
R13: 00007ffe336a68a8 R14: 431bde82d7b634db R15: 00007f2dafdec03b
 </TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:ocfs2_find_dir_space_id fs/ocfs2/dir.c:3406 [inline]
RIP: 0010:ocfs2_prepare_dir_for_insert+0x3309/0x5c70 fs/ocfs2/dir.c:4280
Code: 00 00 e8 2a 25 13 fe e9 ba 06 00 00 e8 20 25 13 fe e9 4f 01 00 00 e8 16 25 13 fe 49 8d 7f 08 49 8d 5f 09 48 89 f8 48 c1 e8 03 <42> 0f b6 04 20 84 c0 0f 85 bd 23 00 00 48 89 d8 48 c1 e8 03 42 0f
RSP: 0018:ffffc9000af9f020 EFLAGS: 00010202
RAX: 0000000000000001 RBX: 0000000000000009 RCX: ffff88801e27a440
RDX: 0000000000000000 RSI: 0000000000000400 RDI: 0000000000000008
RBP: ffffc9000af9f830 R08: ffffffff8380395b R09: ffffffff838090a7
R10: 0000000000000002 R11: ffff88801e27a440 R12: dffffc0000000000
R13: ffff88803c660878 R14: f700000000000088 R15: 0000000000000000
FS:  000055555a677380(0000) GS:ffff888020800000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000560bce569178 CR3: 000000001de5a000 CR4: 0000000000350ef0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
----------------
Code disassembly (best guess):
   0:	00 00                	add    %al,(%rax)
   2:	e8 2a 25 13 fe       	call   0xfe132531
   7:	e9 ba 06 00 00       	jmp    0x6c6
   c:	e8 20 25 13 fe       	call   0xfe132531
  11:	e9 4f 01 00 00       	jmp    0x165
  16:	e8 16 25 13 fe       	call   0xfe132531
  1b:	49 8d 7f 08          	lea    0x8(%r15),%rdi
  1f:	49 8d 5f 09          	lea    0x9(%r15),%rbx
  23:	48 89 f8             	mov    %rdi,%rax
  26:	48 c1 e8 03          	shr    $0x3,%rax
* 2a:	42 0f b6 04 20       	movzbl (%rax,%r12,1),%eax <-- trapping instruction
  2f:	84 c0                	test   %al,%al
  31:	0f 85 bd 23 00 00    	jne    0x23f4
  37:	48 89 d8             	mov    %rbx,%rax
  3a:	48 c1 e8 03          	shr    $0x3,%rax
  3e:	42                   	rex.X
  3f:	0f                   	.byte 0xf

---
This report is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at [email protected].

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

#1 lore raw

i_size_read(dir) too big, make limit overflow, cause last_de uninit.

#syz test: upstream b0da640826ba

fs/ocfs2/dir.c +2 -0
index d620d4c53c6f..c308dba6d213 100644
@@ -3343,6 +3343,8 @@ static int ocfs2_find_dir_space_id(struct inode *dir, struct buffer_head *di_bh,
 	unsigned long offset = 0;
 	unsigned int rec_len, new_rec_len, free_space;
 
+	if (i_size_read(dir) > OCFS2_MAX_BLOCKSIZE)
+		return -EINVAL;
 	/*
 	 * This calculates how many free bytes we'd have in block zero, should
 	 * this function force expansion to an extent tree.
author syzbot Tested-by
#2 lore raw
syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Tested on:

commit:         b0da6408 Merge tag 'printk-for-6.11-rc5' of git://git...
git tree:       git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=15c8a7c5980000
kernel config:  https://syzkaller.appspot.com/x/.config?x=df2f0ed7e30a639d
dashboard link: https://syzkaller.appspot.com/bug?extid=5a64828fcc4c2ad9b04f
compiler:       Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch:          https://syzkaller.appspot.com/x/patch.diff?x=15e4dbd3980000

Note: testing is done by a robot and is best-effort only.

#3 lore raw

PATCH 1/1 ocfs2: Add i_size check for dir

In reply to syzbot

When the i_size of dir is too large, it will cause limit to overflow and be less than de_buf, ultimately resulting in last_de not being initialized and causing uaf issue.

---
 fs/ocfs2/dir.c | 2 ++
 1 file changed, 2 insertions(+)
fs/ocfs2/dir.c +2 -0
index d620d4c53c6f..c308dba6d213 100644
@@ -3343,6 +3343,8 @@ static int ocfs2_find_dir_space_id(struct inode *dir, struct buffer_head *di_bh,
 	unsigned long offset = 0;
 	unsigned int rec_len, new_rec_len, free_space;
 
+	if (i_size_read(dir) > OCFS2_MAX_BLOCKSIZE)
+		return -EINVAL;
 	/*
 	 * This calculates how many free bytes we'd have in block zero, should
 	 * this function force expansion to an extent tree.
Signature · 1 line
2.43.0
maintainer
#4 lore raw

Re: [PATCH] ocfs2: Add i_size check for dir

Quoted 15 lines · Edward Adam Davis

When the i_size of dir is too large, it will cause limit to overflow and be less than de_buf, ultimately resulting in last_de not being initialized and causing uaf issue.

---
 fs/ocfs2/dir.c | 2 ++
 1 file changed, 2 insertions(+)
fs/ocfs2/dir.c +0 -0
index d620d4c53c6f..c308dba6d213 100644

fs/ocfs2/dir.c static int ocfs2_find_dir_space_id(struct inode *dir, struct buffer_head *di_bh, · line 3347

Quoted 5 lines
fs/ocfs2/dir.c +2 -0
@@ -3343,6 +3343,8 @@ static int ocfs2_find_dir_space_id(struct inode *dir, struct buffer_head *di_bh,
 	unsigned long offset = 0;
 	unsigned int rec_len, new_rec_len, free_space;
 
+	if (i_size_read(dir) > OCFS2_MAX_BLOCKSIZE)
+		return -EINVAL;

Why OCFS2_MAX_BLOCKSIZE?
It seems that this is caused by a corrupted dir inode, since this is an inline case, we may try best to make sure it won't exceeds block size? i.e. dir->i_sb->s_blocksize.

Thanks,
Joseph

Quoted 3 lines
fs/ocfs2/dir.c +0 -0
 	/*
 	 * This calculates how many free bytes we'd have in block zero, should
 	 * this function force expansion to an extent tree.
#5 lore raw

Re: [PATCH] ocfs2: Add i_size check for dir

Quoted 18 lines · Joseph Qi
Quoted 18 lines

When the i_size of dir is too large, it will cause limit to overflow and be less than de_buf, ultimately resulting in last_de not being initialized and causing uaf issue.

---
 fs/ocfs2/dir.c | 2 ++
 1 file changed, 2 insertions(+)
fs/ocfs2/dir.c +0 -0
index d620d4c53c6f..c308dba6d213 100644
@@ -3343,6 +3343,8 @@ static int ocfs2_find_dir_space_id(struct inode *dir, struct buffer_head *di_bh,
 	unsigned long offset = 0;
 	unsigned int rec_len, new_rec_len, free_space;
 
Quoted 4 lines

fs/ocfs2/dir.c static int ocfs2_find_dir_space_id(struct inode *dir, struct buffer_head *di_bh, · line 3347

Quoted 2 lines
fs/ocfs2/dir.c +2 -0
+	if (i_size_read(dir) > OCFS2_MAX_BLOCKSIZE)
+		return -EINVAL;

Why OCFS2_MAX_BLOCKSIZE?

I think it is largest block size in ocfs2, therefore, if it is larger than it, it must be incorrect, even though the value of i_size in dir in the current issue is much larger than it (i_size_read(dir) is 0x900000000000100).

Quoted 3 lines

It seems that this is caused by a corrupted dir inode, since this is an inline case, we may try best to make sure it won't exceeds block size? i.e. dir->i_sb->s_blocksize.

You mean dir->i_sb->s_blocksize bigger than OCFS2_MAX_BLOCKSIZE?

BR,
Edward

maintainer
#6 lore raw

Re: [PATCH] ocfs2: Add i_size check for dir

Quoted 23 lines · Edward Adam Davis
Quoted 18 lines · Joseph Qi
Quoted 18 lines

When the i_size of dir is too large, it will cause limit to overflow and be less than de_buf, ultimately resulting in last_de not being initialized and causing uaf issue.

---
 fs/ocfs2/dir.c | 2 ++
 1 file changed, 2 insertions(+)
fs/ocfs2/dir.c +0 -0
index d620d4c53c6f..c308dba6d213 100644
@@ -3343,6 +3343,8 @@ static int ocfs2_find_dir_space_id(struct inode *dir, struct buffer_head *di_bh,
 	unsigned long offset = 0;
 	unsigned int rec_len, new_rec_len, free_space;
 
Quoted 4 lines

fs/ocfs2/dir.c static int ocfs2_find_dir_space_id(struct inode *dir, struct buffer_head *di_bh, · line 3347

Quoted 2 lines
fs/ocfs2/dir.c +2 -0
+	if (i_size_read(dir) > OCFS2_MAX_BLOCKSIZE)
+		return -EINVAL;

Why OCFS2_MAX_BLOCKSIZE?

Quoted 8 lines

I think it is largest block size in ocfs2, therefore, if it is larger than it, it must be incorrect, even though the value of i_size in dir in the current issue is much larger than it (i_size_read(dir) is 0x900000000000100).

Quoted 3 lines

It seems that this is caused by a corrupted dir inode, since this is an inline case, we may try best to make sure it won't exceeds block size? i.e. dir->i_sb->s_blocksize.

You mean dir->i_sb->s_blocksize bigger than OCFS2_MAX_BLOCKSIZE?

No, I mean check s_blocksize seems more reasonable rather than OCFS2_MAX_BLOCKSIZE.

Thanks,
Joseph

#7 lore raw

Re: [PATCH] ocfs2: Add i_size check for dir

Quoted 25 lines · Joseph Qi
Quoted 25 lines
Quoted 18 lines
Quoted 18 lines

When the i_size of dir is too large, it will cause limit to overflow and be less than de_buf, ultimately resulting in last_de not being initialized and causing uaf issue.

---
 fs/ocfs2/dir.c | 2 ++
 1 file changed, 2 insertions(+)
fs/ocfs2/dir.c +0 -0
index d620d4c53c6f..c308dba6d213 100644
@@ -3343,6 +3343,8 @@ static int ocfs2_find_dir_space_id(struct inode *dir, struct buffer_head *di_bh,
 	unsigned long offset = 0;
 	unsigned int rec_len, new_rec_len, free_space;
 
Quoted 4 lines

fs/ocfs2/dir.c static int ocfs2_find_dir_space_id(struct inode *dir, struct buffer_head *di_bh, · line 3347

Quoted 2 lines
fs/ocfs2/dir.c +2 -0
+	if (i_size_read(dir) > OCFS2_MAX_BLOCKSIZE)
+		return -EINVAL;

Why OCFS2_MAX_BLOCKSIZE?

I think it is largest block size in ocfs2, therefore, if it is larger than it, it must be incorrect, even though the value of i_size in dir in the current issue is much larger than it (i_size_read(dir) is 0x900000000000100).

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

It seems that this is caused by a corrupted dir inode, since this is an inline case, we may try best to make sure it won't exceeds block size? i.e. dir->i_sb->s_blocksize.

You mean dir->i_sb->s_blocksize bigger than OCFS2_MAX_BLOCKSIZE?

No, I mean check s_blocksize seems more reasonable rather than OCFS2_MAX_BLOCKSIZE.

Perhaps we have different perspectives on the issue.
My approach is to set a bottom line for the dir's i_size, and if it exceeds the bottom line, the dir will definitely be corrupted. And I think OCFS2_MAX_BLOCKSIZE is the reasonable bottom line.

BR,
Edward

#8 lore raw

Re: [PATCH] ocfs2: Add i_size check for dir

In reply to Edward Adam Davis

fs/ocfs2/dir.c static int ocfs2_find_dir_space_id(struct inode *dir, struct buffer_head *di_bh, · line 3347

Quoted 6 lines · Edward Adam Davis

When the i_size of dir is too large, it will cause limit to overflow and be less than de_buf, ultimately resulting in last_de not being initialized and causing uaf issue.

fs/ocfs2/dir.c +2 -0
+	if (i_size_read(dir) > OCFS2_MAX_BLOCKSIZE)
+		return -EINVAL;

Surely directories can be more than one block in size?

#9 lore raw

Re: [PATCH] ocfs2: Add i_size check for dir

Quoted 10 lines · Matthew Wilcox

fs/ocfs2/dir.c static int ocfs2_find_dir_space_id(struct inode *dir, struct buffer_head *di_bh, · line 3347

Quoted 6 lines · Edward Adam Davis

When the i_size of dir is too large, it will cause limit to overflow and be less than de_buf, ultimately resulting in last_de not being initialized and causing uaf issue.

fs/ocfs2/dir.c +2 -0
+	if (i_size_read(dir) > OCFS2_MAX_BLOCKSIZE)
+		return -EINVAL;

Surely directories can be more than one block in size?

The key point above is that the patch uses a hard code value, but in the real world, the blocksize can be smaller than OCFS2_MAX_BLOCKSIZE.

-Heming

#10 lore raw

Re: [PATCH] ocfs2: Add i_size check for dir

In reply to Matthew Wilcox
Quoted 8 lines · Matthew Wilcox

fs/ocfs2/dir.c static int ocfs2_find_dir_space_id(struct inode *dir, struct buffer_head *di_bh, · line 3347

Quoted 6 lines

When the i_size of dir is too large, it will cause limit to overflow and be less than de_buf, ultimately resulting in last_de not being initialized and causing uaf issue.

fs/ocfs2/dir.c +2 -0
+	if (i_size_read(dir) > OCFS2_MAX_BLOCKSIZE)
+		return -EINVAL;

Surely directories can be more than one block in size?

In this issue, Yes.

--
Edward