Skip to content

Conversation

@teo-tsirpanis
Copy link
Contributor

Windows 8's actual version is 6.2, not 8. The test would succeed only on Windows 10+.

Windows 8's actual version is 6.2, not 8. The test would succeed only on Windows 10+.
@ghost ghost added the area-System.Security label Sep 6, 2021
@teo-tsirpanis
Copy link
Contributor Author

I also noticed in the same file some spans being pinned without MemoryMarshal.GetReference. Was that intentional or can I change it?

@KalleOlaviNiemitalo
Copy link

Is there a policy that requires MemoryMarshal.GetReference? I did not find one in https://github.com/dotnet/runtime/tree/main/docs/coding-guidelines. ReadOnlySpan<T>.GetPinnableReference() exists in the same target frameworks.

@teo-tsirpanis
Copy link
Contributor Author

@KalleOlaviNiemitalo I have seen it being used almost always when pinning spans within the BCL.

@KalleOlaviNiemitalo
Copy link

A fixed statement using MemoryMarshal.GetReference was most recently added in f4e88f4 on 2021-07-02, I think. But 6e286dd on 2021-08-31 used fixed on a Span directly. Perhaps the MemoryMarshal.GetReference style has been left over from runtime versions that were compiled as C# 7.2 or lower.

@stephentoub
Copy link
Member

Is there a policy that requires MemoryMarshal.GetReference?

There's no policy one way or the other. Pinning with:

fixed (byte* ptr = &MemoryMarshal.GetReference(span))

is ever so slightly more efficient than with:

fixed (byte* ptr = span)

as the latter ends up using span.GetPinnableReference, which is identical to MemoryMarshal.GetReference except that the former involves an extra length check; GetPinnableReference will return a null ref (e.g. Unsafe.NullRef<T>) if the span has a Length of 0, whereas MemoryMarshal.GetReference will return whatever reference the span contains, even if the span is empty. Some APIs don't like it when you give them a bad pointer even if they won't end up dereferencing it due to a length/count being zero.

@stephentoub stephentoub requested a review from vcsjones September 7, 2021 14:20
Copy link
Member

@vcsjones vcsjones left a comment

Choose a reason for hiding this comment

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

This looks good to me. Thanks for the fix.

@vcsjones
Copy link
Member

vcsjones commented Sep 7, 2021

How feasible would it be to get this in 6.0, @stephentoub / @dotnet/area-system-security? The impact on this is basically Windows 8.0 will use a much slower Windows 7 API for the PBKDF2 one-shot.

@jeffhandley
Copy link
Member

While this doesn't directly align with any of our RC2 bar criteria, I support presenting it to tactics. After it's merged into RC2, let's backport it to release/6.0 and label it for consideration.

@GrabYourPitchforks
Copy link
Member

I also support bringing this to tactics. Low-risk, good test coverage, etc.

@jeffhandley jeffhandley merged commit 2e93ebb into dotnet:main Sep 8, 2021
@jeffhandley
Copy link
Member

/backport to release/6.0

@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2021

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1214551203

@jeffhandley
Copy link
Member

Thanks for finding and fixing this, @teo-tsirpanis!

@teo-tsirpanis teo-tsirpanis deleted the patch-2 branch September 8, 2021 18:50
@ghost ghost locked as resolved and limited conversation to collaborators Oct 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants