🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.git
4 messages
4 total messages Started by Mustafa Bayar via B4 Relay Thu, 12 Nov 2026 09:48
[PATCH] ref-filter: fix double free when an object is missing
#2978
Author: Mustafa Bayar via B4 Relay
Date: Thu, 12 Nov 2026 09:48
81 lines
13533 bytes
From: Mustafa Bayar <mbayar@gitlab.com>

When a ref points to a missing object, git-for-each-ref(1) may abort
with a double free instead of reporting the missing object:

    free(): double free detected in tcache 2

get_object() frees `oi->content` but leaves the pointer unchanged. Since
the expand_data structures are reused across refs, a later call can
start with `content` pointing to a freed buffer. Then, if the object
lookup in that call fails before it overwrites the pointer, the cleanup
path frees the buffer a second time.

a29e2e8fe (ref-filter: parse objects on demand, 2025-10-23) introduced
this by making object lookup failures jump to the cleanup label.
bea37f1d6 (ref-filter: fix stale parsed objects, 2025-11-04) later fixed
a related stale-state bug by resetting `maybe_object`.

Similar to `maybe_object`, reset `content` at the start of get_object().
Add a regression test that exercises this path.

Signed-off-by: Mustafa Bayar <mbayar@gitlab.com>
---
This is based on maint, since the bug first appeared in v2.53.0.

We ran into this on GitLab.com, where a repository with a tag pointing
to a missing object made `git for-each-ref` abort instead of reporting
the missing object.

A note on the test: the double free only happens when a valid annotated
tag is processed before the broken ref, so that an earlier get_object()
call has already freed its content buffer. The test therefore names the
refs `annotated` and `missing`, which sort in that order.
---
 ref-filter.c                   |  1 +
 t/t6301-for-each-ref-errors.sh | 15 +++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/ref-filter.c b/ref-filter.c
index bdf54f6f..6c4df521 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2349,6 +2349,7 @@ static int get_object(struct ref_array_item *ref, int deref,
 	int ret;
 
 	oi->maybe_object = NULL;
+	oi->content = NULL;
 
 	if (oi->info.contentp) {
 		/* We need to know that to use parse_object_buffer properly */
diff --git a/t/t6301-for-each-ref-errors.sh b/t/t6301-for-each-ref-errors.sh
index 72b27c8b..e955f66a 100755
--- a/t/t6301-for-each-ref-errors.sh
+++ b/t/t6301-for-each-ref-errors.sh
@@ -52,6 +52,21 @@ test_expect_success 'Missing objects are reported correctly' '
 	test_must_be_empty brief-err
 '
 
+test_expect_success 'missing objects after a tag are reported correctly' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		test_commit --no-tag initial &&
+		git tag -a -m annotated annotated &&
+		test-tool ref-store main update-ref msg refs/tags/missing "$MISSING" "$ZERO_OID" REF_SKIP_OID_VERIFICATION &&
+		git rev-parse HEAD >expect &&
+		test_must_fail git for-each-ref --format="%(*objectname)" refs/tags/ >actual 2>err &&
+		test_cmp expect actual &&
+		test_grep "fatal: missing object $MISSING for refs/tags/missing" err
+	)
+'
+
 test_expect_success 'missing ancestors are reported by contains filters' '
 	test_when_finished "git update-ref -d refs/heads/missing-parent" &&
 	{

---
base-commit: 03b41523c576f26ad34085378717a0c1b287470f
change-id: 20261112-mb-ref-filter-missing-object-double-free-maint-9eadbfe11e71
Re: [PATCH] ref-filter: fix double free when an object is missing
#2986
Author: Karthik Nayak
Date: Thu, 12 Nov 2026 13:44
58 lines
14482 bytes
--0000000000000c1abc066014835c
Content-Type: text/plain; charset="UTF-8"

Mustafa Bayar via B4 Relay <devnull+mbayar.gitlab.com@kernel.org>
writes:

> From: Mustafa Bayar <mbayar@gitlab.com>
>
> When a ref points to a missing object, git-for-each-ref(1) may abort
> with a double free instead of reporting the missing object:
>
>     free(): double free detected in tcache 2
>
> get_object() frees `oi->content` but leaves the pointer unchanged. Since
> the expand_data structures are reused across refs, a later call can
> start with `content` pointing to a freed buffer. Then, if the object
> lookup in that call fails before it overwrites the pointer, the cleanup
> path frees the buffer a second time.
>
> a29e2e8fe (ref-filter: parse objects on demand, 2025-10-23) introduced
> this by making object lookup failures jump to the cleanup label.
> bea37f1d6 (ref-filter: fix stale parsed objects, 2025-11-04) later fixed
> a related stale-state bug by resetting `maybe_object`.
>
> Similar to `maybe_object`, reset `content` at the start of get_object().
> Add a regression test that exercises this path.
>

I had only reviewed this patch internally and we did some iterations
there [1], so mostly just rubber-stamping here that it looks good to me.

Thanks for working on this!

[snip]

[1]: https://gitlab.com/gitlab-org/git/-/merge_requests/737

--0000000000000c1abc066014835c
Content-Type: application/pgp-signature; name="signature.asc"
Content-Disposition: attachment; filename="signature.asc"
Content-Transfer-Encoding: base64
X-Attachment-Id: fd9748403826e52b_0.1

LS0tLS1CRUdJTiBQR1AgU0lHTkFUVVJFLS0tLS0KCmlRSEtCQUVCQ2dBMEZpRUVWODVNZjJOMWNR
L0xaY1lHUHRXZkpJNUdqSDhGQW1yMXdyd1dIR3RoY25Sb2FXc3UKTVRnNFFHZHRZV2xzTG1OdmJR
QUtDUkErMVo4a2prYU1md3M4Qy9zRjRxTXRWTGlrR3lwWjN6UVJBaXFqQnVWbgo4ekdiejc0Tk9j
OXJwNDZnMnhEaUZNMFRFbi8vNnorbzBVTGpXaGRmMW5HSnJYL0hHUFRmNEduRWxJOThEZzRaCklS
ZmJhQm5OdllhYUhwMGcrejZYUFJGZm5GSWhuMkxobDFmRThzRHBlbkFHbVcrWEs4MWswL29JMkh5
YTl6enoKRlVQRHdRbUl4SHl1NEJqMmpDR3NWd1NuekpVVGUwbEpDZEkwNU1qV2cxaDRWNi96VXpP
aDg1ZCtXUHpaL1locgphUTdieFBKMzdmaTNjL24wYjk2b0NEb2FUS0ZKT1hYbnJkQm92OWtiTXd6
ZGNPdWFNZWw2VEQ1eEZ5NzhrTjI3Ck5uRjhZcFdoNEhlYVpFSjZjODFlRTIzdG9BR3FJU1hQSUY4
T3ZVNXNBenZiemdEV3dmdURCalpzV1pmVnlXbnAKV21Jd09wVTdmNlhhVmtKMUtLaUFlWDFxd2k5
Rk56bWJ6TXA1MXZPL1dPMVZ5eG5EYk5yUksrZ2ZzbWJNRWlVaApvUXkydTBoNFpYTGxETDhqN0ZL
cnAyQmVkbzI0RTJWdkU2N29KZlcydUJYSXdpOEt4RXk0ZGpPL0hVcWFrU29qCkJiK1FVSkk0aVYv
dDNrdGpLTFRGemN0bHFzRFQ5TVBVc0JUVjNnZz0KPVVBTncKLS0tLS1FTkQgUEdQIFNJR05BVFVS
RS0tLS0t
--0000000000000c1abc066014835c--
Re: [PATCH] ref-filter: fix double free when an object is missing
#3036
Author: Junio C Hamano
Date: Thu, 12 Nov 2026 20:29
19 lines
13273 bytes
Karthik Nayak <karthik.188@gmail.com> writes:

>> Similar to `maybe_object`, reset `content` at the start of get_object().
>> Add a regression test that exercises this path.
>
> I had only reviewed this patch internally and we did some iterations
> there [1], so mostly just rubber-stamping here that it looks good to me.
>
> Thanks for working on this!


I take the above with "only" -> "already".  Thanks for writing and
reviewing.

Will queue and mark the topic ready for 'next'.  The patch is very
well written, together with historical reference and all.

Thanks.
Re: [PATCH] ref-filter: fix double free when an object is missing
#3040
Author: Karthik Nayak
Date: Thu, 12 Nov 2026 23:13
48 lines
13958 bytes
--0000000000009cd0cf06601c7621
Content-Type: text/plain; charset="UTF-8"

Junio C Hamano <gitster@pobox.com> writes:

> Karthik Nayak <karthik.188@gmail.com> writes:
>
>>> Similar to `maybe_object`, reset `content` at the start of get_object().
>>> Add a regression test that exercises this path.
>>
>> I had only reviewed this patch internally and we did some iterations
>> there [1], so mostly just rubber-stamping here that it looks good to me.
>>
>> Thanks for working on this!
>
>
> I take the above with "only" -> "already".  Thanks for writing and
> reviewing.
>

Sigh! that's what I meant :)

> Will queue and mark the topic ready for 'next'.  The patch is very
> well written, together with historical reference and all.
>
> Thanks.

--0000000000009cd0cf06601c7621
Content-Type: application/pgp-signature; name="signature.asc"
Content-Disposition: attachment; filename="signature.asc"
Content-Transfer-Encoding: base64
X-Attachment-Id: ed062f2b408e4df5_0.1

LS0tLS1CRUdJTiBQR1AgU0lHTkFUVVJFLS0tLS0KCmlRSEtCQUVCQ2dBMEZpRUVWODVNZjJOMWNR
L0xaY1lHUHRXZkpJNUdqSDhGQW1yMlNDVVdIR3RoY25Sb2FXc3UKTVRnNFFHZHRZV2xzTG1OdmJR
QUtDUkErMVo4a2prYU1mN0VJQy93SW9xMTlDUmorQk5OVE9ibGUzaUZwM3paNwpTNlhkUjNVaThs
NWNnd2ZBY3JQdlk3eUUwRHNQcVc5LzIyclQ0Z0YyNHJGUVI4SjdMWWtvZ3lnczllOEJiaDdXCnNz
VkRzSWcyYlc0RkN0T3NKOHJJSmRHUnNEcVRRVzh6WWxFRXJYM2RiSW10U1dHa3QrWXdVVTF4SFV6
NVVsb1gKRkI2VTNBV2oxWU1nVFFjWGw2VUpjcXhVU3FwYThXSkhXb05XSVN4d1BkV1NyY2ZKbWhJ
YnFhNW9LVExUZGE5bApKaFlCdlVBZ2k3QlpYdE5VUFBEbGlSMnhraTBKMXlJdGoybFo4a2Z2ZWFo
MFhoUWJLN3g3WkhIeWpITVlaYjJ1CmZLcnY3MENERytSSTc4VDV3cnpocnlDcGZpVENOUlVaM0dL
eVJJaDE0cS8wRnExSzJiVFNKOUtaa2dCZnlTaVQKV3BJak1sUzN0NjdBNk4vWUprdEtFazJLTWV3
a2dxQkRmeTE5eGRVQkJQeUdZSFZEYjUrbUdHUktZbHRLc002bgpPMDZLVmtCek94T1JLdHNocmxk
UWJSZCtpRzRiL2hKN2dWZjVrSzV3OTNrSldNdzAyRTQzeWhwMTNrQWVUK2k4CjhORTlWWXlvK05m
QkJVa3hKL2NrVHpVWkFVdWYxQ3huUkdWb25pMD0KPUxiSFoKLS0tLS1FTkQgUEdQIFNJR05BVFVS
RS0tLS0t
--0000000000009cd0cf06601c7621--
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads