From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 768061367 for ; Wed, 24 Dec 2025 17:01:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766595681; cv=none; b=JLwDsz1lvYi1+XhJjHaHswDrXqv9B+7pZb/vZcAigh8XYXXJiGMjGsXcFnFGfR6Mzt/D3hcILjqeCSV2nkmO49iPqqlEeSLq4lbQPq3Mb/aUJIxqW62eOaQFhgk1uXspeXQaFuAaBYOynKjwT0l9QeRey59AFz5vaVhyGIi5L0o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766595681; c=relaxed/simple; bh=Iyut3XZLrWrqvCjlfWg6XH9gg6fhoR8Qtlr7aCQ9b3k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FNHW6TmgNoxyS2RAVx5xiJ/zAeCOB6z9Z/0CFZMeNmSJjwnf6C4nUH180kElY2i07o4p1kdceYIqX2v5EyrqYOoagcDprQsqwX/rkG3avzV7yVlFx3M9yvZkFllyJtVT+ge1jmHx0KZBFf82sX+p9IPlPo3rrHqqja5qlYeX6EE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=lrXuPb8H; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="lrXuPb8H" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=x57WztIccI1mjFn8capVH7vlO7RY9YeTP7R0mFePSC8=; b=lrXuPb8HSlgIrtEZ26fR9AbTZ8 bBUQVIXX4JANJhuuBVC8a2cQrlyBqB6eHKQJGr8Zu6eV3Mh7PFw+92anJ6nc/E6dK5XiWRuYrRyRn LM8fjE8b3aE+iZDC1Vzx+5MLqOPQ7Oh1/gMRLPG7KTY08rMKX80QE4Igq3IJmqCF72Pg30I2U2Gjr FQEp41fqvFrT/H6q88s75creOKiVvAzLlLS8Wy1OzGu0k7FTO4wG3vWOfMYFYem/oKzW6v2o2f26T MPH9WTFQVaRje6QdWv/dXqXKAd3GW6POtDbgTtODmQLoTefBk+3dsUhLHeCazsQxVg45qhkgQfdpr 6ia3K73g==; Received: from willy by casper.infradead.org with local (Exim 4.98.2 #2 (Red Hat Linux)) id 1vYSEZ-0000000EUaO-354W; Wed, 24 Dec 2025 17:01:11 +0000 Date: Wed, 24 Dec 2025 17:01:11 +0000 From: Matthew Wilcox To: Barry Song <21cnbao@gmail.com> Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Barry Song , Hugh Dickins , Baolin Wang , syzbot+178fff6149127421c2cc@syzkaller.appspotmail.com Subject: Re: [PATCH] mm/shmem: fix uninitialized folio in shmem_symlink Message-ID: References: <20251224094027.65842-1-21cnbao@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251224094027.65842-1-21cnbao@gmail.com> On Wed, Dec 24, 2025 at 10:40:27PM +1300, Barry Song wrote: > From: Barry Song > > Uninitialized folio allocated in shmem_symlink() may be accessed > during swap-out, causing KMSAN BUG: 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. How about this instead which delays zeroing to swapout? diff --git a/mm/shmem.c b/mm/shmem.c index ec6c01378e9d..f3b3be1b50fe 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1636,6 +1636,13 @@ int shmem_writeout(struct folio *folio, struct swap_iocb **plug, folio_mark_uptodate(folio); } + /* Zero out symlink tails to help with compression */ + if (folio_test_owner_2(folio)) { + struct inode *inode = folio->mapping->host; + folio_zero_segment(folio, inode->i_size, folio_size(folio)); + folio_clear_owner_2(folio); + } + if (!folio_alloc_swap(folio)) { bool first_swapped = shmem_recalc_inode(inode, 0, nr_pages); int error; @@ -4133,6 +4140,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, memcpy(folio_address(folio), symname, len); folio_mark_uptodate(folio); folio_mark_dirty(folio); + folio_set_owner_2(folio); folio_unlock(folio); folio_put(folio); }