Skip to content

rgw/posix: fix use-after-free in read_obj_policy - #2

Merged
mattbenjamin merged 1 commit into
linuxbox2:wip-posix-nsfs-accts-notify-sse-miscfrom
mkogan1:wip-posix-nsfs-accts-notify-sse-misc--fix-T77597
Jun 24, 2026
Merged

mattbenjamin merged 1 commit into
linuxbox2:wip-posix-nsfs-accts-notify-sse-miscfrom
mkogan1:wip-posix-nsfs-accts-notify-sse-misc--fix-T77597

Conversation

@mkogan1

@mkogan1 mkogan1 commented Jun 23, 2026

Copy link
Copy Markdown

and stale cache in multipart list_parts

In read_obj_policy(), the MultipartUpload was scoped inside the if-block, and its shadow bucket was destroyed while mpobj still held a dangling pointer to it. Moving the declaration to the function scope keeps the shadow bucket alive for the duration of the call, fixing a SIGSEGV in
POSIXObject::stat() during multipart part uploads.

In POSIXMultipartUpload::list_parts(), the bucket cache for the shadow directory could be filled before parts were uploaded (e.g. by a ListParts call during upload), causing CompleteMultipart to see zero parts. Invalidating the shadow bucket cache before listing ensures parts written to disk are always found.

Fixes: https://tracker.ceph.com/issues/77597

and stale cache in multipart list_parts

In read_obj_policy(), the MultipartUpload was scoped inside the
if-block, and its shadow bucket was destroyed while mpobj still
held a dangling pointer to it. Moving the declaration to the
function scope keeps the shadow bucket alive for the duration
of the call, fixing a SIGSEGV in
POSIXObject::stat() during multipart part uploads.

In POSIXMultipartUpload::list_parts(), the bucket cache for the
shadow directory could be filled before parts were uploaded (e.g.
by a ListParts call during upload), causing CompleteMultipart to
see zero parts. Invalidating the shadow bucket cache before
listing ensures parts written to disk are always found.

Fixes: https://tracker.ceph.com/issues/77597

Signed-off-by: Mark Kogan <[email protected]>
@mkogan1

mkogan1 commented Jun 23, 2026

Copy link
Copy Markdown
Author

before this commit - a SEGF occures on the tests suite > AWS4 tests > AWS4Test.testDownloadHLAPIAWS4 :

image

gdb:
image

after this commit, all the java s3 tests pass:
image

mattbenjamin pushed a commit that referenced this pull request Jun 24, 2026
…tive list

unittest_posix_bucket_cache failed under LeakSanitizer:

  ==40342==ERROR: LeakSanitizer: detected memory leaks
  Direct leak of 248 byte(s) in 1 object(s) allocated from:
      #1 BucketCacheEntry<>::Factory::alloc() src/rgw/driver/posix/bucket_cache.h:114
      #2 cohort::lru::LRU<std::mutex>::insert(...) src/common/cohort_lru.h:269
      ceph#3 BucketCache<>::get_bucket(...) src/rgw/driver/posix/bucket_cache.h:352
      ceph#4 BucketCache<>::list_bucket(...) src/rgw/driver/posix/bucket_cache.h:437
      ceph#5 BucketCacheFixtureDefault_ListTDir1_Test::TestBody() src/test/rgw/test_posix_bucket_cache.cc:199

The leaked object is a BucketCacheEntry the suite never frees at exit.  The
corruption behind it is a race in the multithreaded ListThreads test, so the
leak is intermittent and does not show on every run.

LRU::unref() moves an object from the non-evictable active list to the evictable
q when its last initial ref is dropped, but it never cleared the object's active
flag.  Each Object has a single intrusive lane hook, so the next ref()/unref()
read the stale flag and erased the object from the wrong list, active instead of
q.  That corrupts both lanes' constant_time_size counters and leaves the entry
orphaned off the lanes.  BucketCache's teardown drains the lanes to free their
entries, so it never frees that one, and LeakSanitizer flags it.

Clear the flag when the object moves to q so it always tracks the list it is on.
The leak no longer reproduces.

Signed-off-by: Kefu Chai <[email protected]>
Signed-off-by: Matt Benjamin <[email protected]>

@mattbenjamin mattbenjamin left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

lgtm

@mattbenjamin
mattbenjamin merged commit 929359d into linuxbox2:wip-posix-nsfs-accts-notify-sse-misc Jun 24, 2026
mattbenjamin pushed a commit that referenced this pull request Jun 25, 2026
…tive list

unittest_posix_bucket_cache failed under LeakSanitizer:

  ==40342==ERROR: LeakSanitizer: detected memory leaks
  Direct leak of 248 byte(s) in 1 object(s) allocated from:
      #1 BucketCacheEntry<>::Factory::alloc() src/rgw/driver/posix/bucket_cache.h:114
      #2 cohort::lru::LRU<std::mutex>::insert(...) src/common/cohort_lru.h:269
      ceph#3 BucketCache<>::get_bucket(...) src/rgw/driver/posix/bucket_cache.h:352
      ceph#4 BucketCache<>::list_bucket(...) src/rgw/driver/posix/bucket_cache.h:437
      ceph#5 BucketCacheFixtureDefault_ListTDir1_Test::TestBody() src/test/rgw/test_posix_bucket_cache.cc:199

The leaked object is a BucketCacheEntry the suite never frees at exit.  The
corruption behind it is a race in the multithreaded ListThreads test, so the
leak is intermittent and does not show on every run.

LRU::unref() moves an object from the non-evictable active list to the evictable
q when its last initial ref is dropped, but it never cleared the object's active
flag.  Each Object has a single intrusive lane hook, so the next ref()/unref()
read the stale flag and erased the object from the wrong list, active instead of
q.  That corrupts both lanes' constant_time_size counters and leaves the entry
orphaned off the lanes.  BucketCache's teardown drains the lanes to free their
entries, so it never frees that one, and LeakSanitizer flags it.

Clear the flag when the object moves to q so it always tracks the list it is on.
The leak no longer reproduces.

Signed-off-by: Kefu Chai <[email protected]>
Signed-off-by: Matt Benjamin <[email protected]>
mattbenjamin pushed a commit that referenced this pull request Jul 14, 2026
…tive list

unittest_posix_bucket_cache failed under LeakSanitizer:

  ==40342==ERROR: LeakSanitizer: detected memory leaks
  Direct leak of 248 byte(s) in 1 object(s) allocated from:
      #1 BucketCacheEntry<>::Factory::alloc() src/rgw/driver/posix/bucket_cache.h:114
      #2 cohort::lru::LRU<std::mutex>::insert(...) src/common/cohort_lru.h:269
      ceph#3 BucketCache<>::get_bucket(...) src/rgw/driver/posix/bucket_cache.h:352
      ceph#4 BucketCache<>::list_bucket(...) src/rgw/driver/posix/bucket_cache.h:437
      ceph#5 BucketCacheFixtureDefault_ListTDir1_Test::TestBody() src/test/rgw/test_posix_bucket_cache.cc:199

The leaked object is a BucketCacheEntry the suite never frees at exit.  The
corruption behind it is a race in the multithreaded ListThreads test, so the
leak is intermittent and does not show on every run.

LRU::unref() moves an object from the non-evictable active list to the evictable
q when its last initial ref is dropped, but it never cleared the object's active
flag.  Each Object has a single intrusive lane hook, so the next ref()/unref()
read the stale flag and erased the object from the wrong list, active instead of
q.  That corrupts both lanes' constant_time_size counters and leaves the entry
orphaned off the lanes.  BucketCache's teardown drains the lanes to free their
entries, so it never frees that one, and LeakSanitizer flags it.

Clear the flag when the object moves to q so it always tracks the list it is on.
The leak no longer reproduces.

Signed-off-by: Kefu Chai <[email protected]>
Signed-off-by: Matt Benjamin <[email protected]>
mattbenjamin pushed a commit that referenced this pull request Nov 13, 2026
…tive list

unittest_posix_bucket_cache failed under LeakSanitizer:

  ==40342==ERROR: LeakSanitizer: detected memory leaks
  Direct leak of 248 byte(s) in 1 object(s) allocated from:
      #1 BucketCacheEntry<>::Factory::alloc() src/rgw/driver/posix/bucket_cache.h:114
      #2 cohort::lru::LRU<std::mutex>::insert(...) src/common/cohort_lru.h:269
      ceph#3 BucketCache<>::get_bucket(...) src/rgw/driver/posix/bucket_cache.h:352
      ceph#4 BucketCache<>::list_bucket(...) src/rgw/driver/posix/bucket_cache.h:437
      ceph#5 BucketCacheFixtureDefault_ListTDir1_Test::TestBody() src/test/rgw/test_posix_bucket_cache.cc:199

The leaked object is a BucketCacheEntry the suite never frees at exit.  The
corruption behind it is a race in the multithreaded ListThreads test, so the
leak is intermittent and does not show on every run.

LRU::unref() moves an object from the non-evictable active list to the evictable
q when its last initial ref is dropped, but it never cleared the object's active
flag.  Each Object has a single intrusive lane hook, so the next ref()/unref()
read the stale flag and erased the object from the wrong list, active instead of
q.  That corrupts both lanes' constant_time_size counters and leaves the entry
orphaned off the lanes.  BucketCache's teardown drains the lanes to free their
entries, so it never frees that one, and LeakSanitizer flags it.

Clear the flag when the object moves to q so it always tracks the list it is on.
The leak no longer reproduces.

Signed-off-by: Kefu Chai <[email protected]>
Signed-off-by: Matt Benjamin <[email protected]>
Signed-off-by: Daniel Gryniewicz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants