Repository navigation
e_labels: fix UBSAN misaligned loads in __pmLogLoadLabelSet - #2756
Conversation
tbuf is a plain char buffer; the offset k has no alignment guarantee.
Casting &tbuf[k] to unsigned int * or pmLabel * and dereferencing
requires 4-byte alignment that k does not provide, yielding:
e_labels.c:295:12: runtime error: load of misaligned address 0x506000011931 for type 'unsigned int', which requires 4 byte alignment
0x506000011931: note: pointer points here
75 78 22 7d 00 00 00 01 00 02 05 02 00 09 00 07 00 00 00 b9 96 6e cc b9 96 6e cc 50 19 01 00 60
^
#0 0x7f30e8683c64 in __pmLogLoadLabelSet [...]/src/libpcp/src/e_labels.c:295
performancecopilot#1 0x7f30e852c89d in __pmLogLoadMeta [...]/src/libpcp/src/logmeta.c:933
performancecopilot#2 0x7f30e843a443 in __pmLogOpen [...]/src/libpcp/src/logutil.c:1010
performancecopilot#3 0x7f30e843a443 in __pmFindOrOpenArchive [...]/src/libpcp/src/context.c:695
performancecopilot#4 0x7f30e84442cd in initarchive [...]/src/libpcp/src/context.c:947
performancecopilot#5 0x7f30e84442cd in pmNewContext [...]/src/libpcp/src/context.c:1362
performancecopilot#6 0x7f30e95af431 in pmDiscoverInvokeCallBacks [...]/src/libpcp_web/src/discover.c:1961
performancecopilot#7 0x7f30e95af431 in directory_changed_cb [...]/src/libpcp_web/src/discover.c:2104
performancecopilot#8 0x7f30e95b2993 in pmDiscoverTraverseArg [...]/src/libpcp_web/src/discover.c:226
performancecopilot#9 0x7f30e95b2993 in changed_callback [...]/src/libpcp_web/src/discover.c:2181
performancecopilot#10 0x7f30e9598cdf in fs_change_callBack [...]/src/libpcp_web/src/discover.c:510
performancecopilot#11 0x7f30ea148d91 in uv__inotify_read.isra.0 /usr/src/debug/libuv-1.52.1-1.el10_2.x86_64/src/unix/linux.c:2647
performancecopilot#12 0x7f30ea14954c in uv__io_poll /usr/src/debug/libuv-1.52.1-1.el10_2.x86_64/src/unix/linux.c:1546
performancecopilot#13 0x7f30ea1339f1 in uv_run /usr/src/debug/libuv-1.52.1-1.el10_2.x86_64/src/unix/core.c:460
performancecopilot#14 0x556f59155a93 in main_loop [...]/src/pmproxy/src/server.c:949
performancecopilot#15 0x556f5915260a in main [...]/src/pmproxy/src/pmproxy.c:473
performancecopilot#16 0x7f30e825158d in __libc_start_call_main (/lib64/libc.so.6+0x2a58d) (BuildId: cc6959d636202b0e1d6e17b273bf4060ec9265e5)
performancecopilot#17 0x7f30e8251648 in __libc_start_main_alias_2 (/lib64/libc.so.6+0x2a648) (BuildId: cc6959d636202b0e1d6e17b273bf4060ec9265e5)
performancecopilot#18 0x556f59153014 in _start ([...]/src/pmproxy/src/pmproxy+0xd014) (BuildId: 0ff0d5440313ebe8225d2d57af1546f9d46c6556)
(NOTE: the line numbers above differ because it was encountered on RHEL10.2 PCP 7.0.3)
Replace all pointer-cast dereferences against tbuf[k] with memcpy, which
is the standard C idiom for unaligned reads and is optimised by GCC/Clang
into the same load instructions on x86.
Also fix the equivalent patterns for typep/identp/nsets (lines 244-250)
that carry the same bug but were not yet hit by UBSAN.
Co-Authored-By: Claude Sonnet 4.6 (1M context) noreply@anthropic.com
Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review. 📝 SummarySummary by CodeRabbit
WalkthroughThe label-set parser now copies serialized integer fields and ChangesLabel buffer decoding
Priority: ➖ Normal Change: Bug fix Merge Risk: ⚪ Minimal · up to The parser avoids the reported unaligned reads without changing decoded values or parsing flow. No merge-blocking risk is evident. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit read the labels with care, Comment |
Pull Request Description
tbuf is a plain char buffer; the offset k has no alignment guarantee. Casting &tbuf[k] to unsigned int * or pmLabel * and dereferencing requires 4-byte alignment that k does not provide, yielding:
(NOTE: the line numbers above differ because it was encountered on RHEL10.2 PCP 7.0.3)
Replace all pointer-cast dereferences against tbuf[k] with memcpy, which is the standard C idiom for unaligned reads and is optimised by GCC/Clang into the same load instructions on x86.
Also fix the equivalent patterns for typep/identp/nsets (lines 244-250) that carry the same bug but were not yet hit by UBSAN.
Co-Authored-By: Claude Sonnet 4.6 (1M context) noreply@anthropic.com
Related PR
See also ASAN+UBSAN PR