Commit e6904da
committed
Fix strict aliasing UB in MurMur hash implementation.
This was spotted when trying to upgrade the libseccomp fedora package to
version 2.6.0 in fedora rawhide. It comes with gcc 15 and LTO enabled by
default. When running the test 61-sim-transactions we get plenty of such
errors in valgrind:
==265507== Use of uninitialised value of size 8
==265507== at 0x4096AD: _hsh_add (gen_bpf.c:599)
==265507== by 0x40A557: UnknownInlinedFun (gen_bpf.c:2016)
==265507== by 0x40A557: gen_bpf_generate (gen_bpf.c:2341)
==265507== by 0x400CDE: UnknownInlinedFun (db.c:2685)
==265507== by 0x400CDE: UnknownInlinedFun (db.c:2682)
==265507== by 0x400CDE: UnknownInlinedFun (api.c:756)
==265507== by 0x400CDE: UnknownInlinedFun (util.c:162)
==265507== by 0x400CDE: UnknownInlinedFun (util.c:153)
==265507== by 0x400CDE: main (61-sim-transactions.c:128)
==265507== Uninitialised value was created by a stack allocation
==265507== at 0x409590: _hsh_add (gen_bpf.c:573)
Investigating this a bit, it seems that because of LTO the MurMur hash
implementation is being inlined in _hsh_add. The way we call getblock32
with the explicit cast to const uint32_t* is a strict aliasing
violation.
This is reproducible on a "fedora:rawhide" container (gcc 15) and using:
export CFLAGS='-O2 -flto=auto -ffat-lto-objects -g'
Signed-off-by: Romain Geissler <[email protected]>1 parent 7db46d7 commit e6904da
1 file changed
+2
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | 20 | | |
25 | 21 | | |
26 | 22 | | |
| |||
56 | 52 | | |
57 | 53 | | |
58 | 54 | | |
59 | | - | |
| 55 | + | |
60 | 56 | | |
61 | 57 | | |
62 | 58 | | |
| |||
0 commit comments