BUG/MEDIUM: ebtree: Invalid read when looking for dup entry
authorRemi Tricot-Le Breton <rlebreton@haproxy.com>
Tue, 18 May 2021 16:56:42 +0000 (18:56 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 31 May 2021 13:19:19 +0000 (15:19 +0200)
commit42f9c53a8f1560845304b42a999c74453f15514b
tree0679ca540d8d76274618cd022aaa3d48411a4929
parentc2471edc6075f8af6d03a372d9475e186a444c49
BUG/MEDIUM: ebtree: Invalid read when looking for dup entry

The first item inserted into an ebtree will be inserted directly below
the root, which is a simple struct eb_root which only holds two branch
pointers (left and right).
If we try to find a duplicated entry to this first leaf through a
ebmb_next_dup, our leaf_p pointer will point to the eb_root instead of a
complete eb_node so we cannot look for the bit part of our leaf_p since
it would try to cast our eb_root into an eb_node and perform an out of
bounds access when reading "eb_root_to_node(eb_untag(t,EB_LEFT)))->bit".
This bug was found by address sanitizer running on a CRL hot update VTC
test.

Note that the bug has been there since the import of the eb_next_dup()
and eb_prev_dup() function in 1.5-dev19 by commit 2b5702030 ("MINOR:
ebtree: add new eb_next_dup/eb_prev_dup() functions to visit duplicates").

It can be backported to all stable branches.

(cherry picked from commit 2608e348bec8a533225424fad06760ce6e19f167)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 0179e1d7aa4a15b5325e8e3744ef302a488893d6)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
include/import/ebtree.h