Skip to content

Analyze unsafe code reachability #4037

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

Merged
merged 6 commits into from
Apr 24, 2025

Conversation

carolynzech
Copy link
Contributor

Continuation of #3546.

From @celinval in #3546:

Add call graph analysis to scanner in order to find the distance between functions in a crate and unsafe functions.

For that, we build the crate call graph and collect the unsafe functions. After that, do reverse BFS traversal from the unsafe functions and store the distance to other functions. The result is stored in a new csv file.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

celinval and others added 4 commits April 21, 2025 11:05
Add callgraph analysis to scanner in order to find the distance between
functions in a crate and unsafe functions.

For that, we build the crate call graph and collect the unsafe
functions. After that, do reverse BFS traversal from the unsafe
functions and store the distance to other functions.
The result is stored in a new csv file.
@carolynzech carolynzech requested a review from a team as a code owner April 21, 2025 16:01
@tautschnig
Copy link
Member

Add call graph analysis to scanner in order to find the distance between functions in a crate and unsafe functions.

For that, we build the crate call graph and collect the unsafe functions. After that, do reverse BFS traversal from the unsafe functions and store the distance to other functions. The result is stored in a new csv file.

What does this distance metric tell us?

More generally: what is the goal of the new analysis? And what else can we maybe do with it? I vaguely recall that I wanted to build upon this PR to find all functions that transitively involve loops, but now I'm not entirely sure this is the right place.

@carolynzech
Copy link
Contributor Author

carolynzech commented Apr 22, 2025

What does this distance metric tell us?
More generally: what is the goal of the new analysis? And what else can we maybe do with it?

On my local machine, I added a filter to the queue initialization here to filter out unsafe functions and safe abstractions as roots of the tree. By starting only from safe functions and performing the analysis, we can compute how many safe functions with transitive unsafe dependencies there are.

This is useful for the standard library, where 71% of the functions appear safe in that they don't contain any unsafe blocks, but after performing this analysis, we can see that 52% of these "safe" functions end up calling into unsafe somewhere in their call chain.

@celinval
Copy link
Contributor

Just for some context, initially I implemented this analysis to find out the percentage of safe functions that may lead to an unsafe operation. The distance is not as relevant, but it's something we get for free.

@tautschnig tautschnig added this pull request to the merge queue Apr 24, 2025
Merged via the queue into model-checking:main with commit 5a8febb Apr 24, 2025
26 checks passed
@carolynzech carolynzech deleted the transitive-scan branch May 13, 2025 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants