Branch: refs/heads/master
Home: https://github.com/tianocore/edk2
Commit: 269d0a61949d3da385f9b95ffb887f5fbf86b489
https://github.com/tianocore/edk2/commit/269d0a61949d3da385f9b95ffb887f5fbf86b489
Author: Mingjie Shen <[email protected]>
Date: 2026-05-29 (Fri, 29 May 2026)
Changed paths:
M CryptoPkg/Library/BaseCryptLib/Pk/CryptRsaBasic.c
Log Message:
-----------
CryptoPkg: Fix leaks and failure-path mutation of RSA-owned values
RsaSetKey passed RSA-internal BIGNUMs (returned by RSA_get0_key /
RSA_get0_factors / RSA_get0_crt_params as const) directly to BN_bin2bn,
which mutates its destination in place. This violates the OpenSSL API
contract and can leave RsaContext in a partially modified state on
failure paths: BN_bin2bn has already overwritten one of
n / e / d / p / q / dp / dq / qInv, the function then returns FALSE
on a subsequent BN_dup or RSA_set0_* failure, and the caller has no
indication that the RSA object was silently changed. The same paths
also leaked temporary BIGNUMs allocated by BN_bin2bn or BN_new.
This patch splits RsaSetKey into a small input-validating dispatcher
plus three static helpers (RsaSetKeyNED, RsaSetKeyFactors,
RsaSetKeyCrtParams), one per RSA_set0_* setter. Each helper:
- Allocates a fresh BIGNUM for the slot being set via
BN_bin2bn(BigNumber, BnSize, NULL); the NULL destination forces
BN_bin2bn to allocate so no RSA-owned BIGNUM is mutated.
- Reads the current RSA state via RSA_get0_* purely for inspection.
- For slots not being set, passes NULL when RSA already has a value
(preserves it) or supplies an empty BN_new() placeholder when
RSA's slot is still NULL.
- Atomically installs via RSA_set0_*, which takes ownership of every
non-NULL argument on success and of none on failure.
- Routes all exits through a single label that frees any locally
held BIGNUM. Memory leaks in the early-return paths are fixed as
a consequence.
The previous BN_dup calls are no longer needed and are removed.
Signed-off-by: Mingjie Shen <[email protected]>
To unsubscribe from these emails, change your notification settings at
https://github.com/tianocore/edk2/settings/notifications
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits