Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DoS due to unchecked memory allocation size #27

Open
fox-rose opened this issue Mar 26, 2024 · 0 comments
Open

DoS due to unchecked memory allocation size #27

fox-rose opened this issue Mar 26, 2024 · 0 comments

Comments

@fox-rose
Copy link

While fuzzing the ohttp-go package, we noticed that the ReadVarIntSlice function used
to decode QUIC variable length integers in the encoded varInt without initially checking availability.

Since the encoded values are attacker-controllable, a maliciously crafted and encoded
request could prompt the gateway to allocate an excessively large memory segment,
resulting in a Denial-of-Service (DoS).

One can pertinently note that a reference implementation utilizing the ohttp-go library wraps
the entire library into the Golang standard http library, which features a built-in mechanism to
recover from raised panics. However, the library itself should check for a maximum allowed
allocation size and return an error message when this limit is reached.

Affected file:
ohttp-go/bhttp.go
Affected code:
func readVarintSlice(b *bytes.Buffer) ([]byte, error) {
len, err := Read(b)
if err != nil {
return nil, err
}
value := make([]byte, len)
The following test function will trigger the crash by allocating a massive amount of memory:
PoC:
func TestVeryLargeVarInt(t *testing.T) {
data := []uint8{246, 0, 0, 0, 0, 0, 0, 0}
buf := bytes.NewBuffer(data)
readVarintSlice(buf)
}

To mitigate this issue, consider installing appropriate length checks within this
function. This measure serves to ensure that any potentially attacker-controllable arguments
cannot be exploited to induce remote DoS or crashes stemming from out-of-memory and
panic scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant