[syzbot] [xfs?] KASAN: null-ptr-deref Write in xfs_filestream_select_ag (2)

20 views
Skip to first unread message

syzbot

unread,
Oct 18, 2024, 3:00:36 PM10/18/24
to c...@kernel.org, chanda...@oracle.com, djw...@kernel.org, linux-...@vger.kernel.org, linu...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 4d939780b705 Merge tag 'mm-hotfixes-stable-2024-10-17-16-0..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=169f4c5f980000
kernel config: https://syzkaller.appspot.com/x/.config?x=164d2822debd8b0d
dashboard link: https://syzkaller.appspot.com/bug?extid=4125a3c514e3436a02e6
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=1374d830580000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/cbc7a4f0dff1/disk-4d939780.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/21165b36b232/vmlinux-4d939780.xz
kernel image: https://storage.googleapis.com/syzbot-assets/8e42c5595828/bzImage-4d939780.xz
mounted in repro #1: https://storage.googleapis.com/syzbot-assets/9171ce715585/mount_0.gz
mounted in repro #2: https://storage.googleapis.com/syzbot-assets/faf0b43468d6/mount_2.gz
mounted in repro #3: https://storage.googleapis.com/syzbot-assets/12ac0c5a53d1/mount_14.gz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+4125a3...@syzkaller.appspotmail.com

==================================================================
BUG: KASAN: null-ptr-deref in instrument_atomic_read_write include/linux/instrumented.h:96 [inline]
BUG: KASAN: null-ptr-deref in atomic_inc include/linux/atomic/atomic-instrumented.h:435 [inline]
BUG: KASAN: null-ptr-deref in xfs_filestream_create_association fs/xfs/xfs_filestream.c:320 [inline]
BUG: KASAN: null-ptr-deref in xfs_filestream_select_ag+0x13ed/0x1d80 fs/xfs/xfs_filestream.c:371
Write of size 4 at addr 0000000000000010 by task syz.1.56/5898

CPU: 0 UID: 0 PID: 5898 Comm: syz.1.56 Not tainted 6.12.0-rc3-syzkaller-00217-g4d939780b705 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120
print_report+0xe8/0x550 mm/kasan/report.c:491
kasan_report+0x143/0x180 mm/kasan/report.c:601
kasan_check_range+0x282/0x290 mm/kasan/generic.c:189
instrument_atomic_read_write include/linux/instrumented.h:96 [inline]
atomic_inc include/linux/atomic/atomic-instrumented.h:435 [inline]
xfs_filestream_create_association fs/xfs/xfs_filestream.c:320 [inline]
xfs_filestream_select_ag+0x13ed/0x1d80 fs/xfs/xfs_filestream.c:371
xfs_bmap_btalloc_filestreams fs/xfs/libxfs/xfs_bmap.c:3657 [inline]
xfs_bmap_btalloc fs/xfs/libxfs/xfs_bmap.c:3774 [inline]
xfs_bmapi_allocate+0x162d/0x3450 fs/xfs/libxfs/xfs_bmap.c:4189
xfs_bmapi_convert_one_delalloc fs/xfs/libxfs/xfs_bmap.c:4697 [inline]
xfs_bmapi_convert_delalloc+0x9a0/0x1970 fs/xfs/libxfs/xfs_bmap.c:4752
xfs_map_blocks+0x7b7/0x1050 fs/xfs/xfs_aops.c:363
iomap_writepage_map_blocks fs/iomap/buffered-io.c:1855 [inline]
iomap_writepage_map fs/iomap/buffered-io.c:2003 [inline]
iomap_writepages+0xd49/0x2ac0 fs/iomap/buffered-io.c:2057
xfs_vm_writepages+0xfc/0x150 fs/xfs/xfs_aops.c:477
do_writepages+0x35d/0x870 mm/page-writeback.c:2683
filemap_fdatawrite_wbc+0x125/0x180 mm/filemap.c:398
__filemap_fdatawrite_range mm/filemap.c:431 [inline]
file_write_and_wait_range+0x195/0x280 mm/filemap.c:788
xfs_file_fsync+0x1d3/0xa80 fs/xfs/xfs_file.c:138
generic_write_sync include/linux/fs.h:2871 [inline]
xfs_file_buffered_write+0x9a8/0xac0 fs/xfs/xfs_file.c:799
new_sync_write fs/read_write.c:590 [inline]
vfs_write+0xa6d/0xc90 fs/read_write.c:683
ksys_write+0x183/0x2b0 fs/read_write.c:736
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:0x7f11d7b7dff9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 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 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f11d75de038 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007f11d7d36208 RCX: 00007f11d7b7dff9
RDX: 0000000000000048 RSI: 0000000020020cc0 RDI: 0000000000000004
RBP: 00007f11d7bf0296 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000000000 R14: 00007f11d7d36208 R15: 00007ffcddfd4a88
</TASK>
==================================================================


