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

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