From 6de9a1c3096cb31300e4c251e97ed4151cca0edd Mon Sep 17 00:00:00 2001 From: Lukas Javorsky Date: Thu, 5 Mar 2026 13:13:02 +0100 Subject: [PATCH] Fix CONFIG REWRITE breaks configuration Reported as https://github.com/valkey-io/valkey/issues/2678 Using patch from https://github.com/valkey-io/valkey/pull/2689 Related: RHEL-153641 Fedora commit: https://src.fedoraproject.org/rpms/valkey/c/17ff7b914d8017de60d2d88ce40eb689087987e9?branch=f43 --- valkey-loadmod.patch | 147 +++++++++++++++++++++++++++++++++++++++++++ valkey.spec | 3 + 2 files changed, 150 insertions(+) create mode 100644 valkey-loadmod.patch diff --git a/valkey-loadmod.patch b/valkey-loadmod.patch new file mode 100644 index 0000000..3341863 --- /dev/null +++ b/valkey-loadmod.patch @@ -0,0 +1,147 @@ +Adapted for 8.1.4 from +https://github.com/valkey-io/valkey/pull/2689 + +diff -up ./src/config.c.loadmod ./src/config.c +--- ./src/config.c.loadmod 2025-10-03 21:17:43.000000000 +0200 ++++ ./src/config.c 2025-10-06 03:06:41.774448336 +0200 +@@ -438,6 +438,8 @@ static int updateClientOutputBufferLimit + * within conf file parsing. This is only needed to support the deprecated + * abnormal aggregate `save T C` functionality. Remove in the future. */ + static int reading_config_file; ++/* support detecting include vs main config file */ ++static int reading_include_file = 0; + + void loadServerConfigFromString(char *config) { + deprecatedConfig deprecated_configs[] = { +@@ -529,7 +531,9 @@ void loadServerConfigFromString(char *co + + /* Execute config directives */ + if (!strcasecmp(argv[0], "include") && argc == 2) { ++ reading_include_file = 1; + loadServerConfig(argv[1], 0, NULL); ++ reading_include_file = 0; + } else if (!strcasecmp(argv[0], "rename-command") && argc == 3) { + struct serverCommand *cmd = lookupCommandBySds(argv[1]); + +@@ -562,7 +566,7 @@ void loadServerConfigFromString(char *co + goto loaderr; + } + } else if (!strcasecmp(argv[0], "loadmodule") && argc >= 2) { +- moduleEnqueueLoadModule(argv[1], &argv[2], argc - 2); ++ moduleEnqueueLoadModule(argv[1], &argv[2], argc - 2, reading_include_file); + } else if (strchr(argv[0], '.')) { + if (argc < 2) { + err = "Module config specified without value"; +@@ -1579,7 +1583,7 @@ void rewriteConfigLoadmoduleOption(struc + while ((de = dictNext(di)) != NULL) { + struct ValkeyModule *module = dictGetVal(de); + line = moduleLoadQueueEntryToLoadmoduleOptionStr(module, "loadmodule"); +- rewriteConfigRewriteLine(state, "loadmodule", line, 1); ++ if (line) rewriteConfigRewriteLine(state, "loadmodule", line, 1); + } + dictReleaseIterator(di); + /* Mark "loadmodule" as processed in case modules is empty. */ +diff -up ./src/module.c.loadmod ./src/module.c +--- ./src/module.c.loadmod 2025-10-03 21:17:43.000000000 +0200 ++++ ./src/module.c 2025-10-06 03:05:36.498290506 +0200 +@@ -83,6 +83,7 @@ + + struct moduleLoadQueueEntry { + sds path; ++ int from_include; + int argc; + robj **argv; + }; +@@ -669,7 +670,7 @@ void freeClientModuleData(client *c) { + c->module_data = NULL; + } + +-void moduleEnqueueLoadModule(sds path, sds *argv, int argc) { ++void moduleEnqueueLoadModule(sds path, sds *argv, int argc, int from_include) { + int i; + struct moduleLoadQueueEntry *loadmod; + +@@ -677,6 +678,7 @@ void moduleEnqueueLoadModule(sds path, s + loadmod->argv = argc ? zmalloc(sizeof(robj *) * argc) : NULL; + loadmod->path = sdsnew(path); + loadmod->argc = argc; ++ loadmod->from_include = from_include; + for (i = 0; i < argc; i++) { + loadmod->argv[i] = createRawStringObject(argv[i], sdslen(argv[i])); + } +@@ -687,6 +689,10 @@ sds moduleLoadQueueEntryToLoadmoduleOpti + const char *config_option_str) { + sds line; + ++ if (module->loadmod->from_include) { ++ /* no need to add as already from config */ ++ return NULL; ++ } + line = sdsnew(config_option_str); + line = sdscatlen(line, " ", 1); + line = sdscatsds(line, module->loadmod->path); +@@ -12188,7 +12194,7 @@ void moduleLoadFromQueue(void) { + listRewind(server.loadmodule_queue, &li); + while ((ln = listNext(&li))) { + struct moduleLoadQueueEntry *loadmod = ln->value; +- if (moduleLoad(loadmod->path, (void **)loadmod->argv, loadmod->argc, 0) == C_ERR) { ++ if (moduleLoad(loadmod->path, (void **)loadmod->argv, loadmod->argc, 0, loadmod->from_include) == C_ERR) { + serverLog(LL_WARNING, "Can't load module from %s: server aborting", loadmod->path); + exit(1); + } +@@ -12369,7 +12375,7 @@ void moduleUnregisterCleanup(ValkeyModul + + /* Load a module and initialize it. On success C_OK is returned, otherwise + * C_ERR is returned. */ +-int moduleLoad(const char *path, void **module_argv, int module_argc, int is_loadex) { ++int moduleLoad(const char *path, void **module_argv, int module_argc, int is_loadex, int from_include) { + int (*onload)(void *, void **, int); + void *handle; + +@@ -12444,6 +12450,7 @@ int moduleLoad(const char *path, void ** + ctx.module->loadmod->path = sdsnew(path); + ctx.module->loadmod->argv = module_argc ? zmalloc(sizeof(robj *) * module_argc) : NULL; + ctx.module->loadmod->argc = module_argc; ++ ctx.module->loadmod->from_include = from_include; + for (int i = 0; i < module_argc; i++) { + ctx.module->loadmod->argv[i] = module_argv[i]; + incrRefCount(ctx.module->loadmod->argv[i]); +@@ -13361,7 +13368,7 @@ void moduleCommand(client *c) { + argv = &c->argv[3]; + } + +- if (moduleLoad(c->argv[2]->ptr, (void **)argv, argc, 0) == C_OK) ++ if (moduleLoad(c->argv[2]->ptr, (void **)argv, argc, 0, 0) == C_OK) + addReply(c, shared.ok); + else + addReplyError(c, "Error loading the extension. Please check the server logs."); +@@ -13376,7 +13383,7 @@ void moduleCommand(client *c) { + /* If this is a loadex command we want to populate server.module_configs_queue with + * sds NAME VALUE pairs. We also want to increment argv to just after ARGS, if supplied. */ + if (parseLoadexArguments((ValkeyModuleString ***)&argv, &argc) == VALKEYMODULE_OK && +- moduleLoad(c->argv[2]->ptr, (void **)argv, argc, 1) == C_OK) ++ moduleLoad(c->argv[2]->ptr, (void **)argv, argc, 1, 0) == C_OK) + addReply(c, shared.ok); + else { + dictEmpty(server.module_configs_queue, NULL); +diff -up ./src/module.h.loadmod ./src/module.h +--- ./src/module.h.loadmod 2025-10-03 21:17:43.000000000 +0200 ++++ ./src/module.h 2025-10-06 03:05:36.498698194 +0200 +@@ -169,7 +169,7 @@ static inline void moduleInitDigestConte + memset(mdvar->x, 0, sizeof(mdvar->x)); + } + +-void moduleEnqueueLoadModule(sds path, sds *argv, int argc); ++void moduleEnqueueLoadModule(sds path, sds *argv, int argc, int from_include); + sds moduleLoadQueueEntryToLoadmoduleOptionStr(ValkeyModule *module, + const char *config_option_str); + ValkeyModuleCtx *moduleAllocateContext(void); +@@ -180,7 +180,7 @@ void moduleFreeContext(ValkeyModuleCtx * + void moduleInitModulesSystem(void); + void moduleInitModulesSystemLast(void); + void modulesCron(void); +-int moduleLoad(const char *path, void **argv, int argc, int is_loadex); ++int moduleLoad(const char *path, void **argv, int argc, int is_loadex, int from_include); + int moduleUnload(sds name, const char **errmsg); + void moduleLoadFromQueue(void); + int moduleGetCommandKeysViaAPI(struct serverCommand *cmd, robj **argv, int argc, getKeysResult *result); diff --git a/valkey.spec b/valkey.spec index a2d9c0c..ec882de 100644 --- a/valkey.spec +++ b/valkey.spec @@ -22,6 +22,8 @@ Source8: macros.%{name} Source9: migrate_redis_to_valkey.sh Patch1: valkey-cve-2025-27151.patch +# Workaround to https://github.com/valkey-io/valkey/issues/2678 +Patch2: %{name}-loadmod.patch BuildRequires: make BuildRequires: gcc @@ -107,6 +109,7 @@ BuildArch: noarch %prep %setup -qn %{name}-%{version} %patch -P1 -p1 +%patch -P2 -p1 -b .loadmod mv deps/lua/COPYRIGHT COPYRIGHT-lua mv deps/jemalloc/COPYING COPYING-jemalloc