Commit 71be9729 authored by Oran Agra's avatar Oran Agra
Browse files

Prevent unauthenticated client from easily consuming lots of memory (CVE-2021-32675)

This change sets a low limit for multibulk and bulk length in the
protocol for unauthenticated connections, so that they can't easily
cause redis to allocate massive amounts of memory by sending just a few
characters on the network.
The new limits are 10 arguments of 16kb each (instead of 1m of 512mb)

(cherry picked from commit 3d221e81f3b680543e34942579af190b049ff283)
parent 34f447f1
...@@ -1309,6 +1309,10 @@ int processMultibulkBuffer(client *c) { ...@@ -1309,6 +1309,10 @@ int processMultibulkBuffer(client *c) {
addReplyError(c,"Protocol error: invalid multibulk length"); addReplyError(c,"Protocol error: invalid multibulk length");
setProtocolError("invalid mbulk count",c); setProtocolError("invalid mbulk count",c);
return C_ERR; return C_ERR;
} else if (ll > 10 && server.requirepass && !c->authenticated) {
addReplyError(c, "Protocol error: unauthenticated multibulk length");
setProtocolError("unauth mbulk count", c);
return C_ERR;
} }
c->qb_pos = (newline-c->querybuf)+2; c->qb_pos = (newline-c->querybuf)+2;
...@@ -1354,6 +1358,10 @@ int processMultibulkBuffer(client *c) { ...@@ -1354,6 +1358,10 @@ int processMultibulkBuffer(client *c) {
addReplyError(c,"Protocol error: invalid bulk length"); addReplyError(c,"Protocol error: invalid bulk length");
setProtocolError("invalid bulk length",c); setProtocolError("invalid bulk length",c);
return C_ERR; return C_ERR;
} else if (ll > 16384 && server.requirepass && !c->authenticated) {
addReplyError(c, "Protocol error: unauthenticated bulk length");
setProtocolError("unauth bulk length", c);
return C_ERR;
} }
c->qb_pos = newline-c->querybuf+2; c->qb_pos = newline-c->querybuf+2;
......
...@@ -24,4 +24,20 @@ start_server {tags {"auth"} overrides {requirepass foobar}} { ...@@ -24,4 +24,20 @@ start_server {tags {"auth"} overrides {requirepass foobar}} {
r set foo 100 r set foo 100
r incr foo r incr foo
} {101} } {101}
test {For unauthenticated clients multibulk and bulk length are limited} {
set rr [redis [srv "host"] [srv "port"] 0]
$rr write "*100\r\n"
$rr flush
catch {[$rr read]} e
assert_match {*unauthenticated multibulk length*} $e
$rr close
set rr [redis [srv "host"] [srv "port"] 0]
$rr write "*1\r\n\$100000000\r\n"
$rr flush
catch {[$rr read]} e
assert_match {*unauthenticated bulk length*} $e
$rr close
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment