avoid possible use-after-free with module KSN changes (#13875)
CI / test-ubuntu-latest (push) Has been cancelled Details
CI / test-sanitizer-address (push) Has been cancelled Details
CI / build-debian-old (push) Has been cancelled Details
CI / build-macos-latest (push) Has been cancelled Details
CI / build-32bit (push) Has been cancelled Details
CI / build-libc-malloc (push) Has been cancelled Details
CI / build-centos-jemalloc (push) Has been cancelled Details
CI / build-old-chain-jemalloc (push) Has been cancelled Details
Codecov / code-coverage (push) Has been cancelled Details
External Server Tests / test-external-standalone (push) Has been cancelled Details
External Server Tests / test-external-cluster (push) Has been cancelled Details
External Server Tests / test-external-nodebug (push) Has been cancelled Details
Spellcheck / Spellcheck (push) Has been cancelled Details

in #13505, we changed the code to use the string value of the key rather
than the integer value on the stack, but we have a test in
unit/moduleapi/keyspace_events that uses keyspace notification hook to
modify the value with RM_StringDMA, which can cause this value to be
released before used. the reason it didn't happen so far is because we
were using shared integers, so releasing the object doesn't free it.
This commit is contained in:
Oran Agra 2025-03-24 12:24:52 +02:00 committed by GitHub
parent 319bbcc1a7
commit 2a189709e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 1 deletions

View File

@ -612,10 +612,10 @@ void incrDecrCommand(client *c, long long incr) {
dbAdd(c->db,c->argv[1],new); dbAdd(c->db,c->argv[1],new);
} }
} }
addReplyLongLongFromStr(c,new);
signalModifiedKey(c,c->db,c->argv[1]); signalModifiedKey(c,c->db,c->argv[1]);
notifyKeyspaceEvent(NOTIFY_STRING,"incrby",c->argv[1],c->db->id); notifyKeyspaceEvent(NOTIFY_STRING,"incrby",c->argv[1],c->db->id);
server.dirty++; server.dirty++;
addReplyLongLongFromStr(c,new);
} }
void incrCommand(client *c) { void incrCommand(client *c) {

View File

@ -3,6 +3,10 @@ set testmodule [file normalize tests/modules/keyspace_events.so]
tags "modules" { tags "modules" {
start_server [list overrides [list loadmodule "$testmodule"]] { start_server [list overrides [list loadmodule "$testmodule"]] {
# avoid using shared integers, to increase the chance of detection heap issues
r config set maxmemory-policy allkeys-lru
r config set maxmemory 1gb
test {Test loaded key space event} { test {Test loaded key space event} {
r set x 1 r set x 1
r hset y f v r hset y f v