Skip to content

Commit 8527be5

Browse files
committed
Fix UAF in callback wrapper and add input validation guards
1 parent c36beba commit 8527be5

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/ssl.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8013,9 +8013,16 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
80138013
FreeTimeoutInfo(&ssl->timeoutInfo, ssl->heap);
80148014

80158015
if (hsCb) {
8016+
HandShakeInfo savedHandShakeInfo;
80168017
FinishHandShakeInfo(&ssl->handShakeInfo);
8017-
(hsCb)(&ssl->handShakeInfo);
8018+
XMEMCPY(&savedHandShakeInfo, &ssl->handShakeInfo,
8019+
sizeof(HandShakeInfo));
80188020
ssl->hsInfoOn = 0;
8021+
/* Null out the ssl pointer -- the callback must not free the
8022+
* session through it, and ssl may already have been freed by
8023+
* toCb above. */
8024+
savedHandShakeInfo.ssl = NULL;
8025+
(hsCb)(&savedHandShakeInfo);
80198026
}
80208027
return ret;
80218028
}

wolfcrypt/src/cryptocb.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,10 @@ int wc_CryptoCb_RegisterDevice(int devId, CryptoDevCallbackFunc cb, void* ctx)
403403
{
404404
int rc = 0;
405405

406+
if (devId == INVALID_DEVID) {
407+
return BAD_FUNC_ARG;
408+
}
409+
406410
/* find existing or new */
407411
CryptoCb* dev = wc_CryptoCb_GetDevice(devId);
408412
if (dev == NULL)

wolfcrypt/src/memory.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,9 @@ int wc_LoadStaticMemory_ex(WOLFSSL_HEAP_HINT** pHint,
715715
if (pHint == NULL || buf == NULL || sizeList == NULL || distList == NULL) {
716716
return BAD_FUNC_ARG;
717717
}
718+
if (listSz == 0) {
719+
return BAD_FUNC_ARG;
720+
}
718721

719722
/* Cap the listSz to the actual number of items allocated in the list. */
720723
if (listSz > WOLFMEM_MAX_BUCKETS) {
@@ -831,6 +834,9 @@ int wolfSSL_StaticBufferSz_ex(unsigned int listSz,
831834
if (buffer == NULL || sizeList == NULL || distList == NULL) {
832835
return BAD_FUNC_ARG;
833836
}
837+
if (listSz == 0) {
838+
return BAD_FUNC_ARG;
839+
}
834840

835841
/* Cap the listSz to the actual number of items allocated in the list. */
836842
if (listSz > WOLFMEM_MAX_BUCKETS) {

wolfcrypt/src/wc_pkcs11.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3694,6 +3694,8 @@ static int Pkcs11ECDSASig_Decode(const byte* in, word32 inSz, byte* sig,
36943694
ret = ASN_PARSE_E;
36953695
if (ret == 0 && (len = in[i++]) > sz + 1)
36963696
ret = ASN_PARSE_E;
3697+
if (ret == 0 && len == 0)
3698+
ret = ASN_PARSE_E;
36973699
/* Check there is space for INT data */
36983700
if (ret == 0 && i + len > inSz)
36993701
ret = ASN_PARSE_E;
@@ -3718,6 +3720,8 @@ static int Pkcs11ECDSASig_Decode(const byte* in, word32 inSz, byte* sig,
37183720
ret = ASN_PARSE_E;
37193721
if (ret == 0 && (len = in[i++]) > sz + 1)
37203722
ret = ASN_PARSE_E;
3723+
if (ret == 0 && len == 0)
3724+
ret = ASN_PARSE_E;
37213725
/* Check there is space for INT data */
37223726
if (ret == 0 && i + len > inSz)
37233727
ret = ASN_PARSE_E;
@@ -3762,6 +3766,12 @@ static int Pkcs11GetEccParams(Pkcs11Session* session, CK_OBJECT_HANDLE privKey,
37623766
ret = WC_HW_E;
37633767
}
37643768
PKCS11_DUMP_TEMPLATE("Ec Params", template, 1);
3769+
if (ret == 0) {
3770+
if (template[0].ulValueLen < 2 ||
3771+
template[0].ulValueLen > sizeof(oid)) {
3772+
ret = WC_HW_E;
3773+
}
3774+
}
37653775
if (ret == 0) {
37663776
/* PKCS #11 wraps the OID in ASN.1 */
37673777
curveId = wc_ecc_get_curve_id_from_oid(oid + 2,

0 commit comments

Comments
 (0)