From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 00018606A322 for ; Thu, 3 Dec 2026 04:19:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aroP7goq Received: by kanga.kvack.org (Postfix) id DFE896B05B1; Wed, 2 Dec 2026 23:19:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DD5076B05B2; Wed, 2 Dec 2026 23:19:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D129A6B05B3; Wed, 2 Dec 2026 23:19:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A9E7C6B05B1 for ; Wed, 2 Dec 2026 23:19:24 -0500 (EST) Received: from smtpin09.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1B9DFC05C5 for ; Thu, 3 Dec 2026 04:19:24 +0000 (UTC) X-FDA: 85501367448.09.9FD05ED Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf25.hostedemail.com (Postfix) with ESMTP id 757DBA000A for ; Thu, 3 Dec 2026 04:19:22 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=aroP7goq; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf25.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796271562; b=oVyoeaoPF/cRG36UV5GgNvFePe3Mqn+xZzUfuLRLoYrBuN4xUMPKpcsvvmtXjx0+rquXfR smVBODKDfoAi549/Rp5LShikEPauMnh5U5vz3Zd2Dms3D0h5N/gnqDjyssqLsl1+uaZFGV 2nwiJ3gQcsqi/cP7A+kTqWtxWj3qXgQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796271562; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=h4Er/zGeABfIV9oUGtJN/iXm7jUi/DSBcNTyxHzWAxE=; b=FLeEQzSFTueSyNaBmu/TxYvyucgJEQ8ZejVasnuyO3jRP/XapMxHkFq1mPOzEuWJugd1R/ ZVL0DxREGF5cnPKLbilkhIDX/kBk0QTBH2EFIhjE7oaZIQPImAJaSpFqHt8p3CeRhf0eKX fBls1VtLx+Z/aRNODyHXIb7Syg/FAw8= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=aroP7goq; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf25.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id AE240601DC; Thu, 3 Dec 2026 04:19:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CFD721F000C1; Thu, 3 Dec 2026 04:19:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796271561; bh=h4Er/zGeABfIV9oUGtJN/iXm7jUi/DSBcNTyxHzWAxE=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=aroP7goqwyjhOefbz4HwnEQX5fLdynpiPUU1JrEdbVl3RlCbhFZ2VX8uBbQVj581t YuTRFteLRUgnN/MlWCzTBIdCqS5Ipu83t+H2mirsa0Uwz8Q/qgjSGWYZYz62eG8VJ1 lHehCti+P9nDI1yIb4KhJ7Nrc5dwYZSXeZmuqRMLjqLJAUhQFe4GR0Bq8NmmC+bZV7 IEbQPJFn+d2ntrvbSRMFLqOo4WVUzuj1e4oXTYlOTBKG/8qu9CW8pqaFxSvQV85Ylc 1UerAkim1qoS4Mzbl5WVEQEcUO3xISYTRB/uGc6GfnStMSB06InkquwS2jfBIFud13 mwDoSUtRXYxkA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] btrfs: re-attach folio private when a released folio gets dirtied Reply-To: sashiko-reviews@lists.linux.dev To: "Brahmajit Das" , dsterba@suse.com Cc: quwenruo.btrfs@gmx.com, clm@fb.com, mason@kernel.org, david@kernel.org, jgg@ziepe.ca, jhubbard@nvidia.com, peterx@redhat.com, linux-mm@kvack.org, syzkaller-bugs@googlegroups.com, "Brahmajit Das" , syzbot+d6f123d4060990f0f3ff@syzkaller.appspotmail.com, dsterba@suse.cz In-Reply-To: <20261202041853.4184717-1-listout@listout.xyz> References: <20261202041853.4184717-1-listout@listout.xyz> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 04:19:20 +0000 X-Stat-Signature: um8c383r45bety6kwy4cyjmsp7j39r83 X-Rspamd-Queue-Id: 757DBA000A X-Rspamd-Server: rspam10 X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Rspam-User: X-HE-Tag: 1796271562-489963 X-HE-Meta: U2FsdGVkX1+BsHS4+ar7WdS71hBGSQZ83/PqLvpBl9CqJYiopFxFXdrr3kd5Tex4Y+86FnOZR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xndCIbFhW0chlq9cDvLN8MZ19P62MJOTxlOjQsH75vzMR4sqhO2P+uBqy15is0GAHAK538wM+9TtXJqyDjo3+fXWBT3CSxfP0ty3jAfMyRoVmIhlJgSswukDG7+eJVEq4BGOWCbUIQFy+L3LAk1pGsQL6IpKJOBP6/Hp/wYWVj0J/ZuvZ6ss3OxvwfAha8T1/TjamxesuJ28mq9y/XUOk6Zdy9YqHYvf0NUNMRqi7e5owKnVNe4ZgUw2RhoicODtBspM/JbulNq3Ou7rUP9tgbzsxHNy+PycQfbLXZMoAmeNOt1BT/CJXSGy7xRvW+TWwwobiaveNS0h8XF9vIMVq+kiPbl9wvnl8SaOMznDzW8P60DiFCH+dyBvN+e6nO27xWixCFJycUvwWYyIfnZwPzb/SKBXtS6KfGNGY/YOaKBTkyTewR6QWLU26jsIeqawc4p8k7JVG2go83Yea7qCqDKIkOb1YYYpyrfON8ho1a15wdNNJ20CvLPHv7EWhl0uiKa1l8AT+MwiBAGnYz22aK1B4I8UB/BvCBf9CnDw9mgCU1ZarVFTyqt0Lt39VGXWd3yIJHHhhu16yD4yKqqm1PQRFax2Hhc/xhVkbH3Cp7h/YZEVM7Jg+KJTlFxCtVggf0HVDGDHdWlzna+2hh/uh2pFfHTGtX+OznKEOk6LKNjV2ztAQ7r9LcrPC1OH/ej0hm+2p+xtZdeVjAMSBm2ErRvJy3nPQHxwKinhJRIBM4XbQXHbjkn8+oAf2KMKuoSovdzT9N9yCCl9PJp2O2XTOIdZqPSj/xscuGR6tbqa5121TemhQJ/zwwm6h QIOzAUR7 YN/5q3/jfoq7TrCU7MUk0CbMJfZixpsX Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] btrfs: NULL pointer dereference in extent_writepage() when GFP_NOWAIT fails - [Medium] btrfs: subpage uptodate bitmap not synced outside btrfs_data_dirty_folio() -- commit dc003714a24f865774ee08b412ccb7fac2eadf3d Author: Brahmajit Das btrfs: re-attach folio private when a released folio gets dirtied This commit re-attaches folio::private using GFP_NOWAIT in btrfs_data_dirty_folio() and in the beyond-EOF branch of extent_writepage() when a cached folio that lost its private state is dirtied. > diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c > index 95c9530554d02..f30f334a099e9 100644 > --- a/fs/btrfs/inode.c > +++ b/fs/btrfs/inode.c > @@ -10739,7 +10739,27 @@ static bool btrfs_data_dirty_folio(struct addres= s_space *mapping, > round_up(i_size_read(&inode->vfs_inode), > fs_info->sectorsize)); > =20 > - if (range_end > page_start) > + /* > + * The folio may have lost its private while it stayed in the page > + * cache, e.g. btrfs_release_folio() from a partial invalidation or > + * from a failed large folio split, while it was pinned by GUP. When > + * the pin is released, the folio is dirtied through here, so > + * re-attach the private, as every dirty folio is expected to have it. > + * > + * We may not block here, thus GFP_NOWAIT. If that fails, writeback > + * attaches it later for folios beyond EOF. > + * > + * The new folio state has empty bitmaps. The folio has not been > + * invalidated, only released, thus can still be uptodate, so sync > + * the uptodate bitmap with the folio flag. > + */ > + if (unlikely(!folio_test_private(folio)) && > + set_folio_extent_mapped_gfp(folio, GFP_NOWAIT | __GFP_NOWARN) =3D= =3D 0 && > + folio_test_uptodate(folio)) > + btrfs_folio_set_uptodate(fs_info, folio, page_start, > + folio_size(folio)); > + > + if (range_end > page_start && folio_test_private(folio)) > btrfs_folio_set_fixup_dirty(fs_info, folio, page_start, > range_end - page_start); > return filemap_dirty_folio(mapping, folio); [Severity: High] Can a GFP_NOWAIT failure here on a subpage or large folio inside or straddling EOF cause a NULL pointer dereference in extent_writepage()? set_folio_extent_mapped_gfp() only allocates when btrfs_is_subpage() is true. If that allocation fails, filemap_dirty_folio() still marks the folio dirty with folio->private =3D=3D NULL. When extent_writepage() runs = on a folio that is not completely beyond EOF, it hits the !folio_test_private() check, sets ret =3D -EUCLEAN, and jumps to done:, which passes the folio to btrfs_folio_end_lock_bitmap(): fs/btrfs/subpage.c:btrfs_folio_end_lock_bitmap() { struct btrfs_folio_state *bfs =3D folio_get_private(folio); ... if (!btrfs_is_subpage(fs_info, folio)) { folio_unlock(folio); return; } if (atomic_read(&bfs->nr_locked) =3D=3D 0) { ... } Because btrfs_is_subpage() is true and bfs is NULL, atomic_read() dereferences NULL. Also, if another path calls set_folio_extent_mapped() before writeback runs, a zeroed btrfs_folio_state is attached without the fixup or dirty bits that btrfs_folio_set_fixup_dirty() skipped. > diff --git a/fs/btrfs/subpage.c b/fs/btrfs/subpage.c > index ebf18efe1ea31..c779bf4771b98 100644 > --- a/fs/btrfs/subpage.c > +++ b/fs/btrfs/subpage.c > @@ -36,7 +36,8 @@ > */ > =20 > int btrfs_attach_folio_state(const struct btrfs_fs_info *fs_info, > - struct folio *folio, enum btrfs_folio_type type) > + struct folio *folio, enum btrfs_folio_type type, > + gfp_t gfp) > { > struct btrfs_folio_state *bfs; > =20 > @@ -59,7 +60,7 @@ int btrfs_attach_folio_state(const struct btrfs_fs_info= *fs_info, > if (type =3D=3D BTRFS_SUBPAGE_DATA && !btrfs_is_subpage(fs_info, folio)) > return 0; > =20 > - bfs =3D btrfs_alloc_folio_state(fs_info, folio_size(folio), type, GFP_N= OFS); > + bfs =3D btrfs_alloc_folio_state(fs_info, folio_size(folio), type, gfp); > if (IS_ERR(bfs)) > return PTR_ERR(bfs); [Severity: Medium] Should the subpage uptodate bitmap be synced with folio_test_uptodate() here in btrfs_attach_folio_state() (when type =3D=3D BTRFS_SUBPAGE_DATA) ra= ther than only in btrfs_data_dirty_folio()? If an uptodate folio loses its private via btrfs_release_folio() and another caller such as btrfs_truncate_block(), prepare_one_folio(), or btrfs_page_mkwrite() calls set_folio_extent_mapped() first, a zeroed btrfs_folio_state is attached while PG_uptodate is still set on the folio. Those paths skip reading the already-uptodate folio and only update their own sub-range (or unlock early if an ordered extent is pending in btrfs_page_mkwrite()), leaving unmodified blocks marked not-uptodate in the subpage bitmap and preventing a later btrfs_data_dirty_folio() from syncing the bitmap because folio_test_private() is already true. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202041853.4184= 717-1-listout@listout.xyz?part=3D1