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

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