public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [syzbot] [xfs?] KASAN: null-ptr-deref Write in xfs_filestream_select_ag (2)
@ 2024-10-18 19:00 syzbot
  2024-10-20  5:30 ` [PATCH] xfs: If unable to pick perag an error needs to be returned Edward Adam Davis
  2024-10-22  9:41 ` [syzbot] [xfs?] KASAN: null-ptr-deref Write in xfs_filestream_select_ag (2) Christoph Hellwig
  0 siblings, 2 replies; 5+ messages in thread
From: syzbot @ 2024-10-18 19:00 UTC (permalink / raw)
  To: cem, chandan.babu, djwong, linux-kernel, linux-xfs,
	syzkaller-bugs

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+4125a3c514e3436a02e6@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 syzkaller@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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] xfs: If unable to pick perag an error needs to be returned
  2024-10-18 19:00 [syzbot] [xfs?] KASAN: null-ptr-deref Write in xfs_filestream_select_ag (2) syzbot
@ 2024-10-20  5:30 ` Edward Adam Davis
  2024-10-21 13:51   ` Dave Chinner
  2024-10-22  9:41 ` [syzbot] [xfs?] KASAN: null-ptr-deref Write in xfs_filestream_select_ag (2) Christoph Hellwig
  1 sibling, 1 reply; 5+ messages in thread
From: Edward Adam Davis @ 2024-10-20  5:30 UTC (permalink / raw)
  To: syzbot+4125a3c514e3436a02e6
  Cc: cem, chandan.babu, djwong, linux-kernel, linux-xfs,
	syzkaller-bugs

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+4125a3c514e3436a02e6@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=4125a3c514e3436a02e6
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
 fs/xfs/xfs_filestream.c | 4 ++++
 1 file changed, 4 insertions(+)

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;
 
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] xfs: If unable to pick perag an error needs to be returned
  2024-10-20  5:30 ` [PATCH] xfs: If unable to pick perag an error needs to be returned Edward Adam Davis
@ 2024-10-21 13:51   ` Dave Chinner
  0 siblings, 0 replies; 5+ messages in thread
From: Dave Chinner @ 2024-10-21 13:51 UTC (permalink / raw)
  To: Edward Adam Davis
  Cc: syzbot+4125a3c514e3436a02e6, cem, chandan.babu, djwong,
	linux-kernel, linux-xfs, syzkaller-bugs

On Sun, Oct 20, 2024 at 01:30:05PM +0800, Edward Adam Davis wrote:
> 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+4125a3c514e3436a02e6@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=4125a3c514e3436a02e6
> Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> ---
>  fs/xfs/xfs_filestream.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> 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;
> +

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
david@fromorbit.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [syzbot] [xfs?] KASAN: null-ptr-deref Write in xfs_filestream_select_ag (2)
  2024-10-18 19:00 [syzbot] [xfs?] KASAN: null-ptr-deref Write in xfs_filestream_select_ag (2) syzbot
  2024-10-20  5:30 ` [PATCH] xfs: If unable to pick perag an error needs to be returned Edward Adam Davis
@ 2024-10-22  9:41 ` Christoph Hellwig
  2024-10-22 10:11   ` syzbot
  1 sibling, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2024-10-22  9:41 UTC (permalink / raw)
  To: syzbot; +Cc: cem, chandan.babu, djwong, linux-kernel, linux-xfs,
	syzkaller-bugs

#syz test git://git.infradead.org/users/hch/misc.git xfs-filesystems-pick-fix

On Fri, Oct 18, 2024 at 12:00:34PM -0700, syzbot wrote:
> 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+4125a3c514e3436a02e6@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 syzkaller@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
> 
---end quoted text---

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [syzbot] [xfs?] KASAN: null-ptr-deref Write in xfs_filestream_select_ag (2)
  2024-10-22  9:41 ` [syzbot] [xfs?] KASAN: null-ptr-deref Write in xfs_filestream_select_ag (2) Christoph Hellwig
@ 2024-10-22 10:11   ` syzbot
  0 siblings, 0 replies; 5+ messages in thread
From: syzbot @ 2024-10-22 10:11 UTC (permalink / raw)
  To: cem, chandan.babu, djwong, hch, linux-kernel, linux-xfs,
	syzkaller-bugs

Hello,

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

Reported-by: syzbot+4125a3c514e3436a02e6@syzkaller.appspotmail.com
Tested-by: syzbot+4125a3c514e3436a02e6@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.
Note: testing is done by a robot and is best-effort only.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-10-22 10:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-18 19:00 [syzbot] [xfs?] KASAN: null-ptr-deref Write in xfs_filestream_select_ag (2) syzbot
2024-10-20  5:30 ` [PATCH] xfs: If unable to pick perag an error needs to be returned Edward Adam Davis
2024-10-21 13:51   ` Dave Chinner
2024-10-22  9:41 ` [syzbot] [xfs?] KASAN: null-ptr-deref Write in xfs_filestream_select_ag (2) Christoph Hellwig
2024-10-22 10:11   ` syzbot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox