Validate siglen against modulus_len in PSS decode #807
No reviewers
Labels
No labels
bug
duplicate
enhancement
feature
help wanted
improve API
invalid
needs documentation
not-planned
rtfm
stale
support
wishlist
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libtom/libtomcrypt!807
Loading…
Reference in a new issue
No description provided.
Delete branch "afonsojanu/fix/pss-decode-siglen-check"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #802.
ltc_pkcs_1_pss_decode_mgf1checkssaltlenandmodulus_lenbut never checks thatsiglenactually matchesmodulus_len. Later on it does:which copies
modulus_len - 1bytes total out ofsig, based purely onmodulus_len. Ifsiglen < modulus_len, this reads past the end of the caller's buffer.rsa_verify_hash_v2happens to avoid triggering this today, because it always passes a buffer of exactlymodulus_len(ormodulus_len - 1whenmodulus_bitlen % 8 == 1, handled via its ownx - 1adjustment) into the decode call. Butltc_pkcs_1_pss_decode_mgf1is also reachable directly through the public (deprecated)pkcs_1_pss_decode()API, which forwards whateversiglenthe caller passes with no validation at all — so a caller of that API supplying a genuinely truncated signature buffer hits the out-of-bounds read.Fix: add
siglen != modulus_lento the existing size-checkif, matching the suggested fix in the issue.Added a regression test in
tests/pkcs_1_pss_test.cthat callspkcs_1_pss_decode()directly with a signature one byte shorter than the modulus and asserts it's rejected withCRYPT_PK_INVALID_SIZErather than being processed. Verified with git-stash: reverting only the fix inpkcs_1_pss_decode.cmakes the new assertion fail (on the very first PSS test vector) while everything else still passes; with the fix restored, the full suite passes (SUCCESS: passed=30 failed=0 nop=1).Built and tested locally against LibTomMath (
USE_LTM/LTM_DESC) on macOS/arm64.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.