-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
RSA.VerifyData terminates with "Out of memory." on Linux when passing an all-zero modulus #78293
Comments
Tagging subscribers to this area: @dotnet/area-system-security, @vcsjones Issue DetailsDescriptionIf an all-zero modulus is passed to RSA.VerifyData on Linux, the program will unexpectedly terminate instead of throwing an exception. Reproduction Stepsusing System.Security.Cryptography;
var param = new RSAParameters{Modulus = new byte[256], Exponent = new byte[3]};
using (var rsa = RSA.Create(param))
{
rsa.VerifyData(new byte[512], new byte[256], HashAlgorithmName.SHA256, RSASignaturePadding.Pss);
} Expected behavior
Actual behaviorThe program terminates with Regression?Issue occurs on .NET 6 and 7. Unsure about earlier versions. Known WorkaroundsNo response ConfigurationI've tested running .NET 6.0 and 7.0 on both x64 Ubuntu 22.04 and Debian 11. Other informationNo response
|
Note, I can only reproduce this with OpenSSL 1.1. Using OpenSSL 3, I get an "invalid modulus" I'll take a look at what's going on with OpenSSL 1.1. |
A few questions about the report:
Both .NET 6 and .NET 7 should use OpenSSL 3, which should be present on Ubuntu 22.04. @Thealexbarney can you confirm if you are using OpenSSL 3 or not? If you aren't certain you can add I can't reproduce this under OpenSSL 3. And this:
I don't get an error from For OpenSSL 1.1, this isn't a "real" This is our managed stack:
The top frame is pointing here: Line 190 in d099f07
So, this is not a "real" runtime/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ERR.cs Line 75 in d099f07
There are a couple of options here:
@bartonjs thoughts? |
As a work around, in this case you can catch this using System;
using System.Security.Cryptography;
var param = new RSAParameters{Modulus = new byte[256], Exponent = new byte[3]};
using (var rsa = RSA.Create(param))
{
try
{
rsa.VerifyData(new byte[512], new byte[256], HashAlgorithmName.SHA256, RSASignaturePadding.Pss);
}
catch (Exception e) when (e is CryptographicException or OutOfMemoryException)
{
Console.WriteLine("bad key");
}
}
Console.WriteLine("All done!"); Gives me the output:
|
My mistake. It was Ubuntu 20.04 and Debian 11 that I tested the issue on.
It's the using System;
using System.Security.Cryptography;
var param = new RSAParameters{Modulus = new byte[256], Exponent = new byte[3]};
using (var rsa = RSA.Create(param))
{
try
{
rsa.VerifyData(new byte[512], new byte[256], HashAlgorithmName.SHA256, RSASignaturePadding.Pss);
}
catch (Exception e) when (e is CryptographicException or OutOfMemoryException)
{
Console.WriteLine("bad key");
}
}
Console.WriteLine("All done!"); Gives me the output:
|
Just to confirm - my question was about Windows where you stated that "VerifyData throws a CryptographicException like it does on Windows." So you are seeing Windows throw during
|
Ah, okay. You're right. It's |
Hopefully the problem is just something like that we end up turning all zeros into the I'm a bit wary of adding custom validation to key parameters, especially if it's not universal. That said, if the only hole we know of is a non-null-but-zero Modulus then I guess consistency is good. (Presumably that'd be done with our fancy new vectorized searches |
This got reverted because it broke the x86 Linux build, so re-opening so we can get it in again. |
Description
If an all-zero modulus is passed to RSA.VerifyData on Linux, the program will unexpectedly terminate instead of throwing an exception.
Reproduction Steps
Expected behavior
VerifyData
throws aCryptographicException
like it does on Windows.Actual behavior
The program terminates with
Out of memory. Command terminated by signal 6
Regression?
Issue occurs on .NET 6 and 7. Unsure about earlier versions.
Known Workarounds
No response
Configuration
I've tested running .NET 6.0 and 7.0 on both x64 Ubuntu 22.04 and Debian 11.
Other information
No response
The text was updated successfully, but these errors were encountered: