nix-rust / nix

Rust friendly bindings to *nix APIs
MIT License
2.57k stars 650 forks source link

Fix inconsistent reg struct layout for 64bit tracer and 32bit tracee #2448

Open Evian-Zhang opened 2 weeks ago

Evian-Zhang commented 2 weeks ago

What does this PR do

Fix #2447

Checklist:

Evian-Zhang commented 2 weeks ago

Could you please add a changelog entry? Also, have you audited the other ptrace functions for similar behavior?

I'll add one. For other ptrace functions, it is the setregs and setregset that should be considered. It does not involves UB in Rust side (no uninitialized memory is read by Rust), but it is clear that in the 64bit tracer and 32bit tracee situation, those functions does not do the right thing, and even worse, it may modify the tracee's regs with wrong data. Should we mark it unsafe or add some docs about this?

asomers commented 2 weeks ago

What about the ptrace functions in the BSD module? Did you look at them?

Evian-Zhang commented 2 weeks ago

What about the ptrace functions in the BSD module? Did you look at them?

I do not have a BSD machine, and cannot check whether it has the same behavior with Linux