-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Fix crash during lua script defrag #14319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🎉 Snyk checks have passed. No issues have been found so far.✅ security/snyk check is complete. No issues have been found. (View Details) ✅ license/snyk check is complete. No issues have been found. (View Details) |
New Issues (1)Checkmarx found the following issues in this Pull Request
|
Probably needs a backported as far as 7.4. |
so now this PR just contains 2 bug fixes:
both issues could have caused crashes, and this small fix should be backported. and IIRC there are other improvements (defragging the list nodes and more), that can be done in another PR.. |
Update the top comment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes two critical crashes that occur during Lua script defragmentation. The primary issue is that active defragmentation can relocate luaScript structures to new memory locations while scripts are executing, causing segmentation faults when accessing the original memory addresses.
- Restricts defragmentation to only occur during AOF loading to prevent interference with executing scripts
- Adds callback to update LRU list node pointers when Lua script keys are reallocated during defragmentation
- Reverts previous temporary defragmentation disable logic during database flush operations
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/server.c | Limits defragmentation to AOF loading context only |
src/replication.c | Removes temporary defrag disable logic during replication |
src/defrag.c | Adds callback to update LRU node pointers for Lua scripts |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
@oranagra i found that this PR is not enough, aof loading may loading a long run lua script.😯 |
not with newly generated AOF files, in which scripts propagate effects rather than scripts. |
This PR fixes two defrag issues. 1. Fix a use-after-free issue caused by updating dictionary keys after a pubsub channel is reallocated. This issue was introduced by #13058 1. Fix potential use-after-free for lua during AOF loading with defrag This issue was introduced by #13058 This fix follows #14319 This PR updates the LuaScript LRU list before script execution to prevent accessing a potentially invalidated pointer after long-running scripts.
This PR fixes two crashes due to the defragmentation of the Lua script, which were by redis#13108 1. During long-running Lua script execution, active defragmentation may be triggered, causing the luaScript structure to be reallocated to a new memory location, then we access `l->node`(may be reallocatedd) after script execution to update the Lua LRU list. In this PR, we don't defrag during blocked scripts, so we don't mess up the LRU update when the script ends. Note that defrag is now only permitted during loading. This PR also reverts the changes made by redis#14274. 2. Forgot to update the Lua LUR list node's value. Since `lua_scripts_lru_list` node stores a pointer to the `lua_script`'s key, we also need to update `node->value` when the key is reallocated. In this PR, after performing defragmentation on a Lua script, if the script is in the LRU list, its reference in the LRU list will be unconditionally updated.
This PR fixes two defrag issues. 1. Fix a use-after-free issue caused by updating dictionary keys after a pubsub channel is reallocated. This issue was introduced by redis#13058 1. Fix potential use-after-free for lua during AOF loading with defrag This issue was introduced by redis#13058 This fix follows redis#14319 This PR updates the LuaScript LRU list before script execution to prevent accessing a potentially invalidated pointer after long-running scripts.
This PR fixes two crashes due to the defragmentation of the Lua script, which were by redis#13108 1. During long-running Lua script execution, active defragmentation may be triggered, causing the luaScript structure to be reallocated to a new memory location, then we access `l->node`(may be reallocatedd) after script execution to update the Lua LRU list. In this PR, we don't defrag during blocked scripts, so we don't mess up the LRU update when the script ends. Note that defrag is now only permitted during loading. This PR also reverts the changes made by redis#14274. 2. Forgot to update the Lua LUR list node's value. Since `lua_scripts_lru_list` node stores a pointer to the `lua_script`'s key, we also need to update `node->value` when the key is reallocated. In this PR, after performing defragmentation on a Lua script, if the script is in the LRU list, its reference in the LRU list will be unconditionally updated.
This PR fixes two defrag issues. 1. Fix a use-after-free issue caused by updating dictionary keys after a pubsub channel is reallocated. This issue was introduced by redis#13058 1. Fix potential use-after-free for lua during AOF loading with defrag This issue was introduced by redis#13058 This fix follows redis#14319 This PR updates the LuaScript LRU list before script execution to prevent accessing a potentially invalidated pointer after long-running scripts.
This PR fixes two crashes due to the defragmentation of the Lua script, which were by redis#13108 1. During long-running Lua script execution, active defragmentation may be triggered, causing the luaScript structure to be reallocated to a new memory location, then we access `l->node`(may be reallocatedd) after script execution to update the Lua LRU list. In this PR, we don't defrag during blocked scripts, so we don't mess up the LRU update when the script ends. Note that defrag is now only permitted during loading. This PR also reverts the changes made by redis#14274. 2. Forgot to update the Lua LUR list node's value. Since `lua_scripts_lru_list` node stores a pointer to the `lua_script`'s key, we also need to update `node->value` when the key is reallocated. In this PR, after performing defragmentation on a Lua script, if the script is in the LRU list, its reference in the LRU list will be unconditionally updated.
This PR fixes two defrag issues. 1. Fix a use-after-free issue caused by updating dictionary keys after a pubsub channel is reallocated. This issue was introduced by redis#13058 2. Fix potential use-after-free for lua during AOF loading with defrag This issue was introduced by redis#13058 This fix follows redis#14319 This PR updates the LuaScript LRU list before script execution to prevent accessing a potentially invalidated pointer after long-running scripts.
This PR fixes two crashes due to the defragmentation of the Lua script, which were by #13108
l->node
(may be reallocatedd) after script execution to update the Lua LRU list.In this PR, we don't defrag during blocked scripts, so we don't mess up the LRU update when the script ends.
Note that defrag is now only permitted during loading.
This PR also reverts the changes made by Prevent active defrag from triggering during replicaof db flush #14274.
crash report:
Since
lua_scripts_lru_list
node stores a pointer to thelua_script
's key, we also need to updatenode->value
when the key is reallocated.In this PR, after performing defragmentation on a Lua script, if the script is in the LRU list, its reference in the LRU list will be unconditionally updated.
crash report: