From 356555c0ea315dc7c11315a12e24496446e149d7 Mon Sep 17 00:00:00 2001 From: Binbin Date: Mon, 29 Jan 2024 14:31:41 +0800 Subject: [PATCH] Fix maxmemory-samples stack overflow crash in evictionPoolPopulate, limit its value to [1,64] We have not limited the value of maxmemory-samples in the past, it can be set very large. If it is set very large, we will have stack overflow in evictionPoolPopulate when we trigger the key eviction. There is no reason for this config to be set too high, so just limit its range to [1,64]. --- redis.conf | 3 ++- src/config.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/redis.conf b/redis.conf index 333430ae7c9..65e01b0742e 100644 --- a/redis.conf +++ b/redis.conf @@ -1163,7 +1163,8 @@ acllog-max-len 128 # configuration directive. # # The default of 5 produces good enough results. 10 Approximates very closely -# true LRU but costs more CPU. 3 is faster but not very accurate. +# true LRU but costs more CPU. 3 is faster but not very accurate. The maximum +# value that can be set is 64. # # maxmemory-samples 5 diff --git a/src/config.c b/src/config.c index e5108558fcb..96527c62a71 100644 --- a/src/config.c +++ b/src/config.c @@ -3172,7 +3172,7 @@ standardConfig static_configs[] = { createIntConfig("lfu-decay-time", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.lfu_decay_time, 1, INTEGER_CONFIG, NULL, NULL), createIntConfig("replica-priority", "slave-priority", MODIFIABLE_CONFIG, 0, INT_MAX, server.slave_priority, 100, INTEGER_CONFIG, NULL, NULL), createIntConfig("repl-diskless-sync-delay", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.repl_diskless_sync_delay, 5, INTEGER_CONFIG, NULL, NULL), - createIntConfig("maxmemory-samples", NULL, MODIFIABLE_CONFIG, 1, INT_MAX, server.maxmemory_samples, 5, INTEGER_CONFIG, NULL, NULL), + createIntConfig("maxmemory-samples", NULL, MODIFIABLE_CONFIG, 1, 64, server.maxmemory_samples, 5, INTEGER_CONFIG, NULL, NULL), createIntConfig("maxmemory-eviction-tenacity", NULL, MODIFIABLE_CONFIG, 0, 100, server.maxmemory_eviction_tenacity, 10, INTEGER_CONFIG, NULL, NULL), createIntConfig("timeout", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.maxidletime, 0, INTEGER_CONFIG, NULL, NULL), /* Default client timeout: infinite */ createIntConfig("replica-announce-port", "slave-announce-port", MODIFIABLE_CONFIG, 0, 65535, server.slave_announce_port, 0, INTEGER_CONFIG, NULL, NULL),