Skip to content

Conversation

@enjoy-binbin
Copy link
Contributor

@enjoy-binbin enjoy-binbin commented Mar 13, 2024

After #13072, there is an use-after-free error. In expireScanCallback, we
will delete the dict, and then in dictScan we will continue to use the dict,
like we will doing dictResumeRehashing(d) in the end, this casued an error.

In this PR, in freeDictIfNeeded, if the dict's pauserehash is set, don't
delete the dict yet, and then when scan returns try to delete it again.

At the same time, we noticed that there will be similar problems in iter.
We may also delete elements during the iteration process, causing the dict
to be deleted, so the part related to iter in the PR has also been modified.
dictResetIterator was also missing from the previous kvstoreIteratorNextDict,
we currently have no scenario that elements will be deleted in kvstoreIterator
process, deal with it together to avoid future problems. Added some simple
tests to verify the changes.

In addition, the modification in #13072 omitted initTempDb and emptyDbAsync,
and they were also added. This PR also remove the slow flag from the expire
test (consumes 1.3s) so that problems can be found in CI in the future.

After redis#13072, there is an use-after-free error. In expireScanCallback, we
will delete the dict, and then in dictScan we will continue to use the dict,
like we will doing `dictResumeRehashing(d)` in the end, this casued an error.

In this PR, in freeDictIfNeeded, if the dict's pauserehash is set, don't
delete the dict yet, and then when scan returns try to delete it again.
@oranagra
Copy link
Member

it's a shame this error made it passed the PR CI.
i understand it's because the test is marked as slow, i see it only takes 1.3 seconds, maybe we can remove the slow tag, or maybe we should make some effort to cover this code path in another, quicker test?

either way, let's not delay the fix. what's holding us back?

@enjoy-binbin
Copy link
Contributor Author

enjoy-binbin commented Mar 18, 2024

full daily: https://github.com/enjoy-binbin/redis/actions/runs/8322641194

ok, just 1.3s, i think we can remove the slow flag. I made some changes related to iter to respect the empty flag, please review.

@enjoy-binbin enjoy-binbin changed the title Fix dictionary use-after-free in active expire Fix dictionary use-after-free in active expire and make kvstore iter to respect EMPTY flag Mar 18, 2024
@oranagra oranagra merged commit 7b07042 into redis:unstable Mar 18, 2024
@enjoy-binbin enjoy-binbin deleted the fix_use_after_free branch March 18, 2024 15:58
funny-dog pushed a commit to funny-dog/redis that referenced this pull request Sep 17, 2025
…to respect EMPTY flag (redis#13135)

After redis#13072, there is an use-after-free error. In expireScanCallback, we
will delete the dict, and then in dictScan we will continue to use the dict,
like we will doing `dictResumeRehashing(d)` in the end, this casued an error.

In this PR, in freeDictIfNeeded, if the dict's pauserehash is set, don't
delete the dict yet, and then when scan returns try to delete it again.

At the same time, we noticed that there will be similar problems in iterator.
We may also delete elements during the iteration process, causing the dict
to be deleted, so the part related to iter in the PR has also been modified.
dictResetIterator was also missing from the previous kvstoreIteratorNextDict,
we currently have no scenario that elements will be deleted in kvstoreIterator
process, deal with it together to avoid future problems. Added some simple
tests to verify the changes.

In addition, the modification in redis#13072 omitted initTempDb and emptyDbAsync,
and they were also added. This PR also remove the slow flag from the expire
test (consumes 1.3s) so that problems can be found in CI in the future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants