Commit graph

22484 commits

Author SHA1 Message Date
Gilles Peskine
4f01121f6e Fix memory leak on error in pkcs7_get_signers_info_set
mbedtls_x509_name allocates memory, which must be freed if there is a
subsequent error.

Credit to OSS-Fuzz (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=53811).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-27 22:02:10 +01:00
Gilles Peskine
e7f8c616d0 Fix dangling freed pointer in pkcs7_free_signer_info
This may have been a use-after-free, but I haven't worked out whether it was
a problem or not. Even if it turns out to have been ok, keeping invalid
pointers around is fragile.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-27 21:55:29 +01:00
Gilles Peskine
47a732635b Simplify control flow in PKCS7 functions
Remove useless goto in several functions.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-27 21:55:29 +01:00
Gilles Peskine
391005cb3b Fix structures initialized too late in tests
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-27 21:55:29 +01:00
Gilles Peskine
2336555444 Improve test failure reporting
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-27 21:55:29 +01:00
Gilles Peskine
290f01b3f5 Fix dangling freed pointer on error in pkcs7_get_signers_info_set
This fixes a use-after-free in PKCS#7 parsing when the signer data is
malformed.

Credit to OSS-Fuzz (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=53798).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-27 21:55:29 +01:00
Janos Follath
e7190a2960 mpi_mod_io_neg: fix use of uninitialized value
Uninitialized values are invalid for the tested functions and we
shouldn't be testing that.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-26 18:46:54 +00:00
Janos Follath
6eb92c0410 Bignum Mod: improve documentation and style
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-26 17:34:37 +00:00
Janos Follath
0020df9cf9 mpi_mod_io: test with various buffer sizes
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-26 17:23:16 +00:00
Janos Follath
8dfc8c41b7 mbedtls_mpi_mod_write: prevent data corruption
The function wasn't converting back data to internal representation when
writing it out.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-26 15:39:02 +00:00
Janos Follath
d7bb35257b mbedtls_mpi_mod_read/write: restrict pre-conditions
Require equality for the number of limbs in the modulus and the residue.
This makes these functions consistent with residue_setup().

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-26 14:59:27 +00:00
Janos Follath
75b9f0fd2e mbedtls_mpi_mod_read/write: remove redundant checks
The function isn't documented as accepting null pointer, and there's no
reason why it should be. Just let it dereference the pointer.

The null/zero checks are only marginally useful: they validate that m
and r are properly populated objects, not freshly initialized ones. For
that, it's enough to check that the pointers aren't null or that the
sizes aren't zero, we don't need to check both.

Also, use separate if statements for unrelated checks.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-26 14:28:50 +00:00
Janos Follath
6ef582f2b8 Bignum Mod Tests: improve readabilty and style
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-26 14:19:02 +00:00
Gilles Peskine
89e31adbee Move mps modules to the correct library
This is a private interface only, so it's an ABI change but not an API change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-26 14:18:45 +01:00
Gilles Peskine
898db6b8e5 Move ssl_debug_helpers_generated to the correct library
This is a private interface only, so it's an ABI change but not an API change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-26 14:15:32 +01:00
Janos Follath
339b439906 Bignum Mod: remove unused parameter in io_neg test
The value was overwritten and the length wasn't used either. This latter
could have lead to a buffer overflow as well.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-26 12:24:34 +00:00
Janos Follath
566c91db27 Bignum Mod: io_neg test pass data directly
Pass buffer directly instead of constructing it in the function.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-26 12:24:34 +00:00
Minos Galanakis
96070a53a8 bignum_tests: Refactored mpi_mod_io_neg()
This patch refactores the negative testing suite
to utilised non-hardcoded input data.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-11-26 12:24:34 +00:00
Janos Follath
91f3abdfda Bignum Mod: improve residue_setup test
- Rename input variables to match their purpose.
- Assert fields upon success

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-26 12:24:34 +00:00
Janos Follath
f55505d38b Bignum Mod Raw: fix tests after rebase
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-25 17:58:40 +00:00
Janos Follath
799eaeefdb Bignum Mod: move init before any goto
Test macros have goto instructions to the end where everything is freed.
We need to call init before that happens to make calling free functions
safe.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-25 17:55:00 +00:00
Janos Follath
ee530cc644 Bignum Mod: improve documentation
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-25 17:55:00 +00:00
Janos Follath
fc6fbb4e96 Bignum Mod: improve documentation
Signed-off-by: Janos Follath <janos.follath@arm.com>

Co-authored-by: Tom Cosgrove <tom.cosgrove@arm.com>
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-25 17:55:00 +00:00
Janos Follath
41427dee80 Bignum Mod: improve documentation
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-25 17:55:00 +00:00
Janos Follath
91295d2b8f Bignum Mod: remove endianness from modulus
The external representation before included more than just endianness
(like reading in Mongtomery curve scalars or converting hashes to
numbers in a standard compliant way).

These are higher level concepts and are out of scope for Bignum and for
the modulus structure.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-25 17:55:00 +00:00
Janos Follath
3e3fc91c33 Bignum Mod: pass endianness as a parameter
The external representation before included more than just endianness
(like reading in Mongtomery curve scalars or converting hashes to
numbers in a standard compliant way).

These are higher level concepts and are out of scope for Bignum and for
the modulus structure.

Passing endianness as a parameter is a step towards removing it from the
modulus structure.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-25 17:55:00 +00:00
Janos Follath
d3eed33709 Bignum Mod Raw: pass endianness as a parameter
The external representation before included more than just endianness
(like reading in Mongtomery curve scalars or converting hashes to
numbers in a standard compliant way).

These are higher level concepts and are out of scope for Bignum and for
the modulus structure.

Passing endianness as a parameter is a step towards removing it from the
modulus structure.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-25 17:55:00 +00:00
Janos Follath
50cd4b842b Bignum Mod: Restrict residue setup
In theory we could allow residues to have more allocated limbs than the
modulus, but we might or might not need it in the end.

Go for the simpler option for now and we can extend it later if we
really need it.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-25 17:55:00 +00:00
Janos Follath
b62bad442e Bidnum Mod: fix check in setup
We want to make sure that the value has at least as many limbs allocated
as the modulus as we need this to be able to do any operations in
constant time.

An invariant of the API is that the residue values are canonical, make
sure that the residue is compared to the entire modulus.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-25 17:55:00 +00:00
Minos Galanakis
8b375451c5 bignum_mod: Refactored mbedtls_mpi_mod_read/write()
This patch adjusts the I/O methods and the tests.
Documentation has also been updated to be more clear.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-11-25 17:55:00 +00:00
Minos Galanakis
aed832ac16 bignum_mod: Adjusted input checking for mbedtls_mpi_mod_residue_setup()
This patch adjusts the logic of the size checking of the method,
and refactors the tests. Documentation has also been updated.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-11-25 17:55:00 +00:00
Minos Galanakis
a17ad48e2d bignum_mod: Fixed an issue with input checking in mpi_mod_residue_setup
This patch is inverting the input type checking logic in the method,
in order to ensure that residue < modulus.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-11-25 17:55:00 +00:00
Minos Galanakis
8f24270630 test_suite_bignum_mod: Added tests for hight level IO
This patch adds the following tests for the high levet IO api:
* mpi_mod_io_neg
* mpi_mod_io

Manually generated test data has also been included.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-11-25 17:55:00 +00:00
Minos Galanakis
81f4b11010 bignum_mod: Added mbedtls_mpi_mod_read/write() IO functions
This patch adds input and ouput fucntions in the `bignum_mod` layer.
The data will be automatically converted between Cannonical and
Montgomery representation if required.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-11-25 17:55:00 +00:00
Janos Follath
590ae5363d
Merge pull request #6656 from tom-cosgrove-arm/bignum_pr_6225-updated
Bignum: add mod_raw_add
2022-11-25 17:53:31 +00:00
Dave Rodgman
bf9b23abf8
Merge pull request #6648 from gilles-peskine-arm/psa-ecb-null-0
Fix NULL+0 undefined behavior in PSA crypto ECB
2022-11-25 17:07:46 +00:00
David Horstmann
119d7e2011 Fix typo 'unsupoported' -> 'unsupported'
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2022-11-25 15:50:30 +00:00
Bence Szépkúti
6e85673e8d
Merge pull request #3431 from naynajain/development-pkcs7
PKCS7 Parser - RFC 2315
2022-11-25 15:55:46 +01:00
Tom Cosgrove
ddad40b1de Free the modulus before the data in it in mod_raw_add tests
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-11-25 14:18:52 +00:00
Janos Follath
505a228b7b
Merge pull request #6606 from gabor-mezei-arm/6222_bignum_low_level_subtraction
Bignum: Add low level subtraction
2022-11-25 13:27:23 +00:00
Gilles Peskine
7d23778178 Explain why p + n isn't good enough
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-25 13:34:59 +01:00
Gilles Peskine
5a34b36bbd Remove more now-redundant definitions of inline
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-25 13:26:44 +01:00
Dave Rodgman
f1419dbbe8
Merge pull request #6381 from tom-cosgrove-arm/pr2164
mbedtls: fix possible false success in mbedtls_cipher_check_tag()
2022-11-25 10:55:10 +00:00
Manuel Pégourié-Gonnard
6a543ba1d3 Remove redundant component in all.sh
CID is now enabled in the default config (as well as full), so it's
already tested in numerous all.sh components, not need to add one for
that.

We need a component for the legacy/compat option though as it's never
enabled in existing components. So, keep that one, but adjust the name
and fix a typo in a message.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-11-25 11:48:17 +01:00
Manuel Pégourié-Gonnard
5a454f7781 Remove redundant tests in ssl-opt.sh
We don't need to have two copies of the test with one of them depending
on legacy/compat CID: we can have just one copy, but make sure we run
ssl-opt.sh both in a build with standard CID and in a build with
legacy/compat - that's the job of all.sh (see next commit).

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-11-25 11:48:17 +01:00
Manuel Pégourié-Gonnard
61336848a9 Fix bug when legacy CID is enabled but not used
When legacy CID is enabled at compile time, but not used at runtime, we
would incorrectly skip the sequence number at the beginning of the AAD.

There was already two "else" branches for writing the sequence number
but none of them was taken in that particular case.

Simplify the structure of the code: with TLS 1.2 (we're already in that
branch), we always write the sequence number, unless we're using
standard CID.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-11-25 11:48:17 +01:00
Hannes Tschofenig
db01d05011 Removal of redundant DTLS CID test in ssl-opt.sh
Per suggestion from Manuel, I removed this redundant test.

Signed-off-by: Hannes Tschofenig <hannes.tschofenig@arm.com>
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-11-25 11:19:19 +01:00
Hannes Tschofenig
df84bb30ab Removed MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH from CID tests in all.sh
Added also extra text.

Signed-off-by: Hannes Tschofenig <hannes.tschofenig@arm.com>
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-11-25 11:19:11 +01:00
Hannes Tschofenig
6b6b63f039 Added closing SECTION of doxygen markup
Signed-off-by: Hannes Tschofenig <hannes.tschofenig@arm.com>
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-11-25 11:19:05 +01:00
Hannes Tschofenig
b2e6615625 Added deprecated warning in check_config.h
Warns about the removal of the legacy DTLS Connection ID feature in a future version of Mbed TLS.

Signed-off-by: Hannes Tschofenig <hannes.tschofenig@arm.com>
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-11-25 11:18:57 +01:00