Repository navigation
crypto: fix the RSA parameter mismatch and the out-of-bounds key parameter - #22862
Open
ThePassionate wants to merge 2 commits into
Open
ThePassionate wants to merge 2 commits into
ThePassionate wants to merge 2 commits into
Conversation
Number the RSA components by the cryptkop parameter that carries them and load a component always from krp_param[slot] into comp[slot]. The old two-argument swcr_rsa_load() allowed a caller to read a component from a parameter other than its own slot, and swcr_mod_exp() used that freedom to read the exponent from param[1] and the modulus from param[2]; the rpmsg and vhost transports fill param[1] with n and param[2] with e, so their CRK_MOD_EXP requests reached the software backend with the modulus and the exponent swapped. swcr_rsa_verify() read the same slots from yet another layout on top of that; align it with the transports: params 0 = signature, 1 = n, 2 = e, 3 = padding, 4 = hash. Signed-off-by: makejian <makejian@xiaomi.com>
An RSA private key spans nine input parameters - the operand, n, e, d, p, q, dp, dq and qp - and a request that returns a result needs a tenth for the output. The rpmsg crypto server and the vhost-crypto backend already fill krp_param[8] with qp, which is one past the end of an eight-entry array: the write lands on krp_callback, the function pointer the framework calls when the request completes. Signed-off-by: makejian <makejian@xiaomi.com>
ThePassionate
requested review from
jerpelea,
simbit18 and
xiaoxiang781216
as code owners
December 4, 2026 04:52
|
xiaoxiang781216
approved these changes
Dec 4, 2026
jerpelea
approved these changes
Dec 4, 2026
ThePassionate
force-pushed
the
crypto-rsa-abi-fixes
branch
from
December 4, 2026 08:22
4b5803f to
85721e5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two defects in the RSA path of the software crypto backend, both reachable
only through the rpmsg and vhost transports, which is why the in-tree tests
have not caught them.
1. The modulus and the exponent are read from each other's parameter.
swcr_rsa_load()took a component number and a parameter number separately,so a caller could read a component from a parameter other than its own slot,
and
swcr_mod_exp()used that to read the exponent fromparam[1]and themodulus from
param[2]. The rpmsg crypto server and the vhost-crypto backendboth fill
param[1]with n andparam[2]with e, so aCRK_MOD_EXPrequestthat arrives over either transport is computed with the two swapped.
The fix numbers a component by the parameter that carries it, which removes
the mismatch by construction:
param[1]is always n,param[2]is alwaysthe exponent.
swcr_rsa_verify()read its own third layout and is alignedwith the transports as well.
2.
CRK_MAXPARAMis too small for an RSA private key, and the transportsalready write past the array. A private key spans nine input parameters
(the operand, n, e, d, p, q, dp, dq, qp) and a request returning a result
needs a tenth. With
CRK_MAXPARAMat 8 the valid indices are 0..7, yetrpmsg_crypto_server.c,rpmsg_crypto.candvhost-crypto.call assignkrp_param[8]. Instruct cryptkopthat write lands exactly onkrp_callback, the function pointer the framework calls on completion:Impact
CRK_MOD_EXPover rpmsg or vhost produced a wrong result; a private-keyrequest over either transport corrupted a function pointer. Local requests
through
/dev/cryptowere not affected by the first defect as long as thecaller matched what cryptosoft read, which the in-tree tests did.
The parameter order is now the one the transports use, so two tests that
passed the exponent first need the matching change; that goes through
apache/nuttx-apps#4291 and the two should land together.
Testing
sim:crypto, built and run on Linux:rsa— 3/3 cases pass, including the tampered-signature rejectionaescbc,aesctr,aesxts,des3cbc,hmac,chachapoly— all passtools/checkpatch.sh -c -u -m -gclean over the series