nix icon indicating copy to clipboard operation
nix copied to clipboard

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

Open ShuiRuTian opened this issue 1 year ago • 3 comments
trafficstars

What does this PR do

Fix #2323

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

Checklist:

  • [x] I have read CONTRIBUTING.md
  • [x] I have written necessary tests and rustdoc comments
  • [x] A change log has been added if this PR modifies nix's API

ShuiRuTian avatar Feb 28 '24 10:02 ShuiRuTian

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

ShuiRuTian avatar Feb 28 '24 15:02 ShuiRuTian

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

Will investigate more.

SteveLauC avatar Feb 29 '24 00:02 SteveLauC

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:
    

SteveLauC avatar Feb 29 '24 00:02 SteveLauC

Thanks for the suggestions, it's past now!

ShuiRuTian avatar Feb 29 '24 14:02 ShuiRuTian