Article View: linux.kernel.git
Article #4297Re: [PATCH v2 1/7] commit-graph: verify all trailer hashes against the chain file
From: Kaartic Sivaraam
Date: Thu, 03 Dec 2026 09:13
Date: Thu, 03 Dec 2026 09:13
141 lines
16095 bytes
16095 bytes
On 11/20/26 17:52, Patrick Steinhardt wrote:
>
> The fact that we perform the validation when linking means that the
> check of trailer hashes is delayed: we only verify the hash of layer N
> when linking layer N+1 onto it. That of course doesn't make sense, as we
> will then happily use a layer with a mismatching hash while dropping all
> layers built on top of that. What we should do though is to cut the
> commit graph chain at the first mismatching layer.
>
> Furthermore, this also means that we never verify the trailer hash of
> the topmost layer: there is nothing to link onto that layer, and hence
> we never verify it.
>
> Fix this by verifying each layer directly after loading it.
>
Nit: "verify ... trailer hashes" made me think at first that we now
validate the checksum of each layer on load. On some investigation, I
understand that we don't do that to keep the commit graph load
performant. I wonder if we could phrase that explicitly as follows to
make it less ambiguous:
Fix this by checking each layer's trailer against the chain file.
>
> diff --git a/commit-graph.c b/commit-graph.c
> index da65cd3deb9..0c75939910d 100644
> --- a/commit-graph.c
> +++ b/commit-graph.c
> @@ -580,8 +580,6 @@ static int add_graph_to_chain(struct commit_graph *g,
> struct object_id *oids,
> int n)
> {
> - struct commit_graph *cur_g = chain;
> -
> if (n && !g->chunk_base_graphs) {
> warning(_("commit-graph has no base graphs chunk"));
> return 0;
> @@ -595,15 +593,11 @@ static int add_graph_to_chain(struct commit_graph *g,
> while (n) {
> n--;
>
> - if (!cur_g ||
> - !oideq(&oids[n], &cur_g->oid) ||
> - !hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_algo->rawsz, n),
> + if (!hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_algo->rawsz, n),
> g->hash_algo)) {
> warning(_("commit-graph chain does not match"));
> return 0;
> }
> -
> - cur_g = cur_g->base_graph;
> }
>
> if (chain) {
> @@ -682,13 +676,19 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct object_database *odb,
> free(graph_name);
>
> if (g) {
> - if (add_graph_to_chain(g, graph_chain, oids, i)) {
> + /*
> + * Verify that the loaded commit graph's
> + * trailer matches the chain file.
> + */
> + if (!oideq(&g->oid, &oids[i])) {
> + warning(_("commit-graph chain does not match"));
> + } else if (add_graph_to_chain(g, graph_chain, oids, i)) {
> graph_chain = g;
> valid = 1;
> - } else {
> - commit_graph_free(g);
> }
>
> + if (!valid)
> + commit_graph_free(g);
> break;
> }
> }
The change itself looks fine to me.
> diff --git a/t/t5324-split-commit-graph.sh b/t/t5324-split-commit-graph.sh
> index bf7ba0e5580..aea89f42fa1 100755
> --- a/t/t5324-split-commit-graph.sh
> +++ b/t/t5324-split-commit-graph.sh
> @@ -16,9 +16,6 @@ test_expect_success 'setup repo' '
> infodir="$objdir/info" &&
> graphdir="$infodir/commit-graphs" &&
> test_oid_cache <<-EOM
> - shallow sha1:2132
> - shallow sha256:2436
> -
> base sha1:1408
> base sha256:1528
>
> @@ -275,13 +272,17 @@ corrupt_file() {
> printf "$data" | dd of="$file" bs=1 seek="$pos" conv=notrunc
> }
>
> -test_expect_success 'verify hashes along chain, even in shallow' '
> +corrupt_trailer() {
> + corrupt_file "$1" $(($(test_file_size "$1") - 7)) "corrupt"
> +}
> +
> +test_expect_success PERL_TEST_HELPERS 'verify hashes along chain, even in shallow' '
Nit: Given the change from testing the base commit rather than the tip
commit with 'verify --shallow', can name this 'verify --shallow detects
corrupt tip layer' ?
> git clone --no-hardlinks . verify &&
> (
> cd verify &&
> git commit-graph verify &&
> - base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
> - corrupt_file "$base_file" $(test_oid shallow) "\01" &&
> + tip_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
> + corrupt_chunk_file "$tip_file" OIDL 0 ff &&
> test_must_fail git commit-graph verify --shallow 2>test_err &&
> grep -v "^+" test_err >err &&
> test_grep "incorrect checksum" err
Also, the corruption in base layer would still fail in '--shallow' even
after this change. So, is it worth having a test to verify that?
Something like:
test_expect_success 'verify --shallow notices broken chain below tip' '
git clone --no-hardlinks . verify-broken-base &&
(
cd verify-broken-base &&
base_file=$graphdir/graph-$(head -n 1
$graphdir/commit-graph-chain).graph &&
corrupt_trailer "$base_file" &&
test_must_fail git commit-graph verify --shallow 2>err &&
test_grep "commit-graph chain does not match" err
)
'
--
Sivaraam
Technical Details
Message-ID:
<7da217b2-f359-4336-8a8a-faf67c4f298f@gmail.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76939-linux-kernel-git=dewy.ruReferences:
<20261120-pks-odb-pluggable-commit-graphs-v2-0-31f2341a9932@pks.im> <20261120-pks-odb-pluggable-commit-graphs-v2-1-31f2341a9932@pks.im>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76939-linux-kernel-git=dewy.ru
From: kaartic.sivaraam@gmail.com (Kaartic Sivaraam)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH v2 1/7] commit-graph: verify all trailer hashes against
the chain file
Date: Thu, 3 Dec 2026 14:43:42 +0530
Organization: Usenet Network
Message-ID: <7da217b2-f359-4336-8a8a-faf67c4f298f@gmail.com>
References: <20261120-pks-odb-pluggable-commit-graphs-v2-0-31f2341a9932@pks.im>
<20261120-pks-odb-pluggable-commit-graphs-v2-1-31f2341a9932@pks.im>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
logging-data="2445281"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:CKBN1uRevmhnqivdureJIPVw3pc= sha256:I2ALkfKpUiXfs8u6QDqFwOSOor+tR1MdgQR+4BECakg=
sha1:DCB0iSMcRiasJAVxxXsqp5zs2o8= sha256:UjG3uJvJHHZD2F/DHTPHZ4JqPtz4ZClSxCnRzw3nwic=
Content-Language: en-US
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 669FA117896; Thu, 3 Dec 2026 12:14:02 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id ru_GoeeGcg9Y;
Thu, 3 Dec 2026 12:13:58 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-76939-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 3D647117890; Thu, 3 Dec 2026 12:13:50 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id 9805225A11; Thu, 3 Dec 2026 09:13:48 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1796289228;
b=1wGbk3GIoBupbEbu9VzawI32t49SsY7aOQ7M/4xtkFV/UcHawKfQFUEWymxAArZCNsgE
LaUJlejBKsA+eyUONVER3uKTcZp4c1w9tf3pcK1G+seScZdHWAxBNggw3hmZJP+vf5sQT
xDNqWqmpyKnFX3rqvhjxrMJnp0nveH4e5FZ+5NFB9YINAXaEJQbzyvf6f+W+KHivLC62g
lcb86NLaH5/q/GdO2zQFoqHbKRn9cT4BI5mD1nz/yOZ3voktcy84JYIWr8s4l/h42EJvZ
pGudo0my9dDBxEt44fI/Fnwh/uVwy3QdPwijsqiyYGFbKt+U0TWcb6jaH1XFo54oa5Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796289228;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received:Message-ID:Date:X-Mailing-List:List-Id:
List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
Precedence:MIME-Version:User-Agent:Subject:To:Cc:References:
Content-Language:From:In-Reply-To:Content-Type:
Content-Transfer-Encoding;
bh=ORlF1bSPaMxJOJiShRMtrcxmW5eb3mR+mU1UzDZC8Xg=;
b=0rRBsSlSUeS65Oq06YgUv+SjGSPLk0J9Rfzk8dhpFsRl/nTBxV0H4QBr6GIO79THA/Hj
lOiPChHtOkcO3YMZ+i3HlKN2OpRGqSrl7kLLc/AXm8OSz3TImYPVUgc/qj31aO40RtUVH
L8sNUEqXoQidPH/wSV9mCWMBAtMQPjWoPWaBBK8usJGTpyuwDmaLFI8MyPb5Mm8tjsFX6
Z+NJv3JDbgStzvdPRjYumYc2h4K2txgp1Skpx31PGGlVJ5eOr9bwRActLc+goaKse8Tg5
CI3skJGcQgA60ClXY3zE0jHxn5ORsz8M8WwF00nLEbqWwlfYCpoHQ60xY/j+OTIY2NA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=02vLTN8X;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 71210606A68D;
Thu, 3 Dec 2026 09:13:48 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=02vLTN8X
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.181
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1796289227;
b=lg3oZKUU5aHrSA5fSu0kC77l3dxZ+K4zm+SMJDQFtRVGG30cMdBMVq8Zj9nqqVRdKH6G
w2sDs9jkhg4BTK2VXsDApCHqyhNhRwiDxqBiMQiKfl9BS4ynm38fLK9ZqyMAnYbEzvGy7
+QHcf3ZxABAnZTNr9Q4EddMlTcnzeG032dnqh3z83VvGVWApuajv32hd24wgtU+t81wOu
oG7udgPKY6S7BiVpa8ItAjGqxjcE6YiCXEDR9Pj8YZfscmd3jGbdktke/ammcxdLozk1w
rAP3ryOfIc6NPo3iaVBTUQdFqx3eZBUARTA4jV9Mrh80o/d5wK+3hrWaGDlo1LmD44A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796289227;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References:
Content-Language:From:In-Reply-To:Content-Type:
Content-Transfer-Encoding;
bh=ORlF1bSPaMxJOJiShRMtrcxmW5eb3mR+mU1UzDZC8Xg=;
b=j2kKMvc2i4k2hfRD+zVC0MiuL9QBK5Cv9rIgkIyfK0E40LtjcJIxcQJ+fzrsqb0FI6o6
d7dQ0GxnOUeFOFmqWiFwSl+OjtiiyGoM5xApWGl4HhTTTn8iv6gtwaRZGMvZAxTv+sDiR
oTu47BzR/VUKNiD6AUCenvz+HmPRLasuAOuO0jCZq3lSJtvMmX/V+71XkCEQ7JY7xbVP7
A4Y09lRFcCKY+oMxc3JP4zNeF462XewxQOHavfMl47MHcyiHJNCk1my0Lmek4fgJhq4LM
Dc7SnUe7/g6BH9b95A98t8MuYqCdtbSp+VNuBMjyjlYjVq43vZFUSZowuJk92vd/THA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=02vLTN8X;
arc=none smtp.remote-ip=209.85.210.181
X-Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 866B9606A33E
for <git@vger.kernel.org>; Thu, 3 Dec 2026 09:13:46 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 866B9606A33E
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-8b67f25e6e1so7023825b3a.0
for <git@vger.kernel.org>; Thu, 03 Dec 2026 01:13:46 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1796289226; x=1796894026; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:in-reply-to:from
:content-language:references:cc:to:subject:user-agent:mime-version
:date:message-id:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=ORlF1bSPaMxJOJiShRMtrcxmW5eb3mR+mU1UzDZC8Xg=;
b=02vLTN8XXCSXYLXOjgCaZf40FfEeNPz2mPVp7UPfC/5FXgDjsRzEVGFg57iRW9on29
yNu4/V37dshVIcu58rJa+oSXI1JwVSI0y7HxEetrSzwU4IcQrujHLI1WqgqOu4WYthe0
Xj1PL67f8x9krPM0A5kM2zJNs2cJFBFCFQ0tUWlNW6L//WiFQwhEaJ5p1FlKcdq77BYg
6ItNpRpp+FN/FZqx1MvbLt2+k8vViVrGPywzJ58Gol+PbkzgYUBMG3kZRIxioPfRPblp
3qJj91Htoido+BCiI+AQ4zo6Ft8p1SSHkhoiwPadgyJvxFCYu+YYrzuE+mym85YL6aX1
OxSw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1796289226; x=1796894026;
h=content-transfer-encoding:content-type:in-reply-to: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:content-type;
bh=ORlF1bSPaMxJOJiShRMtrcxmW5eb3mR+mU1UzDZC8Xg=;
b=xegB1YwdCOeEjLJT47UXrC+gHlC6+fpO1uPA9S25TbfpIzuFzzXY1GAdCrkUCCTVHB
d229+F9GNPTou6PnCWcVSFga/bm2XN/CbC7CNzl7y/yCs8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MX4u+uLk
fICI60PXIO6yfR94zK1ddIrMtOcWUkbekhjuzPlFxxHGmWerpTyZwoMTBNHizmU=
X-Received: by 2002:a05:6a00:4b03:b0:89e:3ff1:920d with SMTP id d2e1a72fcca58-8c87d01fba2mr42274092b3a.45.1796289225478;
Thu, 03 Dec 2026 01:13:45 -0800 (PST)
X-Received: from [192.168.1.34] ([103.215.237.233])
by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c87077bff6sm23277219b3a.3.2026.12.03.01.13.43
(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
Thu, 03 Dec 2026 01:13:45 -0800 (PST)
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list
X-User-Agent: Mozilla Thunderbird
X-Cc: Junio C Hamano <gitster@pobox.com>
X-In-Reply-To: <20261120-pks-odb-pluggable-commit-graphs-v2-1-31f2341a9932@pks.im>