mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:50:51 +01:00
[PR #2015] dstorage: harden staging_bytes overflow and StagingPool::Lease reuse (RT-DSTORAGE-STAGING-OVERFLOW-AND-REUSE) #2022
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#2022
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/2015
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/rt-dstorage-staging-overflow-and-reuse📝 Commits (1)
435d754dstorage: harden staging_bytes overflow and StagingPool::Lease reuse📊 Changes
2 files changed (+74 additions, -22 deletions)
View changed files
📝
runtime/shims/dstorage_staging.h(+51 -22)📝
runtime/test/dstorage_test.cpp(+23 -0)📄 Description
Claim:
RT-DSTORAGE-STAGING-OVERFLOW-AND-REUSE(claim comment#7170510712on #1608).Problem
In
runtime/shims/dstorage_staging.h:staging_bytes():pages()computedsize + sizeof(uint64_t) * (1 + (size - 1 + offset) / 65536)andstage()computedinput + outputwithout saturation, allowing extreme values to wrapuint64_tbelowStagingPool::limit.StagingPool::Leaseaccounting leak on reuse: callingtry_pair()oracquire()on aLeasethat already held a reservation overwrotebytes_without returning the previous reservation topool_.used_/pool_.helpers_, permanently leaking pool capacity and eventually deadlocking future waiters.notify_all()and%lluformat casts:acquire()and~Lease()calledpool_.changed_.notify_all()while still holdingpool_.mutex_(causing immediate lock re-contention in woken DirectStorage threads), and printeduint64_twith%lluwithout casting tounsigned long long.Fix
staging_bytes()pages()andstage()calculations saturating againstUINT64_MAX.held_inStagingPool::Lease: refuse duplicatetry_pair()while held, add explicitrelease()(called from~Lease()and before re-acquire()), and callnotify_all()after unlockingpool_.mutex_.pool_.peak_andlimittounsigned long longin tracestd::fprintfcalls.runtime/test/dstorage_test.cpp(test_staging_budget(), 0CMakeLists.txtedits) covering duplicatetry_pair,acquire(0)release, re-acquire, explicitrelease(), and largestaging_bytes()inputs.Verification
runtime/shims/dstorage_staging.h(including 4-thread concurrentStagingPoolstress tests and alltest_staging_budgetassertions) under minimal Win32 ABI stubs with:clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werrorclang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werrorclang++ -std=c++20 -O2 -Wall -Wextra -Werrorpython3 -I scripts/check_no_game_data.py runtime/shims/dstorage_staging.h runtime/test/dstorage_test.cppandpython3 -I tests/test_text_write_line_endings.py: all passed.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.