-
Notifications
You must be signed in to change notification settings - Fork 839
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
[Bug]: Invalid instruction exception in sp_2048_get_from_table_32 #7663
Comments
Hi @vaintroub I've put up a PR to fix this: #7666 Let us know if this fixes your issues! Thanks, |
I asked to test the fix in MariaDB bug report, hopefully there will be some feedback. Myself, I do not have hardware that old |
Thanks @vaintroub. |
So, I found a way to reproduce it, apparently just install of fresh Windows 10 to VirtualBox does it for me. AVX/AVX2, and couple of other instructions (FMA) are unsupported. Bad news, there is still illegal instruction exception, on the same line as originally reported , line 13172 here IFNDEF WC_NO_CACHE_RESISTANT
_text SEGMENT READONLY PARA
sp_2048_get_from_table_32 PROC
sub rsp, 128
vmovdqu OWORD PTR [rsp], xmm6
vmovdqu OWORD PTR [rsp+16], xmm7
vmovdqu OWORD PTR [rsp+32], xmm8 Maybe, those should be Here is the test program I'm using #include <user_settings.h>
#include <openssl/evp.h>
#include <openssl/dh.h>
#include <openssl/bn.h>
#include <openssl/x509.h>
static EVP_PKEY *vio_keygen()
{
EVP_PKEY_CTX *ctx;
EVP_PKEY *pkey= NULL;
if (!(ctx= EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL)))
return NULL;
if (EVP_PKEY_keygen_init(ctx) <= 0)
goto end;
if (EVP_PKEY_CTX_set_rsa_keygen_bits(ctx,4096) <= 0)
goto end;
if (EVP_PKEY_keygen(ctx, &pkey) <= 0)
pkey= NULL; /* just in case */
end:
EVP_PKEY_CTX_free(ctx);
return pkey;
}
static X509 *vio_gencert(EVP_PKEY *pkey)
{
X509 *x;
X509_NAME *name;
if (!(x= X509_new()))
goto err;
if (!X509_set_version(x, 2))
goto err;
if (!(name= X509_get_subject_name(x)))
goto err;
if (!X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, (const unsigned char *)"x",1,-1,0))
goto err;
if (!X509_set_issuer_name(x, name))
goto err;
if (!X509_gmtime_adj(X509_get_notBefore(x), 0))
goto err;
if (!X509_gmtime_adj(X509_get_notAfter(x), 60 * 60 * 24 * 365 * 10))
goto err;
if (!X509_set_pubkey(x, pkey))
goto err;
if (!X509_sign(x, pkey, EVP_sha256()))
goto err;
return x;
err:
X509_free(x);
return NULL;
}
int main()
{
printf("Hello\n");
unsigned long long start,end,freq;
QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
QueryPerformanceCounter((LARGE_INTEGER*)&start);
auto key= vio_keygen();
if (!key)
{
printf("Failed to generate key\n");
return 1;
}
QueryPerformanceCounter((LARGE_INTEGER*)&end);
printf("Keygen took %f seconds\n", (end-start)/(double)freq);
auto cert= vio_gencert(key);
if (!cert)
{
printf("Failed to generate cert\n");
return 1;
}
printf("Success\n");
return 0;
} Stacktrace just before the crash:
|
Hi @vaintroub, I've put up another pull request that should fix this issue now. Let us know if this does fix the issue. Thanks, |
Perfect, this patch seems to have fixed the issue. thank you! |
Great to hear! Sean |
Contact Details
[email protected]
Version
5.7.0
Description
This happens in MariaDB, which uses WolfSSL 5.7.0 (compiles as submodule), using SP_MATH_ALL with assembly support.
Most recent version of MariaDB would call wolfSSL_EVP_PKEY_keygen to generate 4096 bit large private key, to then generate an "ephemeral" server SSL certificate, if user does not provide own.
So far it worked well for us, however there is a recent bug report MDEV-34372 about invalid instruction exception, and attached crashdump confirms that instruction comes from AVX instruction set.
wolfssl\wolfcrypt\src\sp_x86_64_asm.asm, line 13172
Mostly likely, the code did not check CPUID before using it.
this is how we build it
here is generated user_settings.h
Reproduction steps
I did not reproduce myself, so the dump and the log is only thing I have, filing on behalf of our user
It would be something like that
Relevant log output
The text was updated successfully, but these errors were encountered: