From 5f4e982ea8d3ef2d3fb72ec92482de8ab0c632a9 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 17 Oct 2024 16:27:53 -0400 Subject: [PATCH] kernel/cache: Acquire store references in PrecacheIO. If the file in question is deleted while we are performing asynchronous I/O, and there is nothing else left with a reference to it, then the underlying vnode could wind up getting deleted from under us, since the cache does not maintain a reference to the store unless there are active mappings (areas) associated with the cache. Should fix #19122. At least, I couldn't find any other places that performed asynchronous I/O without properly acquiring and releasing references to the underlying vnode besides this one. --- src/system/kernel/cache/file_cache.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/system/kernel/cache/file_cache.cpp b/src/system/kernel/cache/file_cache.cpp index 5ef0929165..4368ab94e4 100644 --- a/src/system/kernel/cache/file_cache.cpp +++ b/src/system/kernel/cache/file_cache.cpp @@ -128,6 +128,7 @@ PrecacheIO::PrecacheIO(file_cache_ref* ref, off_t offset, generic_size_t size) { fPageCount = (size + B_PAGE_SIZE - 1) / B_PAGE_SIZE; fCache->AcquireRefLocked(); + fCache->AcquireStoreRef(); } @@ -135,6 +136,7 @@ PrecacheIO::~PrecacheIO() { delete[] fPages; delete[] fVecs; + fCache->ReleaseStoreRef(); fCache->ReleaseRefLocked(); }