Article View: linux.kernel.git
Article #4290Re: [PATCH v2 1/7] commit-graph: verify all trailer hashes against the chain file
From: Justin Tobler
Date: Wed, 02 Dec 2026 22:29
Date: Wed, 02 Dec 2026 22:29
159 lines
16776 bytes
16776 bytes
On 26/11/20 01:22PM, Patrick Steinhardt wrote:
> Since 118bd570029 (commit-graph: add base graphs chunk, 2019-06-18) we
> verify that the hashes in the commit-graph-chain file match the trailer
> hashes of the respective layers. That check is performed in
> `add_graph_to_chain()`, which is responsible for linking a layer onto a
> base layer.
Ok IIUC, for each layer in the commit-graph-chain file, we validate that
the recorded hash matches the hash in the layer's trailer.
> 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.
Interesting, so we basically ignore the hash of the current layer being
added. The next layer that gets added though will check the previous
hash though. I agree that we should avoid adding any layer that doesn't
have a matching trailer upfront.
> 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.
Ya, that's not great.
> Fix this by verifying each layer directly after loading it.
Makes sense.
> Note that this breaks two tests, which both implicitly rely on this old
> behaviour. Adapt those so that we observe the expected error and add two
> more tests which verify that we detect invalid trailer hashes in the
> lowest and topmost layers.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> commit-graph.c | 20 ++++++++++----------
> t/t5324-split-commit-graph.sh | 43 +++++++++++++++++++++++++++++++++++--------
> 2 files changed, 45 insertions(+), 18 deletions(-)
>
> 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"));
Ok, now when we load the current layer we immediately validate its hash
matches what we expect. Looks good.
[snip]
> @@ -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' '
> 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 &&
Ok IIUC, previously we were changing the base layers trailer which
caused the tip layer to be dropped and consequently the case layer was
validated. Now we are changing the body of the tip layer directly and
expect that to fail the verifcation. Makes sense.
> test_must_fail git commit-graph verify --shallow 2>test_err &&
> grep -v "^+" test_err >err &&
> test_grep "incorrect checksum" err
> @@ -341,6 +342,32 @@ test_expect_success 'warn on base graph chunk incorrect' '
> )
> '
>
> +test_expect_success 'tip layer trailer must match chain file' '
> + git clone --no-hardlinks . tip-trailer &&
> + (
> + cd tip-trailer &&
> + test_line_count = 2 $graphdir/commit-graph-chain &&
> + tip_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
> + corrupt_trailer "$tip_file" &&
> + git -c core.commitGraph=false log >expect &&
> + git -c core.commitGraph=true log >actual 2>err &&
> + test_cmp expect actual &&
> + test_grep "commit-graph chain does not match" err
> + )
> +'
With this test we corrupt the trailer of the tip layer and check that is
was indeed validated. Previously it would have been ignored. The base
layer should still be loaded and used though, but we don't really check
explicitly which layers were kept. Not sure it there is a good way to do
that anyway though.
> +
> +test_expect_success 'base layer trailer must match chain file' '
> + git clone --no-hardlinks . base-trailer &&
> + (
> + cd base-trailer &&
> + test_line_count = 2 $graphdir/commit-graph-chain &&
> + base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
> + corrupt_trailer "$base_file" &&
> + test_must_fail test-tool read-graph 2>err &&
> + test_grep "commit-graph chain does not match" err
> + )
In this case, the base layer is corrupted and thus no commit graph layer
is expected to be kept.
Overall this patch looks good.
-Justin
Technical Details
Message-ID:
<axCNrruYPAUVlUpC@denethor>Path:
mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76928-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!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76928-linux-kernel-git=dewy.ru
From: jltobler@gmail.com (Justin Tobler)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH v2 1/7] commit-graph: verify all trailer hashes against
the chain file
Date: Wed, 2 Dec 2026 16:29:11 -0600
Organization: Usenet Network
Message-ID: <axCNrruYPAUVlUpC@denethor>
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=us-ascii
Injection-Info: usenet.network;
logging-data="2075928"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:tdOf1D1tp35d4RFpl0QLHk3AARQ= sha256:jvbjRWnUGhcdKJGeiC6vNp3uVpId5LXbPFjOVUwrnhs=
sha1:UO3FnJyEgwvLYreGa53WQbeJMik= sha256:6Keakxc7th7vl3mNUTmmdNbcbapwO9S1TFhJVP7Re/c=
Content-Disposition: inline
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 D28C7117757; Thu, 3 Dec 2026 01:29:37 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.948
X-Spam-Status: No, score=-1.948 tagged_above=-9999 required=6.31
tests=[DCC_CHECK=1.1, 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, URIBL_BLOCKED=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 WITs5whzg6NV;
Thu, 3 Dec 2026 01:29:34 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-76928-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 14DD911771C; Thu, 3 Dec 2026 01:29:24 +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 59E5D275C4; Wed, 2 Dec 2026 22:29:21 +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=1796250561;
b=XewfoS3q2FUq1fo9133u5TH2Lzk36G+8qUHKaskPIdoKYaS5kFsOMZufYiCGJB/VDBZV
w4EJOf+wiokOMHLtujHXEi2bt5D7MkJD6BY7HX/93xbSIbSTvxDE+OtoXRer1zJk+1mBV
GQUFythxSJb1tYZAuB9Y3AOpVil/bgQEuTJ4tY/g6GPYYtMtRgzpJKz71qvgTfUbvjIMX
8b7Ld0KZIqhrl/eqKLqMa9z7SENa9+15WEl1Pt/waNgWOpKm5C4bf9XIYibQULr5e/IF6
DQ48jFRntbrLgjJsnhigEolxokSeoOwxsxah7/QM58BQE5N5KS+VueGbgHywQNehJZA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796250561;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:Date:From:To:Cc:Subject:Message-ID:References:X-Mailing-List:
List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
List-Owner:Precedence:MIME-Version:Content-Type:Content-Disposition:
In-Reply-To;
bh=4VFdjuIWs/9fB7PV5h5vJ3EsFbab47SsSy6f1R3hJuI=;
b=wpyICfoJwEQlppNqOZmZObQAUG11lbYL6lJwJkbd/jRqXMEQPSDyCPLnSOTvC1nP+jhd
vhzK8NthKpnT6tZqdsdnY5fxjbHkc7C5hz6N4wsx+jMWJAXhqQVTVT2ECleaqwJIm0QJ0
W1jmGOCV4C3eimKxB8UEvwc59U9CP16fsnLe+RXQeszxlLgGsMCJvgHEksKfdvexh8DFl
J3f7810utQrv8NShG124ZswUZi2YSDzMF9EWFhZJ/wtwX71UIjYx9/rkTc0SP5wH2s61c
DOhGMRGv2riKdmnsRjOXCPGtqlmJMA1BidBqfTPXYUnmAfwLYHWMwldqq1ISqZMyM1A==
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=Tc6lleAe;
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 30F43606A333;
Wed, 2 Dec 2026 22:29:21 +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=Tc6lleAe
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.51
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1796250560;
b=yKZ2iSbTz28qQ2d57FmDFPmV1g7B5Hqtq1bFBD1x0zjhkLMvfLM4k5jMsomJmw31PeTr
4BgFQjg0985BYUz8PrvKa/0BSIKSUZscXuLMdKfnoTMt6/nMA6JF/wohgi66vb1ecXJbm
cxKqg1u91A9Up6QqWCUVenWW+gWpToK0NEblIzW6MPfMRk83by7RQcJI8Nc40+m7WxcS9
QCbmAC5szcSztBayDZ5osshc6fkE8cnePfftpIh+0b0xquy4LERTMv/x+l2FsX+Afiw1O
x2fnYPXbWUuxX6yu0QMpHyCRPfhV4sit/3oPX3D7PIlWnPQk6PCTmnZ3ztfLyzW8jpQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796250560;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Date:From:To:Cc:
Subject:Message-ID:References:MIME-Version:Content-Type:
Content-Disposition:In-Reply-To;
bh=4VFdjuIWs/9fB7PV5h5vJ3EsFbab47SsSy6f1R3hJuI=;
b=tVgzS7qJ2c1EFcaBpS86Q2oMZIUblwrzm8ebZGvYm3wNKnB3ypiGSnJokv0NBLYWSpwb
PB+pknlCjnvKuElCfczyxZhsEw3MpeLWOu4/AI3RUF5G4Fx0OzobIW4BfwaQ4qG2e3TWm
7GtpAt3Ie0wWIFHr3SJpG6bLrPoNj/v4MKyOiR2wSylybLZo6X+FKoK7zIZO/7+ilFK0i
Mnc6H8YfbxnuM5PUUHXK8VDrjWaV6TKAHJNJ3zx7Nb7vIHZ+2AWD9SighBpknICtUTGbB
XSp9C88qmF0rVQe6XA+tFkurn9Qbe5bgDqS8lJEmTWvvv3pRfAXd8pK0K9j3nLQLdEA==
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=Tc6lleAe;
arc=none smtp.remote-ip=209.85.160.51
X-Received: from mail-oa1-f51.google.com (mail-oa1-f51.google.com [209.85.160.51])
(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 E75C5606A322
for <git@vger.kernel.org>; Wed, 2 Dec 2026 22:29:19 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E75C5606A322
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-oa1-f51.google.com with SMTP id 586e51a60fabf-4cde21f3efcso4507779fac.3
for <git@vger.kernel.org>; Wed, 02 Dec 2026 14:29:19 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1796250559; x=1796855359; darn=vger.kernel.org;
h=in-reply-to:content-disposition:content-type:mime-version
:references:message-id:subject:cc:to:from:date:from:to:cc:subject
:date:message-id:reply-to:content-type;
bh=4VFdjuIWs/9fB7PV5h5vJ3EsFbab47SsSy6f1R3hJuI=;
b=Tc6lleAeHyaSnvc9AnDnjcQ2yyt26a6N7/9iLd/S3az+lcBVxpfpOq8CSu4R4Wp+dr
SdyDKSE96hM+s2eeR5mjSsmshhWwWZT6xfgbwm9nxXr2wTyHIWDy++v7+aVHO7pQT0T+
U3Z4U6UWeLw8V8mhi5rdENc/QXcX+s9KRQtT27WuEi316WPtRSa/7Z39lJVu9a+Hv5LP
q6eJuMFF0utJJ8Zo8pY8AgyLWjJlKUTB/F/y9boItkmnSpspyTH23iPR2tjOZTniN00Y
/+jzupY6Tm3u/UGtWaAUUQjoHQTy/OGkRKIXNKW/IOGyASZUkFaYnK4C03vBMRDm7EJt
lgiw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1796250559; x=1796855359;
h=in-reply-to:content-disposition:content-type:mime-version
:references:message-id:subject:cc:to:from:date:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=4VFdjuIWs/9fB7PV5h5vJ3EsFbab47SsSy6f1R3hJuI=;
b=0nfkJfftHwI/UmsPZrvxY0d6DJzZ3j+z3vOyWzr+VWOTk/AToi6UxUC643e3DF8Snk
QdDsJJBbDEPN+ycUo9vadV9mgzEMpS3RRK0Cm1wEjYbfmzPVL30S8087d7jk5ZZMFFd3
5p2AwJbCWMbq435DiYpesvT2lnDBN2ya48a0H09YuVj/MA3rftbzvBs8Gwuo4xOf9yja
tIAjo4ldu879FlTkaC2RgiYnNLZFAFfYg2ecTAevKgGsol+sZ+ryIbcONDHhg2oD5e+F
jtTCVEzYL9REGxJoGzL4SxzmAW9AZmJEymdpP+EQF/MaqeCFMZnPMxn8Pfg4XecjLTGo
Lmfg==
X-Gm-Message-State: APuU4Z+YViF2pMTWlE4KhHn0xgCbg19RYQLiXtQL1poWZg8AImmmO00d
R4JgbWI8rVQ4SnvAoqNNag4zA8JC7Hx6BaAklBT55FbCFJmFdmshM1kK/vUf2A==
X-Gm-Gg: AZFdTZeCgFuRQjX0HhSBqf06HIghEdPkdqNMJ9SyNJTrisDBAZt53yf7GYQOVd8HsUn
W0tSbCgfbHHFeT8G3qDZ307FEHBtGlhiKSwqjce00wDouImk28KU12BOZzjDf0QQG8afqaFydw7
9CdbUZ+w6bdwUREM2JauGUKuZdVGL8cEE2uczOfzon7RGCpogELJAcQARZeaPDzMDMWqUqILXvv
EtI58BQuIvF6Ah4KFiGVXRHkKJoYqk3qkbZrJ7eXgCUoosADk7TpHsnmK8N8IldgFv1/I4XN+ik
i01ok5qK4QSxrM/LNP91N686qbRI1D+PJQl2cematiDPcj709jRS5Ti88/8y4z2asnIBLm89vEX
VTu0zKIvCMDf2z9dLfoOvOWT1lWXq21r5MBYMimDNgqWvu6GGhcGiTTti0KuDcAoBCay4kdRw8V
b1xbvG9cbkmjvEWzlTKrcY0lDO6PxgBT6TqvGWsyPxy88KWvdy/h3LndlJDLkQeKS0zF14EQs7X
MCleIMfShZGuY7jGMEoTFmB4gYEqpcbfooQgX89ICtFhOobfBy6U47l9ogZ+EWIC5ztAoZL2SZy
BV1X7BFTfr2HB6SUkM7XOKzGBKED3NFmuIhPw7m44TGaQFTHWZ1w
X-Received: by 2002:a05:6870:e0c9:b0:4b7:4fda:1750 with SMTP id 586e51a60fabf-4bc84145f58mr37983009fac.32.1796250558914;
Wed, 02 Dec 2026 14:29:18 -0800 (PST)
X-Received: from localhost ([136.51.44.64])
by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4bc5f7ae7dcsm34797879fac.8.2026.12.02.14.29.17
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Wed, 02 Dec 2026 14:29:18 -0800 (PST)
X-Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
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-In-Reply-To: <20261120-pks-odb-pluggable-commit-graphs-v2-1-31f2341a9932@pks.im>