From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.51 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== 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== 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 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 ; Wed, 2 Dec 2026 22:29:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E75C5606A322 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 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 Received: by mail-oa1-f51.google.com with SMTP id 586e51a60fabf-4cde21f3efcso4507779fac.3 for ; Wed, 02 Dec 2026 14:29:19 -0800 (PST) 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) 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) Date: Wed, 2 Dec 2026 16:29:11 -0600 From: Justin Tobler To: Patrick Steinhardt Cc: git@vger.kernel.org, Junio C Hamano Subject: Re: [PATCH v2 1/7] commit-graph: verify all trailer hashes against the chain file Message-ID: References: <20261120-pks-odb-pluggable-commit-graphs-v2-0-31f2341a9932@pks.im> <20261120-pks-odb-pluggable-commit-graphs-v2-1-31f2341a9932@pks.im> X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261120-pks-odb-pluggable-commit-graphs-v2-1-31f2341a9932@pks.im> 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 > --- > 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