Skip to content

e_labels: fix UBSAN misaligned loads in __pmLogLoadLabelSet - #2756

Merged
kmcdonell merged 1 commit into
performancecopilot:mainfrom
rmetrich:ubsan__8
Oct 8, 2026
Merged

kmcdonell merged 1 commit into
performancecopilot:mainfrom
rmetrich:ubsan__8

Conversation

@rmetrich

@rmetrich rmetrich commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

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:

  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
      #1 0x7f30e852c89d in __pmLogLoadMeta [...]/src/libpcp/src/logmeta.c:933
      #2 0x7f30e843a443 in __pmLogOpen [...]/src/libpcp/src/logutil.c:1010
      #3 0x7f30e843a443 in __pmFindOrOpenArchive [...]/src/libpcp/src/context.c:695
      #4 0x7f30e84442cd in initarchive [...]/src/libpcp/src/context.c:947
      #5 0x7f30e84442cd in pmNewContext [...]/src/libpcp/src/context.c:1362
      #6 0x7f30e95af431 in pmDiscoverInvokeCallBacks [...]/src/libpcp_web/src/discover.c:1961
      #7 0x7f30e95af431 in directory_changed_cb [...]/src/libpcp_web/src/discover.c:2104
      #8 0x7f30e95b2993 in pmDiscoverTraverseArg [...]/src/libpcp_web/src/discover.c:226
      #9 0x7f30e95b2993 in changed_callback [...]/src/libpcp_web/src/discover.c:2181
      #10 0x7f30e9598cdf in fs_change_callBack [...]/src/libpcp_web/src/discover.c:510
      #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
      #12 0x7f30ea14954c in uv__io_poll /usr/src/debug/libuv-1.52.1-1.el10_2.x86_64/src/unix/linux.c:1546
      #13 0x7f30ea1339f1 in uv_run /usr/src/debug/libuv-1.52.1-1.el10_2.x86_64/src/unix/core.c:460
      #14 0x556f59155a93 in main_loop [...]/src/pmproxy/src/server.c:949
      #15 0x556f5915260a in main [...]/src/pmproxy/src/pmproxy.c:473
      #16 0x7f30e825158d in __libc_start_call_main (/lib64/libc.so.6+0x2a58d) (BuildId: cc6959d636202b0e1d6e17b273bf4060ec9265e5)
      #17 0x7f30e8251648 in __libc_start_main_alias_2 (/lib64/libc.so.6+0x2a648) (BuildId: cc6959d636202b0e1d6e17b273bf4060ec9265e5)
      #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

Related PR

See also ASAN+UBSAN PR

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>
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository YAML (base), Repository UI (inherited), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4cc8efa3-db0b-4ffe-8c6b-6115ef613247
📥 Commits

Reviewing files that changed from the base of the PR and between aa1ce94 and ce360ef.

📒 Files selected for processing (1)
  • src/libpcp/src/e_labels.c

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved safe parsing of serialized label data without changing decoded values or parsing behavior.

Walkthrough

The label-set parser now copies serialized integer fields and pmLabel records from the input buffer before converting or interpreting them. The decoded values and surrounding parsing flow remain unchanged.

Changes

Label buffer decoding

Layer / File(s) Summary
Copy serialized fields and records
src/libpcp/src/e_labels.c
The parser copies integer fields into aligned local storage before byte-order conversion. It copies each serialized pmLabel into its destination structure with memcpy.

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to ce360

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)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the affected function and the fix for UBSAN misaligned loads, which is the main change.
Description check ✅ Passed The description explains the misaligned reads, the use of memcpy, and the additional affected fields. It is directly related to the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

A rabbit read the labels with care,
And copied each value from here to there.
The bytes stayed neat, the fields aligned,
No typed cast left a trace behind.
Then off it hopped, content and fair.

Comment @coderabbitai help to get the list of available commands.

@kmcdonell
kmcdonell merged commit c260a39 into performancecopilot:main Oct 8, 2026
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants