You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
dongyeonkim@dongyeonkim-Modern-15-A11M:~/Desktop/KeyDB$ src/keydb-cli
Message of the day:
KeyDB has now joined Snap! See the announcement at: https://docs.keydb.dev/news
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> EVAL "return bit.tohex(65535, -2147483648)" 0 //Payload
Error: Server closed the connection
127.0.0.1:6379>
Aditional information
KeyDB version : KeyDB v6.3.4
Operating system : Linux
Operating system, version and so on : Ubuntu 22.04.5 LTS 64bit
To reproduce
To reproduce this error:
Send this payload to the server.
EVAL "return bit.tohex(65535, -2147483648)" 0
KeyDB clients will be disconnected because of a crash.
The function static int bit_tohex(lua_State *L) sets b from the first argument and n from second (defaulting to 8 if missing).
if (n<0) { n=-n; hexdigits="0123456789ABCDEF"; }
At #L134, if n is negative, the code tries to make it positive.
But an int only stores values from -2,147,483,648 to 2,147,483,647.
When you input -2,147,483,648 and compute n = -n , the result should be 2,147,483,648.
However this number is too big for an int .
So an intger overflow occurs and n stays as -2,147,483,648.
for (i= (int)n; --i >= 0; ) { buf[i] =hexdigits[b&15]; b >>= 4; } //buf[0xffffffff]
This flaw bypasses the (n > 8) check at #L137.
At #L138, a negative n makes the loop access buf[0xffffffff] and crash.
This bug was found in Redis and is labeled CVE-2024-31449.
Solution
Add the following code above line #L134, as shown in the redis commit.
if (n==INT32_MIN) n=INT32_MIN+1;
This code is a condition that prevents integer overflow.
dongyeonkim@dongyeonkim-Modern-15-A11M:~/Desktop/KeyDB$ src/keydb-cli
Message of the day:
KeyDB has now joined Snap! See the announcement at: https://docs.keydb.dev/news
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> EVAL "return bit.tohex(65535, -2147483648)" 0
"0000FFFF"
127.0.0.1:6379>
After applying this code, here's what happens during an attack.
Checking the integer range prevents a stack overflow.
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
Crash report
This issue is related to #871:
Aditional information
To reproduce
To reproduce this error:
Description
Located in deps/lua/src/lua_bit.c
static int bit_tohex(lua_State *L)
setsb
from the first argument andn
from second (defaulting to 8 if missing).n
is negative, the code tries to make it positive.int
only stores values from -2,147,483,648 to 2,147,483,647.n = -n
, the result should be 2,147,483,648.int
.n
stays as -2,147,483,648.(n > 8)
check at #L137.n
makes the loop access buf[0xffffffff] and crash.Solution
The text was updated successfully, but these errors were encountered: