Skip to contentSkip to conversation

redis: fix CVE-2024-46981

PATCH New dchellam 1 participant 2 messages Feb 4, 2025

lore
Share & tools
lore

dchellam

author
#0 lore raw

PATCH 1/2 redis: fix CVE-2024-46981

From: Divya Chellam <[email protected]>

Redis is an open source, in-memory database that persists on disk. An authenticated user may use a specially crafted Lua script to manipulate the garbage collector and potentially lead to remote code execution. The problem is fixed in 7.4.2, 7.2.7, and 6.2.17. An additional workaround to mitigate the problem without patching the redis-server executable is to prevent users from executing Lua scripts. This can be done using ACL to restrict EVAL and EVALSHA commands.

Reference:
https://nvd.nist.gov/vuln/detail/CVE-2024-46981

Upstream-patch:
https://github.com/redis/redis/commit/e344b2b5879aa52870e6838212dfb78b7968fcbf

---
 .../redis/redis-7.0.13/CVE-2024-46981.patch   | 32 +++++++++++++++
 .../redis/redis/CVE-2024-46981.patch          | 39 +++++++++++++++++++
 .../recipes-extended/redis/redis_6.2.12.bb    |  1 +
 .../recipes-extended/redis/redis_7.0.13.bb    |  1 +
 4 files changed, 73 insertions(+)
 create mode 100644 meta-oe/recipes-extended/redis/redis-7.0.13/CVE-2024-46981.patch
 create mode 100644 meta-oe/recipes-extended/redis/redis/CVE-2024-46981.patch
