1. 20 Mar, 2023 1 commit
    • Ozan Tezcan's avatar
      Ignore RM_Call deny-oom flag if maxmemory is zero (#11319) · a3903221
      Ozan Tezcan authored
      If a command gets an OOM response and then if we set maxmemory to zero
      to disable the limit, server.pre_command_oom_state never gets updated
      and it stays true. As RM_Call() calls with "respect deny-oom" flag checks
      server.pre_command_oom_state, all calls will fail with OOM.
      
      Added server.maxmemory check in RM_Call() to process deny-oom flag
      only if maxmemory is configured.
      
      (cherry picked from commit 18920813)
      a3903221
  2. 28 Feb, 2023 15 commits
    • Oran Agra's avatar
      Redis 7.0.9 · 86920532
      Oran Agra authored
      86920532
    • Oran Agra's avatar
      Integer Overflow in RAND commands can lead to assertion (CVE-2023-25155) · 2a2a582e
      Oran Agra authored
      Issue happens when passing a negative long value that greater than
      the max positive value that the long can store.
      2a2a582e
    • Tom Levy's avatar
      String pattern matching had exponential time complexity on pathological patterns (CVE-2022-36021) · 08255525
      Tom Levy authored
      Authenticated users can use string matching commands with a
      specially crafted pattern to trigger a denial-of-service attack on Redis,
      causing it to hang and consume 100% CPU time.
      08255525
    • ranshid's avatar
      Fix possible memory corruption in FLUSHALL when a client watches more than one key (#11854) · 7091b495
      ranshid authored
      
      
      Avoid calling unwatchAllKeys when running touchAllWatchedKeysInDb (which was unnecessary)
      This can potentially lead to use-after-free and memory corruption when the next entry
      pointer held by the watched keys iterator is freed when unwatching all keys of a specific client.
      found with address sanitizer, added a test which will not always fail (depending on the random
      dict hashing seed)
      problem introduced in #9829 (Reids 7.0)
      Co-authored-by: default avatarOran Agra <oran@redislabs.com>
      (cherry picked from commit 18017df7)
      7091b495
    • Madelyn Olson's avatar
    • judeng's avatar
      add test case and comments for active expiry in the writeable replica (#11789) · feb796d3
      judeng authored
      This test case is to cover a edge scenario: when a writable replica enabled AOF
      at the same time, active expiry keys which was created in writable replicas should
      propagate to the AOF file, and some versions might crash (fixed by #11615).
      For details, please refer to #11778
      
      (cherry picked from commit 40659c34)
      feb796d3
    • zhaozhao.zz's avatar
      correct cluster inbound link keepalive time (#11785) · c2bedf2d
      zhaozhao.zz authored
      (cherry picked from commit a35e0837)
      c2bedf2d
    • guybe7's avatar
      SCAN/RANDOMKEY and lazy-expire (#11788) · 2db72059
      guybe7 authored
      Starting from Redis 7.0 (#9890) we started wrapping everything a command
       propagates with MULTI/EXEC. The problem is that both SCAN and RANDOMKEY can
      lazy-expire arbitrary keys (similar behavior to active-expire), and put DELs in a transaction.
      
      Fix: When these commands are called without a parent exec-unit (e.g. not in EVAL or
      MULTI) we avoid wrapping their DELs in a transaction (for the same reasons active-expire
      and eviction avoids a transaction)
      
      This PR adds a per-command flag that indicates that the command may touch arbitrary
      keys (not the ones in the arguments), and uses that flag to avoid the MULTI-EXEC.
      For now, this flag is internal, since we're considering other solutions for the future.
      
      Note for cluster mode: if SCAN/RANDOMKEY is inside EVAL/MULTI it can still cause the
      same situation (as it always did), but it won't cause a CROSSSLOT because replicas and AOF
      do not perform slot checks.
      The problem with the above is mainly for 3rd party ecosystem tools that propagate commands
      from master to master, or feed an AOF file with redis-cli into a master.
      This PR aims to fix the regression in redis 7.0, and we opened #11792 to try to handle the
      bigger problem with lazy expire better for another release.
      
      (cherry picked from commit fd82bccd)
      2db72059
    • Ran Shidlansik's avatar
      fix cluster propagation in case of disconnected cluster node, see #11752 · ab05b28b
      Ran Shidlansik authored
      The mentioned PR which was fixed before 7.2 needed these adjustments in
      order to fix the problem in redis 7.0.
      ab05b28b
    • Harkrishn Patro's avatar
      Propagate message to a node only if the cluster link is healthy. (#11752) · ca0b6cae
      Harkrishn Patro authored
      Currently while a sharded pubsub message publish tries to propagate the message across the cluster, a NULL check is missing for clusterLink. clusterLink could be NULL if the link is causing memory beyond the set threshold cluster-link-sendbuf-limit and server terminates the link.
      
      This change introduces two things:
      
      Avoids the engine crashes on the publishing node if a message is tried to be sent to a node and the link is NULL.
      Adds a debugging tool CLUSTERLINK KILL to terminate the clusterLink between two nodes.
      
      (cherry picked from commit fd397568)
      ca0b6cae
    • Binbin's avatar
      Document some fields history of CLIENT LIST command (#11729) · 5aaa1a27
      Binbin authored
      Change history:
      - `user` added in 6.0.0, 0f42447a
      - `argv-mem` and `tot-mem` added in 6.2.0, bea40e6a
      - `redir` added in 6.2.0, dd1f20ed
      - `resp` added in 7.0.0, 7c376398
      - `multi-mem` added in 7.0.0, 2753429c
      - `rbs` and `rbp` added in 7.0.0, 47c51d0c
      - `ssub` added in 7.0.3, 35c2ee87
      
      (cherry picked from commit e7f35edb)
      5aaa1a27
    • uriyage's avatar
      Optimization: sdsRemoveFreeSpace to avoid realloc on noop (#11766) · af80a4a5
      uriyage authored
      
      
      In #7875 (Redis 6.2), we changed the sds alloc to be the usable allocation
      size in order to:
      
      > reduce the need for realloc calls by making the sds implicitly take over
      the internal fragmentation
      
      This change was done most sds functions, excluding `sdsRemoveFreeSpace` and
      `sdsResize`, the reason is that in some places (e.g. clientsCronResizeQueryBuffer)
      we call sdsRemoveFreeSpace when we see excessive free space and want to trim it.
      so if we don't trim it exactly to size, the caller may still see excessive free space and
      call it again and again.
      
      However, this resulted in some excessive calls to realloc, even when there's no need
      and it's gonna be a no-op (e.g. when reducing 15 bytes allocation to 13).
      
      It turns out that a call for realloc with jemalloc can be expensive even if it ends up
      doing nothing, so this PR adds a check using `je_nallocx`, which is cheap to avoid
      the call for realloc.
      
      in addition to that this PR unifies sdsResize and sdsRemoveFreeSpace into common
      code. the difference between them was that sdsResize would avoid using SDS_TYPE_5,
      since it want to keep the string ready to be resized again, while sdsRemoveFreeSpace
      would permit using SDS_TYPE_5 and get an optimal memory consumption.
      now both methods take a `would_regrow` argument that makes it more explicit.
      
      the only actual impact of that is that in clientsCronResizeQueryBuffer we call both sdsResize
      and sdsRemoveFreeSpace for in different cases, and we now prevent the use of SDS_TYPE_5 in both.
      
      The new test that was added to cover this concern used to pass before this PR as well,
      this PR is just a performance optimization and cleanup.
      
      Benchmark:
      `redis-benchmark -c 100 -t set  -d 512 -P 10  -n  100000000`
      on i7-9850H with jemalloc, shows improvement from 1021k ops/sec to 1067k (average of 3 runs).
      some 4.5% improvement.
      Co-authored-by: default avatarOran Agra <oran@redislabs.com>
      (cherry picked from commit 46393f98)
      af80a4a5
    • Madelyn Olson's avatar
      Optimize the performance of cluster slots for non-continuous slots (#11745) · c0e064ef
      Madelyn Olson authored
      This change improves the performance of cluster slots by removing the deferring lengths that are used. Deferring lengths are used in two contexts, the first is for determining the number of replicas that serve a slot (Added in 6.2 as part of a different performance improvement) and the second is for determining the extra networking options for each node (Added in 7.0). For continuous slots, (e.g. 0-8196) this improvement is very negligible, however it becomes more significant when slots are not continuous (e.g. 0 2 4 6 etc) which can happen in production for various users.
      
      The `cluster slots` command is deprecated in favor of `cluster shards`, but since most clients don't support the new command yet I think it's important to not degrade performance here.
      
      Benchmarking shows about 2x improvement, however I wasn't able to get a coherent TPS number since the benchmark process was being saturated long before Redis was, so had to run with multiple benchmarks and merge results. If needed I can add this to our memtier framework. Instead the next section shows the number of usec per call from the benchmark results, which shows significant improvement as well as having a more coherent response in the CoB.
      
      | | New Code | Old Code | % Improvements
      |----|----|----- |-----
      | Uniform slots| usec_per_call=10.46 | usec_per_call=11.03 | 5.7%
      | Worst case (Only even slots)| usec_per_call=963.80 | usec_per_call=2950.99 | 307%
      
      This change also removes some extra white space that I added a when making a code change for adding hostnames.
      
      (cherry picked from commit e74a1f3b)
      c0e064ef
    • guybe7's avatar
      Call postExecutionUnitOperations in active-expire of writable replicas (#11615) · 3a6f0032
      guybe7 authored
      
      
      We need to honor the post-execution-unit API and call it after each KSN
      
      Note that this is an edge case that only happens in case volatile keys were
      created directly on a writable replica, and that anyway nothing is propagated to sub-replicas
      Co-authored-by: default avatarOran Agra <oran@redislabs.com>
      (cherry picked from commit df327b8b)
      3a6f0032
    • Wen Hui's avatar
      Fix command BITFIELD_RO and BITFIELD argument json file, add some test cases for them (#11445) · 4d5a4e4b
      Wen Hui authored
      According to the source code, the commands can be executed with only key name,
      and no GET/SET/INCR operation arguments.
      change the docs to reflect that by marking these arguments as optional.
      also add tests.
      
      (cherry picked from commit fea9bbbe)
      4d5a4e4b
  3. 16 Jan, 2023 11 commits
    • Oran Agra's avatar
      Redis 7.0.8 · 1c75ab06
      Oran Agra authored
      1c75ab06
    • Oran Agra's avatar
      Fix range issues in ZRANDMEMBER and HRANDFIELD (CVE-2023-22458) · 3f1f0203
      Oran Agra authored
      missing range check in ZRANDMEMBER and HRANDIFLD leading to panic due
      to protocol limitations
      3f1f0203
    • Oran Agra's avatar
      Avoid integer overflows in SETRANGE and SORT (CVE-2022-35977) · 6c25c6b7
      Oran Agra authored
      Authenticated users issuing specially crafted SETRANGE and SORT(_RO)
      commands can trigger an integer overflow, resulting with Redis attempting
      to allocate impossible amounts of memory and abort with an OOM panic.
      6c25c6b7
    • Oran Agra's avatar
      Obuf limit, exit during loop in *RAND* commands and KEYS · 4537830e
      Oran Agra authored
      Related to the hang reported in #11671
      Currently, redis can disconnect a client due to reaching output buffer limit,
      it'll also avoid feeding that output buffer with more data, but it will keep
      running the loop in the command (despite the client already being marked for
      disconnection)
      
      This PR is an attempt to mitigate the problem, specifically for commands that
      are easy to abuse, specifically: KEYS, HRANDFIELD, SRANDMEMBER, ZRANDMEMBER.
      The RAND family of commands can take a negative COUNT argument (which is not
      bound to the number of elements in the key), so it's enough to create a key
      with one field, and then these commands can be used to hang redis.
      For KEYS the caller can use the existing keyspace in redis (if big enough).
      4537830e
    • knggk's avatar
      Add minimum version information to new xsetid arguments (#11694) · 5fa7d9a2
      knggk authored
      the metadata for the new arguments of XSETID,
      entries-added and max-deleted-id, which have been added
      in Redis 7.0 was missing.
      
      (cherry picked from commit 44c67703)
      5fa7d9a2
    • Oran Agra's avatar
      Make sure that fork child doesn't do incremental rehashing (#11692) · 3e82bdf7
      Oran Agra authored
      Turns out that a fork child calling getExpire while persisting keys (and
      possibly also a result of some module fork tasks) could cause dictFind
      to do incremental rehashing in the child process, which is both a waste
      of time, and also causes COW harm.
      
      (cherry picked from commit 2bec254d)
      3e82bdf7
    • Gabi Ganam's avatar
      Blocking command with a 0.001 seconds timeout blocks indefinitely (#11688) · 574a49b9
      Gabi Ganam authored
      Any value in the range of [0-1) turns to 0 when being cast from double to long long. This change rounds up instead of down for values that can't be stored precisely as long doubles.
      
      (cherry picked from commit eef29b68)
      574a49b9
    • Oran Agra's avatar
      Fix potential issue with Lua argv caching, module command filter and libc realloc (#11652) · 61a1d454
      Oran Agra authored
      TLDR: solve a problem introduced in Redis 7.0.6 (#11541) with
      RM_CommandFilterArgInsert being called from scripts, which can
      lead to memory corruption.
      
      Libc realloc can return the same pointer even if the size was changed. The code in
      freeLuaRedisArgv had an assumption that if the pointer didn't change, then the
      allocation didn't change, and the cache can still be reused.
      However, if rewriteClientCommandArgument or RM_CommandFilterArgInsert were
      used, it could be that we realloced the argv array, and the pointer didn't change, then
      a consecutive command being executed from Lua can use that argv cache reaching
      beyond its size.
      This was actually only possible with modules, since the decision to realloc was based
      on argc, rather than argv_len.
      
      (cherry picked from commit c8052122)
      61a1d454
    • judeng's avatar
      Optimize the performance of msetnx command by call lookupkey only once (#11594) · f9f48ef6
      judeng authored
      This is a small addition to #9640
      It improves performance by avoiding double lookup of the the key.
      
      (cherry picked from commit 884ca601)
      f9f48ef6
    • sundb's avatar
      Remove unnecessary updateClientMemUsageAndBucket() when feeding monitors (#11657) · b7b78a2d
      sundb authored
      This call is introduced in #8687, but became irrelevant in #11348, and is currently a no-op.
      The fact is that #11348 an unintended side effect, which is that even if the client eviction config
      is enabled, there are certain types of clients for which memory consumption is not accurately
      tracked, and so unlike normal clients, their memory isn't reported correctly in INFO.
      
      (cherry picked from commit af0a4fe2)
      b7b78a2d
    • Moti Cohen's avatar
      Fix sentinel issue if replica changes IP (#11590) · fcfb046d
      Moti Cohen authored
      
      
      As Sentinel supports dynamic IP only when using hostnames, there
      are few leftover addess comparison logic that doesn't take into
      account that the IP might get change.
      Co-authored-by: default avatarmoticless <moticless@github.com>
      (cherry picked from commit 4a27aa48)
      fcfb046d
  4. 16 Dec, 2022 2 commits
  5. 12 Dec, 2022 11 commits
    • Oran Agra's avatar
      Redis 7.0.6 · c0924a83
      Oran Agra authored
      c0924a83
    • Binbin's avatar
      Fix replication on expired key test timing issue, give it more chances (#11548) · e2665c6f
      Binbin authored
      In replica, the key expired before master's `INCR` was arrived, so INCR
      creates a new key in the replica and the test failed.
      ```
      *** [err]: Replication of an expired key does not delete the expired key in tests/integration/replication-4.tcl
      Expected '0' to be equal to '1' (context: type eval line 13 cmd {assert_equal 0 [$slave exists k]} proc ::test)
      ```
      
      This test is very likely to do a false positive if the `wait_for_ofs_sync`
      takes longer than the expiration time, so give it a few more chances.
      
      The test was introduced in #9572.
      
      (cherry picked from commit 06b577aa)
      e2665c6f
    • Binbin's avatar
      Fix redis-cli cluster add-node race in cli.tcl (#11349) · 3c525fab
      Binbin authored
      There is a race condition in the test:
      ```
      *** [err]: redis-cli --cluster add-node with cluster-port in tests/unit/cluster/cli.tcl
      Expected '5' to be equal to '4' {assert_equal 5 [CI 0 cluster_known_nodes]} proc ::test)
      ```
      
      When using cli to add node, there can potentially be a race condition
      in which all nodes presenting cluster state o.k even though the added
      node did not yet meet all cluster nodes.
      
      This comment and the fix were taken from #11221. Also apply it in several
      other similar places.
      
      (cherry picked from commit a549b78c)
      3c525fab
    • ranshid's avatar
      fix test Migrate the last slot away from a node using redis-cli (#11221) · e1557e6c
      ranshid authored
      When using cli to add node, there can potentially be a race condition in
      which all nodes presenting cluster state o.k even though the added node
      did not yet meet all cluster nodes.
      this adds another utility function to wait until all cluster nodes see the same cluster size
      
      (cherry picked from commit c0ce97fa)
      e1557e6c
    • Binbin's avatar
      Fix timing issue in cluster test (#11008) · b5784fea
      Binbin authored
      A timing issue like this was reported in freebsd daily CI:
      ```
      *** [err]: Sanity test push cmd after resharding in tests/unit/cluster/cli.tcl
      Expected 'CLUSTERDOWN The cluster is down' to match '*MOVED*'
      ```
      
      We additionally wait for each node to reach a consensus on the cluster
      state in wait_for_condition to avoid the cluster down error.
      
      The fix just like #10495, quoting madolson's comment:
      Cluster check just verifies the the config state is self-consistent,
      waiting for cluster_state to be okay is an independent check that all
      the nodes actually believe each other are healthy.
      
      At the same time i noticed that unit/moduleapi/cluster.tcl has an exact
      same test, may have the same problem, also modified it.
      
      (cherry picked from commit 5ce64ab0)
      b5784fea
    • Binbin's avatar
      Fix CLUSTERDOWN issue in cluster reshard unblock test (#11139) · a43c51b2
      Binbin authored
      change the cluster-node-timeout from 1 to 1000
      
      (cherry picked from commit 3a16ad30)
      a43c51b2
    • David CARLIER's avatar
      Fixes build warning when CACHE_LINE_SIZE is already defined. (#11389) · d86408b7
      David CARLIER authored
      * Fixes build warning when CACHE_LINE_SIZE is already defined
      * Fixes wrong CACHE_LINE_SIZE on some FreeBSD systems where it could be set to 128 (e.g. on MIPS)
      * Fixes wrong CACHE_LINE_SIZE on Apple M1 (use 128 instead of 64)
      
      Wrong cache line size in that case can some false sharing of array elements between threads, see #10892
      
      (cherry picked from commit 871cc200)
      d86408b7
    • Oran Agra's avatar
      Avoid ASAN test errors on crash report tests · dca63da4
      Oran Agra authored
      Clang Address Sanitizer tests started reporting unknown-crash on these
      tests due to the memcheck, disable the memcheck to avoid that noise.
      
      (cherry picked from commit 18ff6a3269a34b9bfe549b34bda9d83c3eae7e2a)
      dca63da4
    • Oran Agra's avatar
      Try to fix a race in psync2 test (#11553) · 4a5aba16
      Oran Agra authored
      This test sets the master ping interval to 1 hour, in order to avoid
      pings in the replicatoin stream incrementing the replication offset,
      however, it didn't increase the repl-timeout so on slow machines
      where the test took more than 60 seconds, the replicas would drop
      and reconnect.
      
      ```
      *** [err]: PSYNC2: Partial resync after restart using RDB aux fields in tests/integration/psync2.tcl
      Replica didn't partial sync
      ```
      
      The test would detect 4 additional partial syncs where it expects
      only one.
      
      (cherry picked from commit b0250b45)
      4a5aba16
    • Binbin's avatar
      Bump vmactions/freebsd-vm to 0.3.0 to fix FreeBSD daily (#11476) · 72759356
      Binbin authored
      Our FreeBSD daily has been failing recently:
      ```
        Config file: freebsd-13.1.conf
        cd: /Users/runner/work/redis/redis: No such file or directory
        gmake: *** No targets specified and no makefile found.  Stop.
      ```
      
      Upgrade vmactions/freebsd-vm to the latest version (0.3.0) can work.
      I've tested it, but don't know why, but first let's fix it.
      
      (cherry picked from commit 5246bf45)
      72759356
    • Binbin's avatar
      Fix bgsaveerr issue in psync wrong offset test (#11043) · 98410d0d
      Binbin authored
      The kill above is sometimes successful and sometimes already too late.
      The PING in pysnc wrong offset test got rejected by bgsaveerr because
      lastbgsave_status is C_ERR.
      
      In theory, using diskless can avoid PING being affected, because when
      the replica is dropped, we will kill the child with SIGUSR1, and this
      will not affect lastbgsave_status.
      
      Anyway, this kill is not particularly needed here, dropping the kill
      is the best one, since we do have the waitForBgsave, so just let it
      take care of the bgsave. No need for fast termination.
      
      (cherry picked from commit e7144693)
      98410d0d