Hi Aleksei, On Tue, 2023-02-07 at 16:17 +0000, Aleksei Vetrov wrote: > > Did you actually find situations where these functions were called > > with addrp > > > = endp? > > Yes, for example libdw/libdw_form.c:91:7. > Urgh. There are actually 3 places in that function that need a guard. Then I started reviewing all the library code and came up with more than 10 other places that had a guard missing (see attached). I'll clean this up and also audit elflint.c and readelf.c and submit a proper patch for that. > > It turns out that get_[su]leb128 dominates some operations and really does > > have to be as fast as possible. So I do like to know what the impact is of > > this change. > > This patch just moves __libdw_max_len_uleb128 to the beginning of the function > and adds only one new if. So hopefully it shouldn't affect performance at all. Yeah. At first I thought it might be unnecessary because we already have this check in the calling code. But given that I quickly found 10+ places were that wasn't true I don't feel very confident about that now... Then I thought maybe we can just remove the calling code checks and simply always check like you are proposing. But the checks are slightly different. The caller guards signal bad data errors, while yours are hardening checks that make sure no invalid data is read. It is better to have both. Even if it might slow down the code. I'll finish the audit of readelf.c and elflint.c and see if adding both those checks and your hardening checks don't pessimize the code too much. Hopefully it won't and we can just add all the extra checks. Cheers, Mark