From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 B8D60383C6E for ; Fri, 13 Mar 2026 23:49:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773445784; cv=none; b=BVrCUZhJDE/4aWvjK6IihX4udbURowL0B/3Dgqmdq2QYnaJJEeB2qsBubNZN9N5sare5ZvYwQIVZz5SiX9CwnSfnk+Hups7Nt/XrLLuRZwooT7EJqlx96lh2itHj11Mc6lcJBrnMEvbjzwiyDf+YscXpSpZ0Yd8spQ5/1xWIRg0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773445784; c=relaxed/simple; bh=Ug3wEHDhYNRNvcxRpPUXYilANr5OS42G07jtI2lQsF8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=sKPvMRpyaZjHVeLL1TuXxFDjYqr9nb/CF4YlLdSgPAQHpyKSoXPho9M3pNnjwhppZtkEb+UO49bGvS6j37f2O84vsckqKBRKd8eTNgzzxtrV+dZMaIAob7e7coBD082JDeWh8njDy0mrDHQZUa3yEzEnVasLcK06ifg1RGEfauI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=WAeF9i+2; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="WAeF9i+2" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4852ff06541so28357755e9.2 for ; Fri, 13 Mar 2026 16:49:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1773445781; x=1774050581; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=2+abZk65FMlelhEsZphyR/S+RxRS2Dmb37FzndSoqfw=; b=WAeF9i+2m3liEvRYM521y+KjcOePBq4XV99P57P3IKl6AkJforrlYUWuY0r7B5wibr OGhkos/Un3UFNun9P0QDPPFDdi32iVsnmvuA4DqbPnvxG9o/XkLn+k3gfbRZivGbSCxl Gfjy6QN/1NbFt1uX8eR5B3CPrqwGYK8I10nqVszAnISdKARwLG/YylKcqpjvqnC3KQUT mZn+DJ1MmVEsGYM0UUhZRXMmTaUvTkCHFkWvXUYbm6X4Tu7vLBVgSZPQBMQnKL+5lyj6 mT2Z3t0QV/ExGGdnryWYNOGhIYo/pfXHvv3LkQPZ1Pcv++NVL9Q5oFOgxw4D60sNZkUF le3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773445781; x=1774050581; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2+abZk65FMlelhEsZphyR/S+RxRS2Dmb37FzndSoqfw=; b=r83y9jwO4AtAVzbl/wivgUoUw4Li/oUoeqg9BO8EUSk4HzX4I5rQVw6+nhyQwlPgrE JlaoBORcMPX+UNM+wbf2z3UC9ILXAiH40iLH65ZaIrA0ArDd5t1Kyk8rHGFl9mndp8ig PMVG0fLCezyhGJda5RS/i9U0Vnwm4P74xJxweBCBDe2xSflWjtR3SFGDT2Anoj0MpGPk o/+ulOkJe74qQxarl2z0cuab7Mnyhl6L7qeM6PI9K0LeFQPvhc60ko7iZ62pTqEIGhGd TRGxK3qWux2Kx9yu8n1OXjmpxXy0qM3KqOtPd4leCGMU5UVTgEqXzripdCZmohuZytsT l5cA== X-Forwarded-Encrypted: i=1; AJvYcCUMSnfSR4Esxz6sRpmDyFK/71Dyo1r0ldm5Icm98Nv6aVbkRGWPur6t7QHJfrRovn352eWVhn5HWF1rLyE=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5MRD44R35ZTz6PSx8uZMxp/F4W69+OsTITiSzeQzJt7NWY53c whlxE+8xeM0EKtNyd3M3NK9iEJLePHJB6dbZg9u/a1sjLAs7WQMgDiZxiQ3J7p3eUSk= X-Gm-Gg: ATEYQzxLB1gYAAa5u1Y2kmePndSlmhsX/XhQckSrVau9orvnQ9FNgfsZgqHf3lIoe9u vePoXzMVSDaFhL5+cXqI2myyAp7kJqd+tpT/QtV2uX8EqGR4XMgTSzYkDqxiruJZFKg4/pXYRCU nWqN3iYQUEmQ4dYXp3VUx9f0y63sgGirRNi3tkG2kOHv3Xd3WsE6qEBmbL5PNBuLOvMswgVUXbg scDjRcUG0BeyjWftBOiL+pfJ77Zkt6yTo+CiP8qj+UJ0BqsK92rrdUJQkUhEZapAIOdPGVWRdpX 3mh2X4ynDjUA+Xfbsc4dXHLmwBm8ZPSwzEjXDeBBwLpG1IwYShHjSVgUro/yqcHwfYKeki0EGKQ mePJYr0NSscFvcYz2a7hjC8YhibHKWS5K1buHbAdnY6ww6nv8xAt+GSo0s4W+5FT/GAycxhTjxt Qv7V+9rwVywVdHloXEG2nGwSNinqZzzg+TCoYcM24+ubpl1w43ibkkneDkl70OaQ== X-Received: by 2002:a05:600c:4689:b0:485:2fc5:39f with SMTP id 5b1f17b1804b1-48556713b6dmr82954915e9.29.1773445781016; Fri, 13 Mar 2026 16:49:41 -0700 (PDT) Received: from ?IPV6:2403:580d:fda1::299? (2403-580d-fda1--299.ip6.aussiebb.net. [2403:580d:fda1::299]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c73ebb77465sm2561802a12.25.2026.03.13.16.49.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 13 Mar 2026 16:49:40 -0700 (PDT) Message-ID: <1c34e37c-9a5c-4063-9e4d-84c797c0daa8@suse.com> Date: Sat, 14 Mar 2026 10:19:31 +1030 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 0/2] btrfs: verify cached extent buffers against tree parent checks To: ZhengYuan Huang , dsterba@suse.com, clm@fb.com Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, baijiaju1990@gmail.com, r33s3n6@gmail.com, zzzccc427@gmail.com References: <20260313091924.570554-1-gality369@gmail.com> Content-Language: en-US From: Qu Wenruo Autocrypt: addr=wqu@suse.com; keydata= xsBNBFnVga8BCACyhFP3ExcTIuB73jDIBA/vSoYcTyysFQzPvez64TUSCv1SgXEByR7fju3o 8RfaWuHCnkkea5luuTZMqfgTXrun2dqNVYDNOV6RIVrc4YuG20yhC1epnV55fJCThqij0MRL 1NxPKXIlEdHvN0Kov3CtWA+R1iNN0RCeVun7rmOrrjBK573aWC5sgP7YsBOLK79H3tmUtz6b 9Imuj0ZyEsa76Xg9PX9Hn2myKj1hfWGS+5og9Va4hrwQC8ipjXik6NKR5GDV+hOZkktU81G5 gkQtGB9jOAYRs86QG/b7PtIlbd3+pppT0gaS+wvwMs8cuNG+Pu6KO1oC4jgdseFLu7NpABEB AAHNGFF1IFdlbnJ1byA8d3F1QHN1c2UuY29tPsLAlAQTAQgAPgIbAwULCQgHAgYVCAkKCwIE FgIDAQIeAQIXgBYhBC3fcuWlpVuonapC4cI9kfOhJf6oBQJnEXVgBQkQ/lqxAAoJEMI9kfOh Jf6o+jIH/2Kh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FIUb3hFiu3zhDDvslYM4BmzI18QgQTQnotJH8= In-Reply-To: <20260313091924.570554-1-gality369@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 在 2026/3/13 19:49, ZhengYuan Huang 写道: > This series fixes a btrfs crash caused by reusing a cached extent buffer > without re-running the caller supplied tree-parent verification. > > The problem happens when a tree block is first read and validated with one > expected level, then later looked up again through a path that derives a > different expected level from corrupted metadata. If the extent buffer is > already marked EXTENT_BUFFER_UPTODATE, the cached-hit path returns it > without re-validating the supplied btrfs_tree_parent_check. This can allow > an inconsistent btrfs_root to be constructed and later lead to a > null-ptr-deref during backref walking. > > Patch 1/2 is a preparatory change that extends > btrfs_buffer_uptodate() to support tree-parent verification on cached > buffers. Patch 2/2 uses that support on the cached-hit path and contains > the actual fix. > > Together, these changes make cache hits and fresh reads follow the same > tree-parent verification rules, turning the corruption into a read failure > instead of constructing an inconsistent root object and crashing later. > > For reference, a more detailed analysis of the trigger path is available at: > https://lore.kernel.org/all/CAOmEq9U14a=pwN_dw2M70gfujhMKki434cfmegoxcyUpkYs5bQ@mail.gmail.com/ > > Changes since v1: > - drop the adhoc root-specific consistency check in read_tree_root_path() > - move the validation into the cached-hit path as suggested by Qu Wenruo > - extend btrfs_buffer_uptodate() with an optional tree-parent check > - make read_tree_root_path() pass its check when validating a cached root > > ZhengYuan Huang (2): > btrfs: add tree parent check to btrfs_buffer_uptodate() > btrfs: revalidate cached tree blocks on the uptodate path The code looks good to me, but considering both patches are small, and without the second patch the first one doesn't make much sense. So I'll merge both into a single patch at merging. Thanks, Qu > > fs/btrfs/ctree.c | 2 +- > fs/btrfs/disk-io.c | 18 ++++++++++++++---- > fs/btrfs/disk-io.h | 3 ++- > fs/btrfs/extent-tree.c | 2 +- > fs/btrfs/extent_io.c | 12 ++++++++++-- > fs/btrfs/tree-log.c | 2 +- > 6 files changed, 29 insertions(+), 10 deletions(-) >