Skip to contentSkip to conversation

KMSAN: uninit-value in swap_writeout

syzbot syzbot 5 participants 8 messages Dec 22, 2025 – Jan 5

Subsystems (2)
lore
Share & tools
lore

syzbot

author syzbot
#0 lore raw

Hello,

syzbot found the following issue on:

HEAD commit:    ea1013c15392 Merge tag 'bpf-fixes' of git://git.kernel.org..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=11d2e31a580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=b3903bdf68407a14
dashboard link: https://syzkaller.appspot.com/bug?extid=178fff6149127421c2cc
compiler:       Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8
userspace arch: i386

Unfortunately, I don't have any reproducer for this issue yet.

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/27172fba4316/disk-ea1013c1.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/ac8c65aa1d08/vmlinux-ea1013c1.xz
kernel image: https://storage.googleapis.com/syzbot-assets/42241f684d1d/bzImage-ea1013c1.xz

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

Reported-by [email protected]

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

BUG: KMSAN: uninit-value in is_folio_zero_filled mm/page_io.c:188 [inline]
BUG: KMSAN: uninit-value in swap_writeout+0x468/0x1390 mm/page_io.c:263
 is_folio_zero_filled mm/page_io.c:188 [inline]
 swap_writeout+0x468/0x1390 mm/page_io.c:263
 shmem_writeout+0x1abb/0x1f60 mm/shmem.c:1662
 writeout mm/vmscan.c:649 [inline]
 pageout mm/vmscan.c:698 [inline]
 shrink_folio_list+0x5920/0x7fc0 mm/vmscan.c:1418
 evict_folios+0x999d/0xbf30 mm/vmscan.c:4711
 try_to_shrink_lruvec+0x12b6/0x17e0 mm/vmscan.c:4874
 lru_gen_shrink_lruvec mm/vmscan.c:5023 [inline]
 shrink_lruvec+0x46f/0x4f10 mm/vmscan.c:5784
 shrink_node_memcgs mm/vmscan.c:6020 [inline]
 shrink_node+0xf1e/0x51e0 mm/vmscan.c:6061
 shrink_zones mm/vmscan.c:6300 [inline]
 do_try_to_free_pages+0x849/0x26b0 mm/vmscan.c:6362
 try_to_free_mem_cgroup_pages+0x3ae/0x950 mm/vmscan.c:6690
 try_charge_memcg+0x80f/0x1c50 mm/memcontrol.c:2388
 obj_cgroup_charge_pages+0x2ed/0x600 mm/memcontrol.c:2823
 __memcg_kmem_charge_page+0x14a/0x4c0 mm/memcontrol.c:2867
 __alloc_frozen_pages_noprof+0x3ba/0xab0 mm/page_alloc.c:5227
 alloc_pages_mpol+0x328/0x860 mm/mempolicy.c:2486
 alloc_frozen_pages_noprof mm/mempolicy.c:2557 [inline]
 alloc_pages_noprof+0x102/0x280 mm/mempolicy.c:2577
 io_mem_alloc_compound io_uring/memmap.c:30 [inline]
 io_region_allocate_pages+0x164/0x900 io_uring/memmap.c:165
 io_create_region+0x6d0/0x830 io_uring/memmap.c:220
 io_allocate_scq_urings+0x1e3/0x8a0 io_uring/io_uring.c:3379
 io_uring_create+0x7b5/0x1040 io_uring/io_uring.c:3643
 io_uring_setup io_uring/io_uring.c:3718 [inline]
 __do_sys_io_uring_setup io_uring/io_uring.c:3752 [inline]
 __se_sys_io_uring_setup+0x3f0/0x410 io_uring/io_uring.c:3743
 __ia32_sys_io_uring_setup+0x76/0xb0 io_uring/io_uring.c:3743
 ia32_sys_call+0x2c57/0x4340 arch/x86/include/generated/asm/syscalls_32.h:426
 do_syscall_32_irqs_on arch/x86/entry/syscall_32.c:83 [inline]
 __do_fast_syscall_32+0x15a/0x330 arch/x86/entry/syscall_32.c:307
 do_fast_syscall_32+0x38/0x80 arch/x86/entry/syscall_32.c:332
 do_SYSENTER_32+0x1f/0x30 arch/x86/entry/syscall_32.c:370
 entry_SYSENTER_compat_after_hwframe+0x84/0x8e

Uninit was created at:

 __alloc_frozen_pages_noprof+0x421/0xab0 mm/page_alloc.c:5233
 alloc_pages_mpol+0x328/0x860 mm/mempolicy.c:2486
 folio_alloc_mpol_noprof+0x56/0x1d0 mm/mempolicy.c:2505
 shmem_alloc_folio mm/shmem.c:1890 [inline]
 shmem_alloc_and_add_folio+0xc56/0x1bd0 mm/shmem.c:1932
 shmem_get_folio_gfp+0xad3/0x1fc0 mm/shmem.c:2556
 shmem_get_folio mm/shmem.c:2662 [inline]
 shmem_symlink+0x562/0xad0 mm/shmem.c:4129
 vfs_symlink+0x42f/0x4c0 fs/namei.c:5514
 do_symlinkat+0x2ae/0xbb0 fs/namei.c:5541
 __do_sys_symlinkat fs/namei.c:5562 [inline]
 __se_sys_symlinkat fs/namei.c:5559 [inline]
 __ia32_sys_symlinkat+0xf5/0x180 fs/namei.c:5559
 ia32_sys_call+0x385e/0x4340 arch/x86/include/generated/asm/syscalls_32.h:305
 do_syscall_32_irqs_on arch/x86/entry/syscall_32.c:83 [inline]
 __do_fast_syscall_32+0x15a/0x330 arch/x86/entry/syscall_32.c:307
 do_fast_syscall_32+0x38/0x80 arch/x86/entry/syscall_32.c:332
 do_SYSENTER_32+0x1f/0x30 arch/x86/entry/syscall_32.c:370
 entry_SYSENTER_compat_after_hwframe+0x84/0x8e

CPU: 0 UID: 0 PID: 7862 Comm: syz.2.517 Tainted: G             L      syzkaller #0 PREEMPT(none) 
Tainted: [L]=SOFTLOCKUP
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/2025
=====================================================

---
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 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
Quoted 12 lines

Uninit was created at:

 __alloc_frozen_pages_noprof+0x421/0xab0 mm/page_alloc.c:5233
 alloc_pages_mpol+0x328/0x860 mm/mempolicy.c:2486
 folio_alloc_mpol_noprof+0x56/0x1d0 mm/mempolicy.c:2505
 shmem_alloc_folio mm/shmem.c:1890 [inline]
 shmem_alloc_and_add_folio+0xc56/0x1bd0 mm/shmem.c:1932
 shmem_get_folio_gfp+0xad3/0x1fc0 mm/shmem.c:2556
 shmem_get_folio mm/shmem.c:2662 [inline]
 shmem_symlink+0x562/0xad0 mm/shmem.c:4129
 vfs_symlink+0x42f/0x4c0 fs/namei.c:5514
 do_symlinkat+0x2ae/0xbb0 fs/namei.c:5541

+Hugh and Baolin.

This happens in the shmem symlink path, where newly allocated folios are not cleared for some reason. As a result, is_folio_zero_filled() ends up reading uninitialized data.

Clearing newly allocated folios in shmem_get_folio_gfp() would fix the issue, but it may not be the proper solution. We will need Hugh and Baolin’s guidance to recommend an appropriate fix.

Quoted 6 lines
 __do_sys_symlinkat fs/namei.c:5562 [inline]
 __se_sys_symlinkat fs/namei.c:5559 [inline]
 __ia32_sys_symlinkat+0xf5/0x180 fs/namei.c:5559
 ia32_sys_call+0x385e/0x4340 arch/x86/include/generated/asm/syscalls_32.h:305
 do_syscall_32_irqs_on arch/x86/entry/syscall_32.c:83 [inline]
 __do_fast_syscall_32+0x15a/0x330 arch/x86/entry/syscall_32.c:307
Quoted 8 lines
 do_fast_syscall_32+0x38/0x80 arch/x86/entry/syscall_32.c:332
 do_SYSENTER_32+0x1f/0x30 arch/x86/entry/syscall_32.c:370
 entry_SYSENTER_compat_after_hwframe+0x84/0x8e

CPU: 0 UID: 0 PID: 7862 Comm: syz.2.517 Tainted: G             L      syzkaller #0 PREEMPT(none)
Tainted: [L]=SOFTLOCKUP
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/2025
=====================================================

Thanks
Barry

#2 lore raw
Quoted 13 lines · Barry Song
Quoted 12 lines

