Blame SOURCES/0013-quic-Avoid-possible-buffer-overflow-in-find_bucket.patch

84be6c
From 57c6e6b00247ad289a27648213d7ad2306fe3931 Mon Sep 17 00:00:00 2001
84be6c
From: Frediano Ziglio <freddy77@gmail.com>
84be6c
Date: Thu, 30 Apr 2020 10:19:09 +0100
84be6c
Subject: [PATCH spice-common 4/4] quic: Avoid possible buffer overflow in
84be6c
 find_bucket
84be6c
84be6c
Proved by fuzzing the code.
84be6c
84be6c
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
84be6c
Acked-by: Uri Lublin <uril@redhat.com>
84be6c
---
84be6c
 common/quic_family_tmpl.c | 7 ++++++-
84be6c
 1 file changed, 6 insertions(+), 1 deletion(-)
84be6c
84be6c
diff --git a/subprojects/spice-common/common/quic_family_tmpl.c b/subprojects/spice-common/common/quic_family_tmpl.c
84be6c
index 8a5f7d2..6cc051b 100644
84be6c
--- a/subprojects/spice-common/common/quic_family_tmpl.c
84be6c
+++ b/subprojects/spice-common/common/quic_family_tmpl.c
84be6c
@@ -103,7 +103,12 @@ static s_bucket *FNAME(find_bucket)(Channel *channel, const unsigned int val)
84be6c
 {
84be6c
     spice_extra_assert(val < (0x1U << BPC));
84be6c
 
84be6c
-    return channel->_buckets_ptrs[val];
84be6c
+    /* The and (&) here is to avoid buffer overflows in case of garbage or malicious
84be6c
+     * attempts. Is much faster then using comparisons and save us from such situations.
84be6c
+     * Note that on normal build the check above won't be compiled as this code path
84be6c
+     * is pretty hot and would cause speed regressions.
84be6c
+     */
84be6c
+    return channel->_buckets_ptrs[val & ((1U << BPC) - 1)];
84be6c
 }
84be6c
 
84be6c
 #undef FNAME
84be6c
-- 
84be6c
2.25.4
84be6c