Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Label callback uses and instruction cloning inconsistent. #3962

Closed
hgreving2304 opened this issue Nov 22, 2019 · 1 comment · Fixed by #4889
Closed

Label callback uses and instruction cloning inconsistent. #3962

hgreving2304 opened this issue Nov 22, 2019 · 1 comment · Fixed by #4889

Comments

@hgreving2304
Copy link

For label instructions with allow the raw bytes field to be re-used for a label callback pointer. If the pointer is valid, it is called when the label instruction is destroyed. This was causing problems when the instruction is cloned, xref #3960.

We are fixing the hot immediate issue by explicitly not copying the label callback pointer. However, the deeper issue remains about the higher level semantics. Is the cloned instruction passed to the client and the pointer is now invalid? Do we need to make a deep copy? Or should it be transferred? Whatever the solution is, it needs to avoid having two instructions with the same valid pointer since the callback should be unique to an instruction and should only be called once when this instruction is destroyed.

hgreving2304 pushed a commit that referenced this issue Nov 26, 2019
Label callbacks are called every time an instruction is destroyed iff the instruction is
a label instruction and the field is valid. When cloning an instruction, we can't blindly
copy the label callback field causing it to be called when the cloned instruction is
destroyed. We are adding a note to the instr_clone() docs and prevent the field from
being copied.

Fixes #3926
Issue: #3962
@derekbruening
Copy link
Contributor

PR #3960 was broken: it didn't even test cloning. The scatter test doesn't have a loop around any emulation markers; adding one immediately hits the assert:

...
AVX2 gather ok
AVX2 gather ok
<Application /home/bruening/dr/git/build_x64_dbg_tests/suite/tests/bin/client.drx-scattergather (1166706) DynamoRIO usage error : label callback function is already set>

derekbruening added a commit that referenced this issue Apr 29, 2021
PR #3960 added a call to instr_set_label_callback() to set it to NULL
from instr_clone(), but if the callback is non-NULL an assert fires in
that case.  This only normally happens with emulation labels that turn
into traces, which happens to not occur in our very few tests of
emulation labels (#3173 covers adding more tests).

We fix that by adding instr_clear_label_callback() here and using that
from instr_clone(), since these callbacks are a little different from
other values and it feels best to not clear them using the set
routine.

A test is added by putting a loop around a scatter-gather expansion,
triggering trace creation.  I confirmed that the assert does fire
without this fix with the loop in place.

Fixes #3962
derekbruening added a commit that referenced this issue Apr 29, 2021
PR #3960 added a call to instr_set_label_callback() to set it to NULL
from instr_clone(), but if the callback is non-NULL an assert fires in
that case.  This only normally happens with emulation labels that turn
into traces, which happens to not occur in our very few tests of
emulation labels (#3173 covers adding more tests).

We fix that by adding instr_clear_label_callback() here and using that
from instr_clone(), since these callbacks are a little different from
other values and it feels best to not clear them using the set
routine.

A test is added by putting a loop around a scatter-gather expansion,
triggering trace creation.  I confirmed that the assert does fire
without this fix with the loop in place.

Fixes #3962
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants