Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1491896rdb; Sat, 3 Feb 2024 08:17:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFvdbJqh3/Z3gAYbotTPM0cft1fbT+cL/8DuIS6KCrus26NVOxtNMqA55pc3ozOc8Zdgtzd X-Received: by 2002:a17:906:a1d6:b0:a36:3345:be88 with SMTP id bx22-20020a170906a1d600b00a363345be88mr4058067ejb.30.1706977040127; Sat, 03 Feb 2024 08:17:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706977040; cv=pass; d=google.com; s=arc-20160816; b=0UrMASr1GPq76PhFaYq+FCxIRsthed4p+k9r089Hg1CUt9In1y4lFZXjsOBVXCus40 eQCxQc5kTM8Jt2aFEVp5ncm1janrecIU28XjyxNhwg/BYultQeuNiRujiP5ngWGVz7SG Q48lKMS5MV1iFIAt+IMCm8m6vJuGQ1OLq9n7zQJG8YAkJ8tGAxwaQOyYxKla5uqk0n9S kVjaAP5yvEXozrY2KqLBmCT5U7eCMUJKi4sCstPVNjP0oFSwvUjeq4UnZKzXnNaF/WtG aFsoa7UCgsSzhBa0SuZcU1rqPkYysIdzPwIt33Ii8MN5VVXRodvP187/FLgEF69CStHk dCMw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=kkKSBEd57oTuNT42X1XreOYTPrUWtWe7ns5GZwL0900=; fh=sKu0vNCn2H/5ZW7S7cxYviu1PeCv+3KXIdF0+l5kPuM=; b=j3I8IJoFx6lSWdI0fEmQkzgY5eVDZyAhNX1hGG/zGgboo01GAnQ1D32FEcombQ9OUk NR4l/TKvFaAO8TN4t8FjYTkX2qZkagwYCnnvUAPxZlNFvYSgmXeeHVM2N7lYf1DbqLzj iONEUJCh4DEEb/1m+JnviPByLJqadDYrARdI8DWUSHkA08Fm/UU8fLBAV5nZpMtJBQab LmRyWN3YfE0LUB9R2YHcGBuHz3k936egU8ZeB2kQRPHbtAkgSlEN3Dcx2wpVWqeaIyHW /9efludm89lKrd4UOOCg2YkMFX1qfbQRlEXpB2PFfKfsi36BVX13EwLQih9tFwA8Hlgk Y2FA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=S7jV1sBs; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-51178-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51178-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=1; AJvYcCVMZinepTFbSBsJTzmhTq6iE3TKwrZu0v8jltnFVmNyhdU/bRuq4AvGI7Pvc7PpHqtgsSHypT5UMePAwKybo/kQqX7SM1qoRwNL3D3fwQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id m24-20020a17090607d800b00a368b791a21si2085253ejc.833.2024.02.03.08.17.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 08:17:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51178-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=S7jV1sBs; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-51178-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51178-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8F1721F23648 for ; Sat, 3 Feb 2024 16:17:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 868175F57D; Sat, 3 Feb 2024 16:17:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S7jV1sBs" Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F8105F561; Sat, 3 Feb 2024 16:17:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706977029; cv=none; b=jHEvtgniNqTczrmoAmxL4jrRwWaGn7WzbO3Ilr1aZq1iIhKAXC5fbo1ArSbd3YJgLHsqGI/6PZjrFpmjwOJ7yTqnLnT58FBIpaqzvT5z9JWSGcdxCNqoPEJ6XH4uQTIANYB4b/MgXjPmWV2xsCbFBDZhcwIAkBjuxj3uUXEvHO8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706977029; c=relaxed/simple; bh=2GPOc2PZ2fg/zlvgyDEmTDV/NI/x0BA9gFkuOhJfAhw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fWzrPQ5ZpIdeH8BAL5QraDctUs8ebzYSGQ097OzQA7HKwzqUtMoiJXrxldvig1N8x5ExdZFRY++ikKjMtNjNZ178DJ9+fXZQGNp3uZ+3SB5OXQBN3+owUtVopTRdd5P1ZF7h25CqUhbysQkNNPkd/djk/pujHndnIoP9FiHxuk8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=S7jV1sBs; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1d76671e5a4so24458355ad.0; Sat, 03 Feb 2024 08:17:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706977027; x=1707581827; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kkKSBEd57oTuNT42X1XreOYTPrUWtWe7ns5GZwL0900=; b=S7jV1sBs7Mcm7rqfwHOJP6a0cwTGEyInPG5WsPEt2HGJrno0qvX7tGGdtjYz+hn0lb YYM2gMcxV++t3vaAs4PcaXfehuiPWyV3/jwfAynQSJpEMbDbER8VdvAsOoPep4Bz0Kr+ Vcd+vwfzFejN0tsQJcZnGaBqFXB4xg8GrEFB4aqeKoo5Cpts4dJVKZpJXqOIsYzqY+fV D+crHNFqJ0w92g0+OmjsT7gbrWCFOo1wBcOg9Iv98iVZoG6dKB9K9FD6ZYWbDCxpVmTA 8hf6C4B5xpkIbT28tFcWySR/d+QspiMqfskk1SPui2QJ9hrkLAo2OOr/BOWn5ie7FH7p npsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706977027; x=1707581827; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kkKSBEd57oTuNT42X1XreOYTPrUWtWe7ns5GZwL0900=; b=ILUlmya94cY0qU9mQM297EkrtdajrnrrJ9ylmWG/H6hHBSmYK5LJG/oUVBdx61ixsk gE2BK38bV5t8wWwrjkCFehBvEVUgkgj0XoKx+doUPLreYhlaZmkZEMVLjYnLIujyarwa 4/WW//4eXF3EXsUnSzC7LRWBZPAQfddquQ+qe2wLcIiXT3BcB5gUUi4dpVFsr4ZYhHAs 2E/pvUPUQHVnyOnzKDju42quFyN/JWaLKzijxCRUhulcvXO59mBlgoc1RkUyEfi4HSMe CU3HDUWycqyzIHyGNWSHYbxAr4mITkQPSFbAx/1HS9ew3hfE3q0KQr9iMDjZG4kcVzMt 82jg== X-Gm-Message-State: AOJu0YwHXfv3ctOB4nfhgYJYT0Lmq4Er6fm26c33wVnSs/T0K03JZiiq r6QobvAQH2x6DZ09heKeHrQOAt8BQED/AZFnFSNZQIny0QtT/NxG X-Received: by 2002:a17:902:e807:b0:1d7:83e4:a19 with SMTP id u7-20020a170902e80700b001d783e40a19mr15438382plg.33.1706977027362; Sat, 03 Feb 2024 08:17:07 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCULw3SkPAaFjzvA6Q65uEQ8raXUpBhJ0EnZPV9zLFUX5bKx2X9NDKnGsY0NTXcjz3SXf4C6HzWXEBLvbdnCr58EpB3Bub36vNbCmhWz2xdVQz3f3UMt88wMpKGoR8+WqjUwJKJrBPb8mGZSxK3p89Fkyg75Fk1E9qc270suqMUMhj/qcW64nctsNHeggY3Fqm1X3jxKGD6QdgBxqueu6IYMb5Akvg== Received: from carrot.. (i223-218-113-167.s42.a014.ap.plala.or.jp. [223.218.113.167]) by smtp.gmail.com with ESMTPSA id jh2-20020a170903328200b001d94546686esm3465551plb.28.2024.02.03.08.17.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 08:17:05 -0800 (PST) From: Ryusuke Konishi To: Andrew Morton Cc: linux-nilfs@vger.kernel.org, syzbot , syzkaller-bugs@googlegroups.com, linux-kernel@vger.kernel.org Subject: [PATCH] nilfs2: fix potential bug in end_buffer_async_write Date: Sun, 4 Feb 2024 01:16:45 +0900 Message-Id: <20240203161645.4992-1-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <00000000000019a97c05fd42f8c8@google.com> References: <00000000000019a97c05fd42f8c8@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit According to a syzbot report, end_buffer_async_write(), which handles the completion of block device writes, may detect abnormal condition of the buffer async_write flag and cause a BUG_ON failure when using nilfs2. Nilfs2 itself does not use end_buffer_async_write(). But, the async_write flag is now used as a marker by commit 7f42ec394156 ("nilfs2: fix issue with race condition of competition between segments for dirty blocks") as a means of resolving double list insertion of dirty blocks in nilfs_lookup_dirty_data_buffers() and nilfs_lookup_node_buffers() and the resulting crash. This modification is safe as long as it is used for file data and b-tree node blocks where the page caches are independent. However, it was irrelevant and redundant to also introduce async_write for segment summary and super root blocks that share buffers with the backing device. This led to the possibility that the BUG_ON check in end_buffer_async_write would fail as described above, if independent writebacks of the backing device occurred in parallel. The use of async_write for segment summary buffers has already been removed in a previous change. Fix this issue by removing the manipulation of the async_write flag for the remaining super root block buffer. Signed-off-by: Ryusuke Konishi Reported-by: syzbot+5c04210f7c7f897c1e7f@syzkaller.appspotmail.com Closes: https://lkml.kernel.org/r/00000000000019a97c05fd42f8c8@google.com Fixes: 7f42ec394156 ("nilfs2: fix issue with race condition of competition between segments for dirty blocks") Cc: --- Andrew, please apply this as a bugfix. This fixes a kernel bug issue reported by syzbot. This may conflict with the merged folio conversion series when backporting it to stable trees. I would like to send a separate request to the stable team in that case. Thanks, Ryusuke Konishi fs/nilfs2/segment.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c index 2590a0860eab..2bfb08052d39 100644 --- a/fs/nilfs2/segment.c +++ b/fs/nilfs2/segment.c @@ -1703,7 +1703,6 @@ static void nilfs_segctor_prepare_write(struct nilfs_sc_info *sci) list_for_each_entry(bh, &segbuf->sb_payload_buffers, b_assoc_buffers) { - set_buffer_async_write(bh); if (bh == segbuf->sb_super_root) { if (bh->b_folio != bd_folio) { folio_lock(bd_folio); @@ -1714,6 +1713,7 @@ static void nilfs_segctor_prepare_write(struct nilfs_sc_info *sci) } break; } + set_buffer_async_write(bh); if (bh->b_folio != fs_folio) { nilfs_begin_folio_io(fs_folio); fs_folio = bh->b_folio; @@ -1800,7 +1800,6 @@ static void nilfs_abort_logs(struct list_head *logs, int err) list_for_each_entry(bh, &segbuf->sb_payload_buffers, b_assoc_buffers) { - clear_buffer_async_write(bh); if (bh == segbuf->sb_super_root) { clear_buffer_uptodate(bh); if (bh->b_folio != bd_folio) { @@ -1809,6 +1808,7 @@ static void nilfs_abort_logs(struct list_head *logs, int err) } break; } + clear_buffer_async_write(bh); if (bh->b_folio != fs_folio) { nilfs_end_folio_io(fs_folio, err); fs_folio = bh->b_folio; @@ -1896,8 +1896,9 @@ static void nilfs_segctor_complete_write(struct nilfs_sc_info *sci) BIT(BH_Delay) | BIT(BH_NILFS_Volatile) | BIT(BH_NILFS_Redirected)); - set_mask_bits(&bh->b_state, clear_bits, set_bits); if (bh == segbuf->sb_super_root) { + set_buffer_uptodate(bh); + clear_buffer_dirty(bh); if (bh->b_folio != bd_folio) { folio_end_writeback(bd_folio); bd_folio = bh->b_folio; @@ -1905,6 +1906,7 @@ static void nilfs_segctor_complete_write(struct nilfs_sc_info *sci) update_sr = true; break; } + set_mask_bits(&bh->b_state, clear_bits, set_bits); if (bh->b_folio != fs_folio) { nilfs_end_folio_io(fs_folio, 0); fs_folio = bh->b_folio; -- 2.34.1