---
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 syzk...@googlegroups.com.

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

Edward Adam Davis

unread,
Oct 19, 2024, 10:53:15 PM10/19/24
to syzbot+4125a3...@syzkaller.appspotmail.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
catch can't pick any perpag

#syz test

diff --git a/fs/xfs/xfs_filestream.c b/fs/xfs/xfs_filestream.c
index e3aaa0555597..8c8f341cf627 100644
--- a/fs/xfs/xfs_filestream.c
+++ b/fs/xfs/xfs_filestream.c
@@ -165,6 +165,7 @@ xfs_filestream_pick_ag(

trace_xfs_filestream_pick(pag, pino, free);
args->pag = pag;
+ printk("pag: %p, %s\n", args->pag, __func__);
return 0;

}
@@ -298,8 +299,8 @@ xfs_filestream_create_association(

*longest = ap->length;
error = xfs_filestream_pick_ag(args, pino, agno, flags, longest);
- if (error)
- return error;
+ if (error || !args->pag)
+ return error ?: 0;

/*
* We are going to use this perag now, so create an assoication for it.

syzbot

unread,
Oct 19, 2024, 11:14:04 PM10/19/24
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
general protection fault in xfs_filestream_select_ag

pag: 0000000000000000, xfs_filestream_pick_ag
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] PREEMPT SMP KASAN PTI
KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
CPU: 1 UID: 0 PID: 6564 Comm: syz.0.31 Not tainted 6.12.0-rc3-syzkaller-00420-g715ca9dd687f-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
RIP: 0010:xfs_filestream_select_ag+0xfd0/0x1d60 fs/xfs/xfs_filestream.c:377
Code: 24 08 49 83 c4 18 4c 89 e0 48 c1 e8 03 80 3c 28 00 74 08 4c 89 e7 e8 5f 3c a7 fe 49 8b 1c 24 48 83 c3 08 48 89 d8 48 c1 e8 03 <0f> b6 04 28 84 c0 0f 85 bb 07 00 00 8b 1b 48 8b 94 24 a0 00 00 00
RSP: 0018:ffffc900043eeb58 EFLAGS: 00010202
RAX: 0000000000000001 RBX: 0000000000000008 RCX: ffff88802ea13c00
RDX: 0000000000000000 RSI: 0000000080000000 RDI: 0000000000000000
RBP: dffffc0000000000 R08: ffffffff8174af9c R09: 1ffff9200087dd08
R10: dffffc0000000000 R11: fffff5200087dd09 R12: ffffc900043eeda8
R13: dffffc0000000000 R14: ffffc900043eefe0 R15: ffffc900043eed90
FS: 00007f847f8b96c0(0000) GS:ffff8880b8700000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fd5ac27b378 CR3: 0000000024938000 CR4: 00000000003526f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<TASK>
xfs_bmap_btalloc_filestreams fs/xfs/libxfs/xfs_bmap.c:3657 [inline]
xfs_bmap_btalloc fs/xfs/libxfs/xfs_bmap.c:3774 [inline]
xfs_bmapi_allocate+0x162d/0x3450 fs/xfs/libxfs/xfs_bmap.c:4189
xfs_bmapi_convert_one_delalloc fs/xfs/libxfs/xfs_bmap.c:4697 [inline]
xfs_bmapi_convert_delalloc+0x9a0/0x1970 fs/xfs/libxfs/xfs_bmap.c:4752
xfs_map_blocks+0x7b7/0x1050 fs/xfs/xfs_aops.c:363
iomap_writepage_map_blocks fs/iomap/buffered-io.c:1816 [inline]
iomap_writepage_map fs/iomap/buffered-io.c:1964 [inline]
iomap_writepages+0xd49/0x2ac0 fs/iomap/buffered-io.c:2018
xfs_vm_writepages+0xfc/0x150 fs/xfs/xfs_aops.c:477
do_writepages+0x35d/0x870 mm/page-writeback.c:2683
filemap_fdatawrite_wbc+0x125/0x180 mm/filemap.c:398
__filemap_fdatawrite_range mm/filemap.c:431 [inline]
file_write_and_wait_range+0x195/0x280 mm/filemap.c:788
xfs_file_fsync+0x1d3/0xa80 fs/xfs/xfs_file.c:138
generic_write_sync include/linux/fs.h:2871 [inline]
xfs_file_buffered_write+0x9a8/0xac0 fs/xfs/xfs_file.c:829
new_sync_write fs/read_write.c:590 [inline]
vfs_write+0xa6d/0xc90 fs/read_write.c:683
ksys_write+0x183/0x2b0 fs/read_write.c:736
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:0x7f847eb7dff9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 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 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f847f8b9038 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007f847ed36208 RCX: 00007f847eb7dff9
RDX: 0000000000000048 RSI: 0000000020020cc0 RDI: 0000000000000004
RBP: 00007f847ebf0296 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000000000 R14: 00007f847ed36208 R15: 00007fff16fee758
</TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:xfs_filestream_select_ag+0xfd0/0x1d60 fs/xfs/xfs_filestream.c:377
Code: 24 08 49 83 c4 18 4c 89 e0 48 c1 e8 03 80 3c 28 00 74 08 4c 89 e7 e8 5f 3c a7 fe 49 8b 1c 24 48 83 c3 08 48 89 d8 48 c1 e8 03 <0f> b6 04 28 84 c0 0f 85 bb 07 00 00 8b 1b 48 8b 94 24 a0 00 00 00
RSP: 0018:ffffc900043eeb58 EFLAGS: 00010202
RAX: 0000000000000001 RBX: 0000000000000008 RCX: ffff88802ea13c00
RDX: 0000000000000000 RSI: 0000000080000000 RDI: 0000000000000000
RBP: dffffc0000000000 R08: ffffffff8174af9c R09: 1ffff9200087dd08
R10: dffffc0000000000 R11: fffff5200087dd09 R12: ffffc900043eeda8
R13: dffffc0000000000 R14: ffffc900043eefe0 R15: ffffc900043eed90
FS: 00007f847f8b96c0(0000) GS:ffff8880b8600000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f17012ff000 CR3: 0000000024938000 CR4: 00000000003526f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
----------------
Code disassembly (best guess):
0: 24 08 and $0x8,%al
2: 49 83 c4 18 add $0x18,%r12
6: 4c 89 e0 mov %r12,%rax
9: 48 c1 e8 03 shr $0x3,%rax
d: 80 3c 28 00 cmpb $0x0,(%rax,%rbp,1)
11: 74 08 je 0x1b
13: 4c 89 e7 mov %r12,%rdi
16: e8 5f 3c a7 fe call 0xfea73c7a
1b: 49 8b 1c 24 mov (%r12),%rbx
1f: 48 83 c3 08 add $0x8,%rbx
23: 48 89 d8 mov %rbx,%rax
26: 48 c1 e8 03 shr $0x3,%rax
* 2a: 0f b6 04 28 movzbl (%rax,%rbp,1),%eax <-- trapping instruction
2e: 84 c0 test %al,%al
30: 0f 85 bb 07 00 00 jne 0x7f1
36: 8b 1b mov (%rbx),%ebx
38: 48 8b 94 24 a0 00 00 mov 0xa0(%rsp),%rdx
3f: 00


Tested on:

commit: 715ca9dd Merge tag 'io_uring-6.12-20241019' of git://g..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=14deb240580000
kernel config: https://syzkaller.appspot.com/x/.config?x=78db40d8379956d9
dashboard link: https://syzkaller.appspot.com/bug?extid=4125a3c514e3436a02e6
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=157a0c87980000

Edward Adam Davis

unread,
Oct 19, 2024, 11:35:20 PM10/19/24
to syzbot+4125a3...@syzkaller.appspotmail.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
catch can't pick any perpag

#syz test

diff --git a/fs/xfs/xfs_filestream.c b/fs/xfs/xfs_filestream.c
index e3aaa0555597..f4c731fd61ea 100644
--- a/fs/xfs/xfs_filestream.c
+++ b/fs/xfs/xfs_filestream.c
@@ -159,6 +159,8 @@ xfs_filestream_pick_ag(
free = maxfree;
atomic_inc(&pag->pagf_fstrms);
}
+
+ return -ENOSPC;
} else if (max_pag) {
xfs_perag_rele(max_pag);
}

syzbot

unread,
Oct 20, 2024, 12:12:05 AM10/20/24
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

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

Reported-by: syzbot+4125a3...@syzkaller.appspotmail.com
Tested-by: syzbot+4125a3...@syzkaller.appspotmail.com

Tested on:

commit: 715ca9dd Merge tag 'io_uring-6.12-20241019' of git://g..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=12d9b240580000
kernel config: https://syzkaller.appspot.com/x/.config?x=78db40d8379956d9
dashboard link: https://syzkaller.appspot.com/bug?extid=4125a3c514e3436a02e6
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=134a20a7980000

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

Edward Adam Davis

unread,
Oct 20, 2024, 1:00:59 AM10/20/24
to syzbot+4125a3...@syzkaller.appspotmail.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
can't pick any perpag

#syz test

diff --git a/fs/xfs/xfs_filestream.c b/fs/xfs/xfs_filestream.c
index e3aaa0555597..dd8f193a3957 100644
--- a/fs/xfs/xfs_filestream.c
+++ b/fs/xfs/xfs_filestream.c
@@ -165,6 +165,10 @@ xfs_filestream_pick_ag(

trace_xfs_filestream_pick(pag, pino, free);
args->pag = pag;
+
+ if (!args->pag)
+ return -ENOSPC;
+
return 0;

}

syzbot

unread,
Oct 20, 2024, 1:27:06 AM10/20/24
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

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

Reported-by: syzbot+4125a3...@syzkaller.appspotmail.com
Tested-by: syzbot+4125a3...@syzkaller.appspotmail.com

Tested on:

commit: 715ca9dd Merge tag 'io_uring-6.12-20241019' of git://g..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=13a120a7980000
kernel config: https://syzkaller.appspot.com/x/.config?x=78db40d8379956d9
dashboard link: https://syzkaller.appspot.com/bug?extid=4125a3c514e3436a02e6
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=12480d1b980000

Edward Adam Davis

unread,
Oct 20, 2024, 1:30:16 AM10/20/24
to syzbot+4125a3...@syzkaller.appspotmail.com, c...@kernel.org, chanda...@oracle.com, djw...@kernel.org, linux-...@vger.kernel.org, linu...@vger.kernel.org, syzkall...@googlegroups.com
Syzbot reported a null-ptr-deref Write in xfs_filestream_select_ag.
When pag is not found, xfs_filestream_pick_ag() also returns 0, which leads
to null pointer access in xfs_filestream_create_association().

At the end of xfs_filestream_pick_ag, we need to add a sanity check for pag,
if we fail to grab any AG, we should return to -ENOSPC instead of 0.

Reported-and-tested-by: syzbot+4125a3...@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=4125a3c514e3436a02e6
Signed-off-by: Edward Adam Davis <ead...@qq.com>
---
fs/xfs/xfs_filestream.c | 4 ++++
1 file changed, 4 insertions(+)
--
2.43.0

Dave Chinner

unread,
Oct 21, 2024, 9:51:08 AM10/21/24
to Edward Adam Davis, syzbot+4125a3...@syzkaller.appspotmail.com, c...@kernel.org, chanda...@oracle.com, djw...@kernel.org, linux-...@vger.kernel.org, linu...@vger.kernel.org, syzkall...@googlegroups.com
If we get here with pag == NULL, then something else has gone
wrong before we got here.

i.e. there's an if (!pag) {} check directly above this, and it can
only fall through to this code if pag != NULL. Hence if pag is NULL
at this point, we should have already hit a null pointer deref
before we got to this point...

So, where's the null pag coming from?

-Dave.
--
Dave Chinner
da...@fromorbit.com

Christoph Hellwig

unread,
Oct 22, 2024, 5:41:36 AM10/22/24
to syzbot, c...@kernel.org, chanda...@oracle.com, djw...@kernel.org, linux-...@vger.kernel.org, linu...@vger.kernel.org, syzkall...@googlegroups.com
#syz test git://git.infradead.org/users/hch/misc.git xfs-filesystems-pick-fix
---end quoted text---

syzbot

unread,
Oct 22, 2024, 6:11:05 AM10/22/24
to c...@kernel.org, chanda...@oracle.com, djw...@kernel.org, h...@infradead.org, linux-...@vger.kernel.org, linu...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

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

Reported-by: syzbot+4125a3...@syzkaller.appspotmail.com
Tested-by: syzbot+4125a3...@syzkaller.appspotmail.com

Tested on:

commit: 0338c38c xfs: fix finding a last resort AG in xfs_file..
git tree: git://git.infradead.org/users/hch/misc.git xfs-filesystems-pick-fix
console output: https://syzkaller.appspot.com/x/log.txt?x=11150287980000
kernel config: https://syzkaller.appspot.com/x/.config?x=41330fd2db03893d
dashboard link: https://syzkaller.appspot.com/bug?extid=4125a3c514e3436a02e6
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40

Note: no patches were applied.
Reply all
Reply to author
Forward
0 new messages