Changes
Started by upstream project gerrit-libosmocore #2399
Started 1 day 4 hr ago
Queued 9.2 sec
Took 3 min 24 sec
on built-in
linuxlist: fix false-positive UBSan misaligned-access reports
llist_for_each_entry() and its variants terminate by comparing
&pos->member against head. Once a full traversal reaches the end of a
non-empty list (or the list is empty to begin with), pos becomes a pure
container_of()-computed sentinel address that was never a real object
of typeof(*pos), only ever the plain 'struct llist_head *' passed in as
head. Forming 'pos->member' on that address requires pos to satisfy
the alignment of typeof(*pos), which the sentinel does not necessarily
provide (e.g. embedded struct osmo_timer_list/gprs_nsvc on 32-bit ARM
with a 64-bit time_t need 8-byte alignment, while head itself is only
pointer-aligned) - tripping -fsanitize=alignment even though no real
object is ever misaligned or dereferenced.
Add __llist_member(), computing the same address via 'char *'
pointer arithmetic and an explicit cast to 'struct llist_head *', which
carries no alignment requirement of its own. Use it for the loop
termination check, the "next" pointer computation, and the prefetch()
calls (dereferencing the returned struct llist_head * still only
requires pointer alignment, so prefetch() keeps working exactly
as before without reintroducing the false positive).
Change-Id: I0424e76e76d8aa9402bd1a5aefe789de16e72fae
Related: OS#7036, OS#6858
llist_for_each_entry() and its variants terminate by comparing
&pos->member against head. Once a full traversal reaches the end of a
non-empty list (or the list is empty to begin with), pos becomes a pure
container_of()-computed sentinel address that was never a real object
of typeof(*pos), only ever the plain 'struct llist_head *' passed in as
head. Forming 'pos->member' on that address requires pos to satisfy
the alignment of typeof(*pos), which the sentinel does not necessarily
provide (e.g. embedded struct osmo_timer_list/gprs_nsvc on 32-bit ARM
with a 64-bit time_t need 8-byte alignment, while head itself is only
pointer-aligned) - tripping -fsanitize=alignment even though no real
object is ever misaligned or dereferenced.
Add __llist_member(), computing the same address via 'char *'
pointer arithmetic and an explicit cast to 'struct llist_head *', which
carries no alignment requirement of its own. Use it for the loop
termination check, the "next" pointer computation, and the prefetch()
calls (dereferencing the returned struct llist_head * still only
requires pointer alignment, so prefetch() keeps working exactly
as before without reintroducing the false positive).
Change-Id: I0424e76e76d8aa9402bd1a5aefe789de16e72fae
Related: OS#7036, OS#6858