-
Notifications
You must be signed in to change notification settings - Fork 180
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
bn_mod_barrt out-of-bounds write and hang #222
Comments
Thanks! With 87cb595 the code now falls back to long division in case the input to Barrett reduction is too long. |
Tested at 87cb595: #include <relic_conf.h>
#include <relic.h>
int main(void)
{
if ( core_init() != RLC_OK ) abort();
bn_t A, B, tmp, R;
bn_null(A); bn_new(A);
bn_null(B); bn_new(B);
bn_null(tmp); bn_new(tmp);
bn_null(R); bn_new(R);
const char* s1 = "379220024083016978237080970674718990000000000000000000000000000000000000000000000000000000000000000000000000000000400001000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005555555000001000000000000000000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000072057594037927935000000000000000000000000000000000000000";
const char* s2 = "6777215000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000032317006071311007300714876688678908931972014115229134636887179609218980194941195591504909210950881525864482831206308773673009960917501977503896521517960576383840675682767922186426197561618380943384761704705816458520363050428875758915410658086075523991239303859919143333899668342430855568497478556456949485617607598351150301582835151321971577101803084265674677361251231136292707753237390374856789689487223767233095444444444444444444444444444444445344444444444308944440488444444344534444444444444444444444444444444444444444551444";
bn_read_str(A, s1, strlen(s1), 10);
bn_read_str(B, s2, strlen(s2), 10);
bn_mod_pre_barrt(tmp, B);
bn_mod_barrt(R, A, B, tmp);
bn_free(A);
bn_free(B);
bn_free(tmp);
bn_free(R);
return 0;
}
|
Oh, the fix triggered a different bug, potentially fixed by 384468a |
Fixed for my previous reproducer, but: #include <relic_conf.h>
#include <relic.h>
int main(void)
{
if ( core_init() != RLC_OK ) abort();
bn_t A, B, tmp, R;
bn_null(A); bn_new(A);
bn_null(B); bn_new(B);
bn_null(tmp); bn_new(tmp);
bn_null(R); bn_new(R);
const char* s1 = "2";
const char* s2 = "1";
bn_read_str(A, s1, strlen(s1), 10);
bn_read_str(B, s2, strlen(s2), 10);
bn_mod_pre_barrt(tmp, B);
bn_mod_barrt(R, A, B, tmp);
bn_free(A);
bn_free(B);
bn_free(tmp);
bn_free(R);
return 0;
}
|
You found a gradient descent of interlinked bugs! There is a more principled attempt to fix at 3563cb2 |
Confirmed fixed as far as I can tell now. If there's anything more we will hear it from OSS-Fuzz. |
OOB write:
Hang:
The text was updated successfully, but these errors were encountered: