-
Notifications
You must be signed in to change notification settings - Fork 1.7k
new restriction lint: pointer_format #14792
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
base: master
Are you sure you want to change the base?
Conversation
rustbot has assigned @samueltardieu. Use |
Lint example needs to be fixed. FCP thread created on Zulip. @rustbot label +S-final-comment-period |
Is there any chance this could be adapted to check for any |
Do you mean debug-formatting a function pointer? That should be workable for the direct case but might become pretty hard for the general case. |
I think a specific example would be something like this: #[derive(Debug)]
pub struct S {
pub p: *const u32,
}
pub fn foo(a: *const u32) {
println!("{a:?}");
}
pub fn bar(a: S) {
println!("{a:?}");
}
fn main() {
foo(&0u32);
bar(S{p: &0u32});
} I'm not sure how this would be done in clippy since it would need to check whether a crate calls the |
A thing we might do there is to walk the types of the arguments (as far as they derive Debug, we should not go into manual implementations) and see if there's any raw pointer or reference. |
/// In kernel context, this might be vulnerable to misuse for exfiltrating | ||
/// stack or kernel function addresses. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
“…misuse for exfiltrating…” makes it sound like this is protection against attempts to insert malicious code into a project. Is auditing such code within scope for clippy? If not, it might be good to change the wording.
Also, “kernel context” isn’t very clear to people not familiar with what it’s talking about and sounds like it might be a formal or common Rust term, which it is not. How about something more like “In (projects|codebases|crates) such as operating system kernels,”?
Yeah, I'm working on some code to add that. I may not be able to look through manual |
Ideally, there would be a way to customize all pointer printing, i.e. including |
I read a blog post about kernel security, and how various features might get lost while porting to Rust. In kernel C, they have some guardrails against divulging pointers. An easy way to replicate that in Rust is a lint for pointer formatting. So that's what this lint does.
changelog: new [
pointer_format
] lint