Do not refresh clobber state for store address registers (#36)#37
Merged
Conversation
The explicit-dst clobber refresh added in the ROP chain search (PR #35) zeroed the clobber counter of a gadget's dst whenever a step wrote it. For store operations (mov [dst], src), dst is the address base register, which is read as an address rather than written, so refreshing it could mask an earlier clobber and yield an invalid ROP chain. Guard the refresh on whether the gadget actually writes dst (Gadget.writes_reg), so it applies to register writes (mov, pop, xchg) but not to store address registers. Add a discriminating regression test. Closes #36 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #36. Follow-up to #34 / #35.
Problem
The explicit-
dstclobber refresh added to the ROP chain search in PR #35 zeroes the clobber counter of a gadget'sdstwhenever a step writes it, so later steps can reuse that register:This is correct for register writes (
mov dst, src,lc(dst),xchg dst, src), but wrong for store operations. A storestismov [dst], src, sogad.dstholds the address base register ([rax]->rax), which is read as an address, not written. Zeroing its clobber count marks it as freshly produced when it is not, so a stale clobber from an earlier step can be masked and an invalid chain produced. This is a correctness issue, not a regression (a store'sdstwas never protected by the side-effect guard).Fix
Guard the refresh on whether the gadget actually writes
dst. A new helperGadget.writes_reg(normalized_reg)reports whether the gadget explicitly or implicitly writes a register (mirroringcalculate_side_effects). The refresh now applies only whendstis genuinely written:mov,pop,xchg) ->dstin written regs -> refresh (unchanged behavior);mov [dst], src) ->dstnot written -> no refresh (fixed).Tests
Adds
test_store_dst_does_not_clear_clobbered_address_register, which is discriminating: it fails on the pre-fix code (an invalid chain is produced) and passes with the fix. It complements the existingtest_explicit_dst_clears_clobbered_register(the register-write case). Full suite passes locally (103 tests) and covers Python 3.11, 3.12 and 3.13 in CI.