From: Barry Song <21cnbao@gmail.com>
To: akpm@linux-foundation.org, linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, Barry Song <baohua@kernel.org>,
Hugh Dickins <hughd@google.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
syzbot+178fff6149127421c2cc@syzkaller.appspotmail.com
Subject: [PATCH] mm/shmem: fix uninitialized folio in shmem_symlink
Date: Wed, 24 Dec 2025 22:40:27 +1300 [thread overview]
Message-ID: <20251224094027.65842-1-21cnbao@gmail.com> (raw)
From: Barry Song <baohua@kernel.org>
Uninitialized folio allocated in shmem_symlink() may be accessed
during swap-out, causing KMSAN BUG:
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]
This patch clears the remaining part to zero for the portion not
covered by memcpy from symname.
Cc: Hugh Dickins <hughd@google.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Reported-by: syzbot+178fff6149127421c2cc@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/lkml/6949370f.050a0220.1b4e0c.0038.GAE@google.com/
Signed-off-by: Barry Song <baohua@kernel.org>
---
mm/shmem.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/mm/shmem.c b/mm/shmem.c
index ec6c01378e9d..835900a08f51 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -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);
--
2.43.0
next reply other threads:[~2025-12-24 9:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-24 9:40 Barry Song [this message]
2025-12-24 17:01 ` Matthew Wilcox
2025-12-25 4:04 ` Barry Song
2025-12-25 10:08 ` Baolin Wang
2025-12-28 4:29 ` Matthew Wilcox
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=20251224094027.65842-1-21cnbao@gmail.com \
--to=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=syzbot+178fff6149127421c2cc@syzkaller.appspotmail.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