From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6B2A925DAFD; Tue, 11 Mar 2025 15:12:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741705961; cv=none; b=hLcXh6LDBcmRpvfs+Lndnsy+pCfjX3lv+NWSLWLPXdgb4BquNPr7Qfa1W67/5oDTvI18HdCa7OMq/nOrwrket1nysysuzeXMLvzV7bIAQJl/3My2XzAY7wh3UysYhyS0m19EekmnH6gTATY8BtID9LvRSyXwSFftBPR+O4RiCw4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741705961; c=relaxed/simple; bh=83PZAEAKi5qbRFDU4ynLXojYVaL+QgSd/OoVjRT8rPs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GY98Zol+MzM+AtXGQE9XG0/LbBEfeRMSoSs8lKCrahOvp9Z1S2quyA3yJ9iGTa0RNpoaR1GUs9UXp53/eNIlpC1S26VLyoIgaddr0MLFyGY7ZIZhx/f6jQl9/JGdYQhganrp92IytBcTGswGqRa2DxClX2H3Pcvnlbf6NbQFHhA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=kqZh1zXa; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="kqZh1zXa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E79D0C4CEE9; Tue, 11 Mar 2025 15:12:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1741705961; bh=83PZAEAKi5qbRFDU4ynLXojYVaL+QgSd/OoVjRT8rPs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kqZh1zXaZph2po0J2KpLb4skx1mSj7zvpczMbiiSf1562XsnpTeOPhGcL0eDDycKM rJiYm5wVHUAB6VhTORNoMzK40VvuebgBRrFWR59UjWkJY3yALzqI/DkW6BcBGaJamD GsYaHSrumh2apcDdx3dOWpdN6jk2gDgYL9X1+VpY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Andrew Morton , Ryusuke Konishi Subject: [PATCH 5.4 215/328] nilfs2: protect access to buffers with no active references Date: Tue, 11 Mar 2025 15:59:45 +0100 Message-ID: <20250311145723.448656334@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250311145714.865727435@linuxfoundation.org> References: <20250311145714.865727435@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ryusuke Konishi commit 367a9bffabe08c04f6d725032cce3d891b2b9e1a upstream. nilfs_lookup_dirty_data_buffers(), which iterates through the buffers attached to dirty data folios/pages, accesses the attached buffers without locking the folios/pages. For data cache, nilfs_clear_folio_dirty() may be called asynchronously when the file system degenerates to read only, so nilfs_lookup_dirty_data_buffers() still has the potential to cause use after free issues when buffers lose the protection of their dirty state midway due to this asynchronous clearing and are unintentionally freed by try_to_free_buffers(). Eliminate this race issue by adjusting the lock section in this function. [konishi.ryusuke@gmail.com: adjusted for page/folio conversion] Link: https://lkml.kernel.org/r/20250107200202.6432-3-konishi.ryusuke@gmail.com Signed-off-by: Ryusuke Konishi Fixes: 8c26c4e2694a ("nilfs2: fix issue with flush kernel thread after remount in RO mode because of driver's internal error or metadata corruption") Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- fs/nilfs2/segment.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/fs/nilfs2/segment.c +++ b/fs/nilfs2/segment.c @@ -732,7 +732,6 @@ static size_t nilfs_lookup_dirty_data_bu } if (!page_has_buffers(page)) create_empty_buffers(page, i_blocksize(inode), 0); - unlock_page(page); bh = head = page_buffers(page); do { @@ -742,11 +741,14 @@ static size_t nilfs_lookup_dirty_data_bu list_add_tail(&bh->b_assoc_buffers, listp); ndirties++; if (unlikely(ndirties >= nlimit)) { + unlock_page(page); pagevec_release(&pvec); cond_resched(); return ndirties; } } while (bh = bh->b_this_page, bh != head); + + unlock_page(page); } pagevec_release(&pvec); cond_resched();