Uninit was created at:

 __alloc_frozen_pages_noprof+0x421/0xab0 mm/page_alloc.c:5233
 alloc_pages_mpol+0x328/0x860 mm/mempolicy.c:2486
 folio_alloc_mpol_noprof+0x56/0x1d0 mm/mempolicy.c:2505
 shmem_alloc_folio mm/shmem.c:1890 [inline]
 shmem_alloc_and_add_folio+0xc56/0x1bd0 mm/shmem.c:1932
 shmem_get_folio_gfp+0xad3/0x1fc0 mm/shmem.c:2556
 shmem_get_folio mm/shmem.c:2662 [inline]
 shmem_symlink+0x562/0xad0 mm/shmem.c:4129
 vfs_symlink+0x42f/0x4c0 fs/namei.c:5514
 do_symlinkat+0x2ae/0xbb0 fs/namei.c:5541
Quoted 6 lines

+Hugh and Baolin.

This happens in the shmem symlink path, where newly allocated folios are not cleared for some reason. As a result, is_folio_zero_filled() ends up reading uninitialized data.

I'm not Hugh nor Baolin, but I would guess that letting is_folio_zero_filled() skip/disable KMSAN would also work. Since all we want is to skip writeout if the folio is zero, whether it is incidentally zero, or not, does not really matter, I think.

Signature · 1 line
Pedro
#3 lore raw
Quoted 22 lines · Pedro Falcato
Quoted 13 lines · Barry Song
Quoted 12 lines

Uninit was created at:

 __alloc_frozen_pages_noprof+0x421/0xab0 mm/page_alloc.c:5233
 alloc_pages_mpol+0x328/0x860 mm/mempolicy.c:2486
 folio_alloc_mpol_noprof+0x56/0x1d0 mm/mempolicy.c:2505
 shmem_alloc_folio mm/shmem.c:1890 [inline]
 shmem_alloc_and_add_folio+0xc56/0x1bd0 mm/shmem.c:1932
 shmem_get_folio_gfp+0xad3/0x1fc0 mm/shmem.c:2556
 shmem_get_folio mm/shmem.c:2662 [inline]
 shmem_symlink+0x562/0xad0 mm/shmem.c:4129
 vfs_symlink+0x42f/0x4c0 fs/namei.c:5514
 do_symlinkat+0x2ae/0xbb0 fs/namei.c:5541
Quoted 6 lines

+Hugh and Baolin.

This happens in the shmem symlink path, where newly allocated folios are not cleared for some reason. As a result, is_folio_zero_filled() ends up reading uninitialized data.

Quoted 4 lines

I'm not Hugh nor Baolin, but I would guess that letting is_folio_zero_filled() skip/disable KMSAN would also work. Since all we want is to skip writeout if the folio is zero, whether it is incidentally zero, or not, does not really matter, I think.

Hi Pedro, thanks! You’re always welcome to chime in.

You are probably right. However, I still prefer the remaining data to be zeroed, as it may be more compression-friendly.

Random data could potentially lead to larger compressed output, whereas a large area of zeros would likely result in much smaller compressed data.

Not quite sure if the below can fix the issue:

mm/shmem.c +1 -0
index ec6c01378e9d..0ca2d4bffdb4 100644
@@ -4131,6 +4131,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,
 			goto out_remove_offset;
 		inode->i_op = &shmem_symlink_inode_operations;
 		memcpy(folio_address(folio), symname, len);
+		memset(folio_address(folio) + len, 0, folio_size(folio) - len);
 		folio_mark_uptodate(folio);
 		folio_mark_dirty(folio);
 		folio_unlock(folio);
Quoted 3 lines

--
Pedro

Thanks
Barry

reviewer
#4 lore raw
Quoted 16 lines · Barry Song
Quoted 15 lines · Pedro Falcato
Quoted 13 lines · Barry Song
Quoted 12 lines

Uninit was created at:

  __alloc_frozen_pages_noprof+0x421/0xab0 mm/page_alloc.c:5233
  alloc_pages_mpol+0x328/0x860 mm/mempolicy.c:2486
  folio_alloc_mpol_noprof+0x56/0x1d0 mm/mempolicy.c:2505
  shmem_alloc_folio mm/shmem.c:1890 [inline]
  shmem_alloc_and_add_folio+0xc56/0x1bd0 mm/shmem.c:1932
  shmem_get_folio_gfp+0xad3/0x1fc0 mm/shmem.c:2556
  shmem_get_folio mm/shmem.c:2662 [inline]
  shmem_symlink+0x562/0xad0 mm/shmem.c:4129
  vfs_symlink+0x42f/0x4c0 fs/namei.c:5514
  do_symlinkat+0x2ae/0xbb0 fs/namei.c:5541
Quoted 1 line
Quoted 1 line
Quoted 1 line

+Hugh and Baolin.

Thanks for CCing me.

Quoted 11 lines
Quoted 10 lines
Quoted 5 lines

This happens in the shmem symlink path, where newly allocated folios are not cleared for some reason. As a result, is_folio_zero_filled() ends up reading uninitialized data.

I'm not Hugh nor Baolin, but I would guess that letting is_folio_zero_filled() skip/disable KMSAN would also work. Since all we want is to skip writeout if the folio is zero, whether it is incidentally zero, or not, does not really matter, I think.

Quoted 8 lines

Hi Pedro, thanks! You’re always welcome to chime in.

You are probably right. However, I still prefer the remaining data to be zeroed, as it may be more compression-friendly.

Random data could potentially lead to larger compressed output, whereas a large area of zeros would likely result in much smaller compressed data.

Thanks Pedro and Barry. I remember Hugh raised a similar issue before (See [1], but I did not investigate further:(). I agree with Hugh's point that the uninitialized parts should be zeroed before going the outside world.

[1] https://lore.kernel.org/all/[email protected]/

Quoted 7 lines

Not quite sure if the below can fix the issue:

mm/shmem.c +0 -0
index ec6c01378e9d..0ca2d4bffdb4 100644

mm/shmem.c static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, · line 4137

Quoted 7 lines
mm/shmem.c +1 -0
@@ -4131,6 +4131,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,
  			goto out_remove_offset;
  		inode->i_op = &shmem_symlink_inode_operations;
  		memcpy(folio_address(folio), symname, len);
+		memset(folio_address(folio) + len, 0, folio_size(folio) - len);
  		folio_mark_uptodate(folio);
  		folio_mark_dirty(folio);
  		folio_unlock(folio);

That looks reasonable to me, though I prefer to use the more readable helper: folio_zero_range(). Barry, could you send out a formal patch? Thanks.

#5 lore raw
Quoted 54 lines · Baolin Wang
Quoted 16 lines · Barry Song
Quoted 15 lines · Pedro Falcato
Quoted 13 lines · Barry Song
Quoted 12 lines

Uninit was created at:

  __alloc_frozen_pages_noprof+0x421/0xab0 mm/page_alloc.c:5233
  alloc_pages_mpol+0x328/0x860 mm/mempolicy.c:2486
  folio_alloc_mpol_noprof+0x56/0x1d0 mm/mempolicy.c:2505
  shmem_alloc_folio mm/shmem.c:1890 [inline]
  shmem_alloc_and_add_folio+0xc56/0x1bd0 mm/shmem.c:1932
  shmem_get_folio_gfp+0xad3/0x1fc0 mm/shmem.c:2556
  shmem_get_folio mm/shmem.c:2662 [inline]
  shmem_symlink+0x562/0xad0 mm/shmem.c:4129
  vfs_symlink+0x42f/0x4c0 fs/namei.c:5514
  do_symlinkat+0x2ae/0xbb0 fs/namei.c:5541
Quoted 1 line
Quoted 1 line
Quoted 1 line

+Hugh and Baolin.

Thanks for CCing me.

Quoted 11 lines
Quoted 10 lines
Quoted 5 lines

This happens in the shmem symlink path, where newly allocated folios are not cleared for some reason. As a result, is_folio_zero_filled() ends up reading uninitialized data.

I'm not Hugh nor Baolin, but I would guess that letting is_folio_zero_filled() skip/disable KMSAN would also work. Since all we want is to skip writeout if the folio is zero, whether it is incidentally zero, or not, does not really matter, I think.

Quoted 8 lines

Hi Pedro, thanks! You’re always welcome to chime in.

You are probably right. However, I still prefer the remaining data to be zeroed, as it may be more compression-friendly.

Random data could potentially lead to larger compressed output, whereas a large area of zeros would likely result in much smaller compressed data.

Thanks Pedro and Barry. I remember Hugh raised a similar issue before (See [1], but I did not investigate further:(). I agree with Hugh's point that the uninitialized parts should be zeroed before going the outside world.

[1]
https://lore.kernel.org/all/[email protected]/

Quoted 2 lines

Not quite sure if the below can fix the issue:

Quoted 16 lines

mm/shmem.c static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, · line 4137

Quoted 12 lines
mm/shmem.c +1 -0
index ec6c01378e9d..0ca2d4bffdb4 100644
@@ -4131,6 +4131,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,
                       goto out_remove_offset;
               inode->i_op = &shmem_symlink_inode_operations;
               memcpy(folio_address(folio), symname, len);
+             memset(folio_address(folio) + len, 0, folio_size(folio) - len);
               folio_mark_uptodate(folio);
               folio_mark_dirty(folio);
               folio_unlock(folio);

That looks reasonable to me, though I prefer to use the more readable
helper: folio_zero_range(). Barry, could you send out a formal patch? Thanks.

Thanks, Baolin. Let me request a bot test first.

#syz test

mm/shmem.c +1 -0
index ec6c01378e9d..835900a08f51 100644
@@ -4131,6 +4131,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,
 			goto out_remove_offset;
 		inode->i_op = &shmem_symlink_inode_operations;
 		memcpy(folio_address(folio), symname, len);
+		folio_zero_range(folio, len, folio_size(folio) - len);
 		folio_mark_uptodate(folio);
 		folio_mark_dirty(folio);
 		folio_unlock(folio);
Signature · 1 line
2.48.1
author syzbot
#6 lore raw
This crash does not have a reproducer. I cannot test it.
Quoted 72 lines · Baolin Wang
Quoted 54 lines · Barry Song
Quoted 16 lines · Pedro Falcato
Quoted 15 lines · Barry Song
Quoted 13 lines
Quoted 12 lines

Uninit was created at:

  __alloc_frozen_pages_noprof+0x421/0xab0 mm/page_alloc.c:5233
  alloc_pages_mpol+0x328/0x860 mm/mempolicy.c:2486
  folio_alloc_mpol_noprof+0x56/0x1d0 mm/mempolicy.c:2505
  shmem_alloc_folio mm/shmem.c:1890 [inline]
  shmem_alloc_and_add_folio+0xc56/0x1bd0 mm/shmem.c:1932
  shmem_get_folio_gfp+0xad3/0x1fc0 mm/shmem.c:2556
  shmem_get_folio mm/shmem.c:2662 [inline]
  shmem_symlink+0x562/0xad0 mm/shmem.c:4129
  vfs_symlink+0x42f/0x4c0 fs/namei.c:5514
  do_symlinkat+0x2ae/0xbb0 fs/namei.c:5541
Quoted 1 line
Quoted 1 line
Quoted 1 line

+Hugh and Baolin.

Thanks for CCing me.

Quoted 11 lines
Quoted 10 lines
Quoted 5 lines

This happens in the shmem symlink path, where newly allocated folios are not cleared for some reason. As a result, is_folio_zero_filled() ends up reading uninitialized data.

I'm not Hugh nor Baolin, but I would guess that letting is_folio_zero_filled() skip/disable KMSAN would also work. Since all we want is to skip writeout if the folio is zero, whether it is incidentally zero, or not, does not really matter, I think.

Quoted 8 lines

Hi Pedro, thanks! You’re always welcome to chime in.

You are probably right. However, I still prefer the remaining data to be zeroed, as it may be more compression-friendly.

Random data could potentially lead to larger compressed output, whereas a large area of zeros would likely result in much smaller compressed data.

Thanks Pedro and Barry. I remember Hugh raised a similar issue before (See [1], but I did not investigate further:(). I agree with Hugh's point that the uninitialized parts should be zeroed before going the outside world.

[1]
https://lore.kernel.org/all/[email protected]/

Quoted 2 lines

Not quite sure if the below can fix the issue:

Quoted 16 lines

mm/shmem.c static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, · line 4137

Quoted 12 lines
mm/shmem.c +1 -0
index ec6c01378e9d..0ca2d4bffdb4 100644
@@ -4131,6 +4131,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,
                       goto out_remove_offset;
               inode->i_op = &shmem_symlink_inode_operations;
               memcpy(folio_address(folio), symname, len);
+             memset(folio_address(folio) + len, 0, folio_size(folio) - len);
               folio_mark_uptodate(folio);
               folio_mark_dirty(folio);
               folio_unlock(folio);

That looks reasonable to me, though I prefer to use the more readable
helper: folio_zero_range(). Barry, could you send out a formal patch? Thanks.

Quoted 3 lines

Thanks, Baolin. Let me request a bot test first.

#syz test

This crash does not have a reproducer. I cannot test it.

Quoted 15 lines
mm/shmem.c +1 -0
index ec6c01378e9d..835900a08f51 100644
@@ -4131,6 +4131,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,
 			goto out_remove_offset;
 		inode->i_op = &shmem_symlink_inode_operations;
 		memcpy(folio_address(folio), symname, len);
+		folio_zero_range(folio, len, folio_size(folio) - len);
 		folio_mark_uptodate(folio);
 		folio_mark_dirty(folio);
 		folio_unlock(folio);
Signature · 1 line
2.48.1
#7 lore raw
In reply to Baolin Wang
Quoted 44 lines · Baolin Wang
Quoted 16 lines · Barry Song
Quoted 15 lines · Pedro Falcato
Quoted 13 lines · Barry Song
Quoted 12 lines

Uninit was created at:

  __alloc_frozen_pages_noprof+0x421/0xab0 mm/page_alloc.c:5233
  alloc_pages_mpol+0x328/0x860 mm/mempolicy.c:2486
  folio_alloc_mpol_noprof+0x56/0x1d0 mm/mempolicy.c:2505
  shmem_alloc_folio mm/shmem.c:1890 [inline]
  shmem_alloc_and_add_folio+0xc56/0x1bd0 mm/shmem.c:1932
  shmem_get_folio_gfp+0xad3/0x1fc0 mm/shmem.c:2556
  shmem_get_folio mm/shmem.c:2662 [inline]
  shmem_symlink+0x562/0xad0 mm/shmem.c:4129
  vfs_symlink+0x42f/0x4c0 fs/namei.c:5514
  do_symlinkat+0x2ae/0xbb0 fs/namei.c:5541
Quoted 1 line
Quoted 1 line
Quoted 1 line

+Hugh and Baolin.

Thanks for CCing me.

Quoted 11 lines
Quoted 10 lines
Quoted 5 lines

This happens in the shmem symlink path, where newly allocated folios are not cleared for some reason. As a result, is_folio_zero_filled() ends up reading uninitialized data.

I'm not Hugh nor Baolin, but I would guess that letting is_folio_zero_filled() skip/disable KMSAN would also work. Since all we want is to skip writeout if the folio is zero, whether it is incidentally zero, or not, does not really matter, I think.

Quoted 8 lines

Hi Pedro, thanks! You’re always welcome to chime in.

You are probably right. However, I still prefer the remaining data to be zeroed, as it may be more compression-friendly.

Random data could potentially lead to larger compressed output, whereas a large area of zeros would likely result in much smaller compressed data.

Quoted 4 lines

This would be an unfortunate way to fix it. The vast majority of symlinks are short, and we'll never access past the \0 in normal operation, so we'll be dirtying a lot of cachelines essentially to (1) shut up an automated tool and (2) optimise a corner case.

Won't the uninit data end up in a swap file if it's not 0's? If yes, isn't leaking crypto keys to a swap file a problem?

Quoted 31 lines

Thanks Pedro and Barry. I remember Hugh raised a similar issue before (See [1], but I did not investigate further:(). I agree with Hugh's point that the uninitialized parts should be zeroed before going the outside world.

[1]
https://lore.kernel.org/all/[email protected]/

Quoted 7 lines

Not quite sure if the below can fix the issue:

mm/shmem.c +0 -0
index ec6c01378e9d..0ca2d4bffdb4 100644

mm/shmem.c static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, · line 4137

Quoted 7 lines
mm/shmem.c +1 -0
@@ -4131,6 +4131,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,
                      goto out_remove_offset;
              inode->i_op = &shmem_symlink_inode_operations;
              memcpy(folio_address(folio), symname, len);
+             memset(folio_address(folio) + len, 0, folio_size(folio) - len);
              folio_mark_uptodate(folio);
              folio_mark_dirty(folio);
              folio_unlock(folio);

That looks reasonable to me, though I prefer to use the more readable
helper: folio_zero_range(). Barry, could you send out a formal patch? Thanks.

--
You received this message because you are subscribed to the Google Groups "syzkaller-bugs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/syzkaller-bugs/9bbc1962-5f6f-4e3c-a672-d80565aa5157%40linux.alibaba.com.