C_Verify/C_Sign/C_Encrypt with CKM_RSA_X_509 and data longer than the modulus terminate the application (exit 5) instead of CKR_DATA_LEN_RANGE
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
Direzione di ricerca
Leggi AsymEncrypt, AsymSign e AsymVerify in src/lib/SoftHSM.cpp, poi segui il modo in cui ciascuno gestisce l’input CKM_RSA_X_509 prima del padding con zeri. Controlla i test esistenti per queste operazioni PKCS#11 e aggiungi casi con un input più lungo del modulo; il lavoro è completato quando tutti e tre restituiscono CKR_DATA_LEN_RANGE senza terminare il processo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
C_Verify, C_Sign and C_Encrypt with CKM_RSA_X_509 and more data than the modulus has bytes make SoftHSM call exit(5). The calling application terminates and never gets a return code. With a 2048-bit key, 257 bytes is enough.
Seen on 2.7.0-28-g884cb38. The code is the same on main (9ad8734).
Expected (PKCS#11 v3.2)
§6.1.12 (Table 45, CKM_RSA_X_509): the input is at most k bytes, where k is the length of the modulus in bytes. For more than that, the call returns CKR_DATA_LEN_RANGE (§5.1.6), and the process keeps running.
Results
These ran logged in as the user, with a session RSA-2048 key pair, each case in its own process:
| Call | Data | Result |
|---|---|---|
C_Verify(CKM_RSA_X_509) |
256 bytes (control) | CKR_OK |
C_Verify(CKM_RSA_X_509) |
257 bytes | process exits with status 5 |
C_Sign(CKM_RSA_X_509) |
256 bytes (control) | CKR_OK |
C_Sign(CKM_RSA_X_509) |
257 bytes | process exits with status 5 |
C_Encrypt(CKM_RSA_X_509) |
256 bytes (control) | CKR_OK |
C_Encrypt(CKM_RSA_X_509) |
257 bytes | process exits with status 5 |
Each exit is preceded in syslog by:
src/lib/common/fatal.cpp(56): A fatal exception occurred; exiting...
Cause
AsymEncrypt, AsymSign and AsymVerify in src/lib/SoftHSM.cpp zero-pad raw RSA input to the modulus length, with no check that the input fits:
// We must allow input length <= k and therfore need to prepend the data with zeroes.
if (mechanism == AsymMech::RSA) {
data.wipe(size-ulDataLen);
}
When ulDataLen > size, size - ulDataLen wraps around to nearly 2^64, so ByteString::wipe → resize throws std::length_error. The catch (...) in main.cpp calls FatalException(), which wipes the secure memory and calls exit(CKR_GENERAL_ERROR).
Suggested fix
Check the length before padding, in all three functions:
if (mechanism == AsymMech::RSA) {
if (ulDataLen > size) {
session->resetOp();
return CKR_DATA_LEN_RANGE;
}
data.wipe(size-ulDataLen);
}
Context
The length comes from the caller, so any application that passes unchecked input to raw RSA is ended by the library. That includes one that sits behind p11-kit remoting or a PKCS#11 proxy. Found while running the KerckhoffsLabs.Security.Cryptography.Pkcs11 conformance suite, which has to skip this case on SoftHSM2.
- Lingua principale
- C++
- Stelle
- 1.1k
- Fork
- 434
- Merge medio
- 12g 14h
- PR unite (30g)
- 2
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di softhsm/SoftHSMv2
-
C_DigestKey digests a sensitive EC private key's CKA_VALUE: no check that the object is a secret keyAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 54/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 56/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 57/100
Tutte le issue di softhsm/SoftHSMv2
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
charmplusplus/charm#4210 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
[BUG] VPN auth dialog spawned by the secret agent fails with "TLS support is not available" on NixOSApertabug nixos umbriel
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
noctalia-dev/noctalia#5310 ·
I maintainer di solito rispondono entro 1 giorno
-
area/docdb kind/bug priority/medium status/awaiting-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
yugabyte/yugabyte-db#37426 ·
I maintainer di solito rispondono entro 1 giorno