Repository navigation
fix(net): avoid a misaligned reference to a packed epoll_event member - #8215
PastaPastaPasta merged 1 commit into
Conversation
|
No actionable comments were generated in the recent review. WalkthroughThe epoll and kqueue paths in Estimated code review effort: 1 (Trivial) | ~2 minutes Possibly related PRs
Merge Risk:
|
|
✅ Final review complete — no blockers (commit 6d1c11e) · triage: low |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
The local copy fixes the epoll alignment bug without changing the event tag or dispatch. The same reference-binding pattern remains in the kqueue branch, where the macOS SDK also packs the event struct. No CI checks have failed on this head; the ASan/UBSan, TSan, and no-wallet tests and multiprocess lint are still pending.
🟡 1 suggestion(s) | 💬 1 nitpick(s)
Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.
1 finding(s) not shown inline (the lines are not part of this PR's diff)
🟡 Suggestion: Copy the kqueue tag before constructing the pair
src/util/edge.cpp:168
The macOS SDK declares struct kevent under #pragma pack(4), so the event array's type guarantees only 4-byte alignment, while a reference to its udata pointer requires 8-byte alignment on 64-bit macOS. Passing ev.udata directly to the pair constructor leaves the same reference-binding hazard that this PR removes from epoll. Copy the tag by value here too, so correctness does not depend on the compiler giving the array more alignment than its type requires.
void* const tag{ev.udata};
occurred_per_tag[idx] = {tag, occurred};
source: glm-5.3-flash (phase1-reviewer: general); gpt-6.2-sol (phase2-reviewer: general, dash-core-commit-history)
Review provenance
Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: dash-core-commit-history); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
lowbygpt-6.2-sol(effort low) — The change is confined to the epoll branch of EdgeTriggeredEvents::Wait(), where copying the packed pointer into an aligned local avoids a misaligned reference without changing the returned value. - Phase 1 reviewers:
glm-5.3-flash— general (completed, effort high); agentphase1-reviewer - Phase 1 model:
glm-5.3-flash— zai quota: 5h 99% left, weekly 48% left; passed overgemini-3.8-flash-high(antigravity quota lookup failed) - Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort medium); agentphase2-reviewer,gpt-6.2-sol— dash-core-commit-history (completed, effort medium); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `src/util/edge.cpp`:
- [SUGGESTION] src/util/edge.cpp:168: Copy the kqueue tag before constructing the pair
The macOS SDK declares `struct kevent` under `#pragma pack(4)`, so the event array's type guarantees only 4-byte alignment, while a reference to its `udata` pointer requires 8-byte alignment on 64-bit macOS. Passing `ev.udata` directly to the pair constructor leaves the same reference-binding hazard that this PR removes from epoll. Copy the tag by value here too, so correctness does not depend on the compiler giving the array more alignment than its type requires.
- [NITPICK] src/util/edge.cpp:143-144: Document why the epoll tag must be copied
The local looks like a temporary that can be inlined. A short comment preserves the reason at the point of use: passing `ev.data.ptr` directly would let the pair constructor bind a reference to a potentially misaligned packed member.
| void* const tag{ev.data.ptr}; | ||
| occurred_per_tag[idx] = {tag, occurred}; |
There was a problem hiding this comment.
✅ Resolved at
6d1c11ed; see the replies below.
💬 Nitpick: Document why the epoll tag must be copied
The local looks like a temporary that can be inlined. A short comment preserves the reason at the point of use: passing ev.data.ptr directly would let the pair constructor bind a reference to a potentially misaligned packed member.
| void* const tag{ev.data.ptr}; | |
| occurred_per_tag[idx] = {tag, occurred}; | |
| // Copy the tag to avoid binding a reference to a packed member. | |
| void* const tag{ev.data.ptr}; | |
| occurred_per_tag[idx] = {tag, occurred}; |
source: glm-5.3-flash (phase1-reviewer: general)
There was a problem hiding this comment.
Resolved (re-reviewed at 6d1c11ed): Your comment at src/util/edge.cpp:143 explains why the tag is copied: binding a reference directly to the packed member could bind to a misaligned address.
glibc declares struct epoll_event with __EPOLL_PACKED on x86_64, so its data member sits at offset 4. EdgeTriggeredEvents::Wait() built the (tag, events) pair from ev.data.ptr directly, which binds a const reference to that misaligned void* inside std::pair's constructor. That is undefined behaviour, and UBSan's alignment check aborts dashd on the first epoll event, failing most functional tests in the sanitizer CI job since dashpay#8193. Copy the pointer into a local before building the pair. Do the same for the kqueue tag: the macOS SDK declares struct kevent under #pragma pack(4), so its udata pointer is not guaranteed 8-byte alignment either. Co-Authored-By: Claude Opus 5.5 <[email protected]>
a0aa2c9 to
6d1c11e
Compare
|
🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta. |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
Static review of 6d1c11e found no issues: both event backends read packed tags by value before constructing the result pair, leaving socket lookup and dispatch unchanged. No code checks have failed; the macOS and ASan builds passed, while the ASan/UBSan, TSan, and multiprocess tests, multiprocess lint, and standard Linux build are still pending.
🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)
Review provenance
Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: dash-core-commit-history); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
lowbygpt-6.2-sol(effort low) — This is a small, self-contained undefined-behavior fix in src/util/edge.cpp that copies packed event members before constructing result pairs, with no consensus, funds, cryptographic, or storage impact. - Phase 1 reviewers:
glm-5.3-flash— general (completed, effort high); agentphase1-reviewer - Phase 1 model:
glm-5.3-flash— zai quota: 5h 99% left, weekly 48% left; passed overgemini-3.8-flash-high(antigravity quota lookup failed) - Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort medium); agentphase2-reviewer,gpt-6.2-sol— dash-core-commit-history (completed, effort medium); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.
No unresolved findings remain from the prior review on this head.
| void* const tag{ev.data.ptr}; | ||
| occurred_per_tag[idx] = {tag, occurred}; |
There was a problem hiding this comment.
Resolved (re-reviewed at 6d1c11ed): Your comment at src/util/edge.cpp:143 explains why the tag is copied: binding a reference directly to the packed member could bind to a misaligned address.
Issue being fixed or feature implemented
Since #8193 merged, the
linux64_asan-testjob (ASan + UBSan,halt_on_error=1) fails on develop and on every PR based on it. dashd aborts on its first epoll event, so most functional tests die within a second or two:glibc declares
struct epoll_eventwith__EPOLL_PACKEDon x86_64, so itsdatamember sits at offset 4. #8193 changedEdgeTriggeredEvents::Wait()to build the result pair withoccurred_per_tag[idx] = {ev.data.ptr, occurred};. That passesev.data.ptrtostd::pair's constructor by const reference, which binds a reference to a misalignedvoid*. That is undefined behaviour, and UBSan's alignment check aborts on it. The code before #8193 readstatic_cast<SOCKET>(ev.data.fd), a prvalue, so it never bound a reference.What was done?
The pointer is copied into a local (
void* const tag{ev.data.ptr};) before the pair is built. This is the only place that binds a reference to a packedepoll_eventmember;Sock::RegisterEvents()only stores toevent.data.ptr. The kqueue branch gets the same copy ofev.udata: the macOS SDK declaresstruct keventunder#pragma pack(4), so its 8-byteudatapointer isn't guaranteed alignment either (that path isn't built with UBSan in CI).How Has This Been Tested?
-DSANITIZERS=address,float-divide-by-zero,integer,undefinedand CI'sASAN_OPTIONS/UBSAN_OPTIONS, develop reproduces the exact error above inp2p_ping.pyandmining_getblocktemplate_longpoll_mempool.py. With this fix,feature_block.py,mining_getblocktemplate_longpoll_mempool.py,p2p_addr_relay.py,p2p_disconnect_ban.py,p2p_ping.py,rpc_net.pyandrpc_uptime.pyall pass under the same build.epoll_event, a brace-initialisedstd::pair<const void*, unsigned>fromev.data.ptr), built withclang++ -fsanitize=alignment, reports the same runtime error. Copying the member into a local first makes it run clean.Breaking Changes
None.
Checklist:
🤖 Generated with Claude Code