Skip to content

healthchecks: reference count status file data - #13432

Open
bneradt wants to merge 1 commit into
apache:masterfrom
bneradt:healthchecks-use-after-free
Open

healthchecks: reference count status file data#13432
bneradt wants to merge 1 commit into
apache:masterfrom
bneradt:healthchecks-use-after-free

Conversation

@bneradt

@bneradt bneradt commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Replaced file data was retired onto a freelist and freed after a
timeout, but the deadline was computed from a timestamp taken before
the blocking inotify read. That timestamp is stale by however long the
watcher waited for an event, so the deadline was routinely already in
the past and the data was freed while transactions still referenced it.

The patch addresses this issue by holding the data in a shared_ptr and
letting each transaction pin its own snapshot. The data now lives
exactly as long as it is referenced, which removes both the freelist
and the guess about how long a transaction can last.

Fixes: #8735

Copilot AI review requested due to automatic review settings July 27, 2026 16:27
@bneradt bneradt added this to the 11.0.0 milestone Jul 27, 2026
@bneradt bneradt self-assigned this Jul 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Replaced file data was retired onto a freelist and freed after a
timeout, but the deadline was computed from a timestamp taken before
the blocking inotify read. That timestamp is stale by however long the
watcher waited for an event, so the deadline was routinely already in
the past and the data was freed while transactions still referenced it.

The patch addresses this issue by holding the data in a shared_ptr and
letting each transaction pin its own snapshot. The data now lives
exactly as long as it is referenced, which removes both the freelist
and the guess about how long a transaction can last.

Fixes: apache#8735

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@bneradt
bneradt force-pushed the healthchecks-use-after-free branch from 79b3c22 to 5429a3b Compare July 27, 2026 16:33
@moonchen
moonchen requested a review from Copilot July 27, 2026 21:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment on lines 132 to 137
if (nullptr != (fd = fopen(info->fname, "r"))) {
data->exists = 1;
do {
data->b_len = fread(data->body, 1, MAX_BODY_LEN, fd);
} while (!feof(fd)); /* Only save the last 16KB of the file ... */
fclose(fd);
Comment on lines +83 to +103
/* Take a reference to the current data for this health check file. */
HCFileDataPtr
get_data()
{
std::lock_guard<std::mutex> lock{_data_mutex};
return _data;
}

/* Replace the current data for this health check file. Snapshots handed out by get_data() stay
valid until their last reference is dropped. */
void
set_data(HCFileDataPtr data)
{
std::lock_guard<std::mutex> lock{_data_mutex};
_data = std::move(data);
}

private:
std::mutex _data_mutex; /* Protects @a _data */
HCFileDataPtr _data; /* Holds the current data for this health check file */
};

@moonchen moonchen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status
Status: No status

Development

Successfully merging this pull request may close these issues.

[Healthcheck] ASAN reports use after free

3 participants