Skip to content

test: turn sspi-ffi-attacker into tests runnable with miri #275

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
Jul 26, 2024

Conversation

TheBestTvarynka
Copy link
Collaborator

@TheBestTvarynka TheBestTvarynka commented Jul 26, 2024

Hi,
In the scope of this PR, I've refactored the sspi-fii-attacker:

  1. Removed the sspi-ffi-attacker.
  2. Moved scenarios to ffi/sspi/sec_handle/tests.
    Now we can run those scenarios with Miri which will help us catch UBs and other memory errors.
  3. Fixed two UBs.

Additional context: #261 (comment)

@TheBestTvarynka TheBestTvarynka self-assigned this Jul 26, 2024
@@ -22,8 +22,10 @@ pub struct SecPkgInfoW {

pub type PSecPkgInfoW = *mut SecPkgInfoW;

pub struct RawSecPkgInfoW(pub *mut SecPkgInfoW);
Copy link
Collaborator Author

@TheBestTvarynka TheBestTvarynka Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was fun to investigate and fix. In short, conversions chain like this one *mut SecPkgInfoW -> &mut SecPkgInfoW -> *mut SecPkgInfoW can create UB 😮
image_2024-07-25_22-31-46
When we create &mut SecPkgInfoW, Rust creates a SharedReadWrite tag (it relates to stacked borrows and so on). And when we convert it to the raw pointer and try to deallocate, we have UB.
This is why I removed the conversion into &mut SecPkgInfoW and refactored it to use only raw pointers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

@TheBestTvarynka TheBestTvarynka requested a review from CBenoit July 26, 2024 10:03
@TheBestTvarynka TheBestTvarynka marked this pull request as ready for review July 26, 2024 10:03
@TheBestTvarynka TheBestTvarynka changed the title Refactor sspi-ffi-attacher Refactor sspi-ffi-attacker Jul 26, 2024
@@ -22,8 +22,10 @@ pub struct SecPkgInfoW {

pub type PSecPkgInfoW = *mut SecPkgInfoW;

pub struct RawSecPkgInfoW(pub *mut SecPkgInfoW);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question/nitpick: Should we use the PSecPkgInfoW type alias? Remove it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not allowed to implement the From trait for any raw pointers, because all raw pointers are foreign types

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant this:

Suggested change
pub struct RawSecPkgInfoW(pub *mut SecPkgInfoW);
pub struct RawSecPkgInfoW(pub PSecPkgInfoW);

I am under the impression that we don’t really use this alias.

Copy link
Member

@CBenoit CBenoit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! LGTM!

@CBenoit
Copy link
Member

CBenoit commented Jul 26, 2024

Merging now, the remaining comment is not very important

@CBenoit CBenoit changed the title Refactor sspi-ffi-attacker test: turn sspi-ffi-attacker into tests runnable with miri Jul 26, 2024
@CBenoit CBenoit merged commit 4c8381b into master Jul 26, 2024
42 checks passed
@CBenoit CBenoit deleted the refactor/sspi-ffi-attacker branch July 26, 2024 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants