Fix critical stack overflow arising from VLA usage#1242
Conversation
ddb6436 to
edb9001
Compare
Codecov Report
@@ Coverage Diff @@
## master #1242 +/- ##
========================================
+ Coverage 83.2% 83.6% +0.4%
========================================
Files 82 82
Lines 14827 14867 +40
========================================
+ Hits 12342 12436 +94
+ Misses 2485 2431 -54
Continue to review full report at Codecov.
|
5d91f6f to
a2f5688
Compare
057f0ef to
c189be1
Compare
a881614 to
ed044cf
Compare
|
You should check for nullptr returns from malloc in the crypto_core
functions.
More importantly: I'm worried that putting copies of the plaintext on
the heap is a bad idea. These functions could be used for sensitive
information, right? Doing a crypto_memzero before freeing should be
enough to deal with this, afaics.
@iphy, could you comment on this please?
|
ed044cf to
242b53d
Compare
|
@zugz crypto_memzeroed it for now. |
iphydf
left a comment
There was a problem hiding this comment.
Reviewable status: 0 of 1 approvals obtained (waiting on @hugbubby and @zugz)
auto_tests/encryptsave_test.c, line 158 at r2 (raw file):
int ciphertext_length2a = size_large + TOX_PASS_ENCRYPTION_EXTRA_LENGTH; int plaintext_length2a = size_large; uint8_t *encrypted2a = (uint8_t *) malloc(ciphertext_length2a);
No space after the cast.
auto_tests/encryptsave_test.c, line 164 at r2 (raw file):
free(in_plaintext2a); //Decryption of same message.
Space after //.
toxcore/crypto_core.c, line 159 at r2 (raw file):
} size_t size_temp_plain = length + crypto_box_ZEROBYTES;
const
toxcore/crypto_core.c, line 162 at r2 (raw file):
size_t size_temp_encrypted = length + crypto_box_MACBYTES + crypto_box_BOXZEROBYTES; uint8_t *temp_plain = crypto_malloc(size_temp_plain);
uint8_t *const temp...
66cca94 to
05ea03e
Compare
|
@iphydf I... (think?) I implemented your requests correctly? Travis is complaining about a build but it seems to be unrelated. Thank you for doing the crypto_malloc and crypto_memzero, by the way. I know I said I would but somehow was under the impression that you wanted me to do it after this got merged. Sorry about that. |
|
@iphydf why is this critical fix not merged yet? can you have a look please. |
978df33 to
8ad3481
Compare
8ad3481 to
9d6b351
Compare
|
@hugbubby it's green now, but the commits aren't signed. |
77904ca to
c0514a9
Compare
Also added and used the new crypto_malloc and crypto_free. The latter also zeroes out the memory safely. The former only exists for symmetry (static analysis can detect asymmetric usages).
c0514a9 to
b4144fa
Compare
Two instances of VLA usage in the encrypt/decrypt functions of crypto_core left users vulnerable to a stack overflow. Here is a patch and addition to the encryptsave test to make sure it doesn't reappear.
This change is