meta-oe/recipes-extended/redis/redis-7.0.13/CVE-2024-46981.patch new file +32 -0
new file mode 100644
index 0000000000..870ef71f52
@@ -0,0 +1,32 @@
+From e344b2b5879aa52870e6838212dfb78b7968fcbf Mon Sep 17 00:00:00 2001
+From: YaacovHazan <[email protected]>
+Date: Sun, 15 Dec 2024 21:33:11 +0200
+Subject: [PATCH] Fix LUA garbage collector (CVE-2024-46981) 
+
+Reset GC state before closing the lua VM to prevent user data 
+to be wrongly freed while still might be used on destructor callbacks.
+
+CVE: CVE-2024-46981
+
+Upstream-Status: Backport [https://github.com/redis/redis/commit/e344b2b5879aa52870e6838212dfb78b7968fcbf]
+
+Signed-off-by: Divya Chellam <[email protected]>
+---
+ src/eval.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/src/eval.c b/src/eval.c
+index 8190856..a562335 100644
+--- a/src/eval.c
++++ b/src/eval.c
+@@ -273,6 +273,7 @@ void scriptingRelease(int async) {
+     else
+         dictRelease(lctx.lua_scripts);
+     lctx.lua_scripts_mem = 0;
++    lua_gc(lctx.lua, LUA_GCCOLLECT, 0);
+     lua_close(lctx.lua);
+ }
+ 
+-- 
+2.40.0
+
meta-oe/recipes-extended/redis/redis/CVE-2024-46981.patch new file +39 -0
new file mode 100644
index 0000000000..c02dd21271
@@ -0,0 +1,39 @@
+From e344b2b5879aa52870e6838212dfb78b7968fcbf Mon Sep 17 00:00:00 2001
+From: YaacovHazan <[email protected]>
+Date: Sun, 15 Dec 2024 21:33:11 +0200
+Subject: [PATCH] Fix LUA garbage collector (CVE-2024-46981)
+
+Reset GC state before closing the lua VM to prevent user data
+to be wrongly freed while still might be used on destructor callbacks.
+
+Conflicts:
+Since luaCtx lctx structure  introduced in later versions [1]
+used already existed redisServer server structure.
+
+Reference:
+[1] https://github.com/redis/redis/commit/e0cd580aefe13e49df802fec5135e4f22d46e758
+
+CVE: CVE-2024-46981
+
+Upstream-Status: Backport [https://github.com/redis/redis/commit/e344b2b5879aa52870e6838212dfb78b7968fcbf]
+
+Signed-off-by: Divya Chellam <[email protected]>
+---
+ src/scripting.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/src/scripting.c b/src/scripting.c
+index 9b926e8..656d4dd 100644
+--- a/src/scripting.c
++++ b/src/scripting.c
+@@ -1467,6 +1467,7 @@ void scriptingRelease(int async) {
+     else
+         dictRelease(server.lua_scripts);
+     server.lua_scripts_mem = 0;
++    lua_gc(server.lua, LUA_GCCOLLECT, 0);
+     lua_close(server.lua);
+ }
+ 
+-- 
+2.40.0
+
meta-oe/recipes-extended/redis/redis_6.2.12.bb +1 -0
index a13dfdbe45..0fdd3da327 100644
@@ -19,6 +19,7 @@ SRC_URI = "http://download.redis.io/releases/${BP}.tar.gz \
            file://CVE-2023-45145.patch \
            file://CVE-2024-31228.patch \
            file://CVE-2024-31449.patch \
+           file://CVE-2024-46981.patch \
            "
 SRC_URI[sha256sum] = "75352eef41e97e84bfa94292cbac79e5add5345fc79787df5cbdff703353fb1b"
 
meta-oe/recipes-extended/redis/redis_7.0.13.bb +1 -0
index fa1716a192..3535da9664 100644
@@ -21,6 +21,7 @@ SRC_URI = "http://download.redis.io/releases/${BP}.tar.gz \
            file://CVE-2024-31227.patch \
            file://CVE-2024-31228.patch \
            file://CVE-2024-31449.patch \
+           file://CVE-2024-46981.patch \
            "
 SRC_URI[sha256sum] = "97065774d5fb8388eb0d8913458decfcb167d356e40d31dd01cd30c1cc391673"
 
Signature · 1 line
2.40.0
author
#1 lore raw

PATCH 2/2 redis: fix CVE-2024-51741

From: Divya Chellam <[email protected]>

Redis is an open source, in-memory database that persists on disk. An authenticated with sufficient privileges may create a malformed ACL selector which, when accessed, triggers a server panic and subsequent denial of service. The problem is fixed in Redis 7.2.7 and 7.4.2.

Reference:
https://nvd.nist.gov/vuln/detail/CVE-2024-51741

Upstream-patch:
https://github.com/redis/redis/commit/15e212bf69de28d2b4585aa79cc2a40f49e4a94d

---
 .../redis/redis-7.0.13/CVE-2024-51741.patch   | 89 +++++++++++++++++++
 .../recipes-extended/redis/redis_7.0.13.bb    |  1 +
 2 files changed, 90 insertions(+)
 create mode 100644 meta-oe/recipes-extended/redis/redis-7.0.13/CVE-2024-51741.patch
meta-oe/recipes-extended/redis/redis-7.0.13/CVE-2024-51741.patch new file +89 -0
new file mode 100644
index 0000000000..e3a43fe896
@@ -0,0 +1,89 @@
+From 15e212bf69de28d2b4585aa79cc2a40f49e4a94d Mon Sep 17 00:00:00 2001
+From: YaacovHazan <[email protected]>
+Date: Sun, 15 Dec 2024 11:27:48 +0200
+Subject: [PATCH] Fix Read/Write key pattern selector (CVE-2024-51741)
+
+The '%' rule must contain one or both of R/W
+
+CVE: CVE-2024-51741
+
+Upstream-Status: Backport [https://github.com/redis/redis/commit/15e212bf69de28d2b4585aa79cc2a40f49e4a94d]
+
+Signed-off-by: Divya Chellam <[email protected]>
+---
+ src/acl.c             | 11 ++++++++---
+ tests/unit/acl-v2.tcl | 26 ++++++++++++++++++++++++++
+ 2 files changed, 34 insertions(+), 3 deletions(-)
+
+diff --git a/src/acl.c b/src/acl.c
+index 6b53d90..ed6dc97 100644
+--- a/src/acl.c
++++ b/src/acl.c
+@@ -1031,19 +1031,24 @@ int ACLSetSelector(aclSelector *selector, const char* op, size_t oplen) {
+         int flags = 0;
+         size_t offset = 1;
+         if (op[0] == '%') {
++            int perm_ok = 1;
+             for (; offset < oplen; offset++) {
+                 if (toupper(op[offset]) == 'R' && !(flags & ACL_READ_PERMISSION)) {
+                     flags |= ACL_READ_PERMISSION;
+                 } else if (toupper(op[offset]) == 'W' && !(flags & ACL_WRITE_PERMISSION)) {
+                     flags |= ACL_WRITE_PERMISSION;
+-                } else if (op[offset] == '~' && flags) {
++                } else if (op[offset] == '~') {
+                     offset++;
+                     break;
+                 } else {
+-                    errno = EINVAL;
+-                    return C_ERR;
++                    perm_ok = 0;
++                    break;
+                 }
+             }
++            if (!flags || !perm_ok) {
++                errno = EINVAL;
++                return C_ERR;
++            }
+         } else {
+             flags = ACL_ALL_PERMISSION;
+         }
+diff --git a/tests/unit/acl-v2.tcl b/tests/unit/acl-v2.tcl
+index d836f9c..0b83b89 100644
+--- a/tests/unit/acl-v2.tcl
++++ b/tests/unit/acl-v2.tcl
+@@ -107,6 +107,32 @@ start_server {tags {"acl external:skip"}} {
+         assert_match "*NOPERM*keys*" $err
+     }
+ 
++    test {Validate read and write permissions format - empty permission} {
++        catch {r ACL SETUSER key-permission-RW %~} err
++        set err
++    } {ERR Error in ACL SETUSER modifier '%~': Syntax error}
++
++    test {Validate read and write permissions format - empty selector} {
++        catch {r ACL SETUSER key-permission-RW %} err
++        set err
++    } {ERR Error in ACL SETUSER modifier '%': Syntax error}
++
++    test {Validate read and write permissions format - empty pattern} {
++        # Empty pattern results with R/W access to no key
++        r ACL SETUSER key-permission-RW on nopass %RW~ +@all
++        $r2 auth key-permission-RW password
++        catch {$r2 SET x 5} err
++        set err
++    } {NOPERM No permissions to access a key}
++
++    test {Validate read and write permissions format - no pattern} {
++        # No pattern results with R/W access to no key (currently we accept this syntax error)
++        r ACL SETUSER key-permission-RW on nopass %RW +@all
++        $r2 auth key-permission-RW password
++        catch {$r2 SET x 5} err
++        set err
++    } {NOPERM No permissions to access a key}
++
+     test {Test separate read and write permissions on different selectors are not additive} {
+         r ACL SETUSER key-permission-RW-selector on nopass "(%R~read* +@all)" "(%W~write* +@all)"
+         $r2 auth key-permission-RW-selector password
+-- 
+2.40.0
+
meta-oe/recipes-extended/redis/redis_7.0.13.bb +1 -0
index 3535da9664..e7bff9b4ec 100644
@@ -22,6 +22,7 @@ SRC_URI = "http://download.redis.io/releases/${BP}.tar.gz \
            file://CVE-2024-31228.patch \
            file://CVE-2024-31449.patch \
            file://CVE-2024-46981.patch \
+           file://CVE-2024-51741.patch \
            "
 SRC_URI[sha256sum] = "97065774d5fb8388eb0d8913458decfcb167d356e40d31dd01cd30c1cc391673"
 
Signature · 1 line
2.40.0