nix-rust / nix

Rust friendly bindings to *nix APIs
MIT License
2.63k stars 661 forks source link

Change the type of data of ptrace::write to make it safe #2324

Closed ShuiRuTian closed 7 months ago

ShuiRuTian commented 7 months ago

What does this PR do

Fix #2323

Change the signature of ptrace::write and ptrace::write_user to make them safe

Checklist:

ShuiRuTian commented 7 months ago

I use the same command, but could not reproduce the issue, does anyone know the reason?

I ran cargo clippy --target x86_64-unknown-linux-gnu --all-targets --all-features -- -D warnings -A unknown-lints

SteveLauC commented 7 months ago

Well, it is indeed weird, I didn't reproduce it either...

Will investigate more.

SteveLauC commented 7 months ago

I kinda think this error is a false positive?

My guess on the reason why it is triggered is that we are directly casting a c_long to a raw pointer, but I think this is fine as the kernel won't treat it as a raw pointer but an unsigned long, so we can:

  1. Allow it #[allow(clippy::not_unsafe_ptr_arg_deref)]
  2. Write a comment stating why the usages of ptrace_other() within write() and write_user() are safe

    // Safety:
ShuiRuTian commented 7 months ago

Thanks for the suggestions, it's past now!