Skip to content

Commit 4e8fc7d

Browse files
committed
Fix UAF in callback wrapper and add input validation guards
1 parent 5074cf3 commit 4e8fc7d

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
@@ -8030,9 +8030,16 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
80308030
FreeTimeoutInfo(&ssl->timeoutInfo, ssl->heap);
80318031

80328032
if (hsCb) {
8033+
HandShakeInfo savedHandShakeInfo;
80338034
FinishHandShakeInfo(&ssl->handShakeInfo);
8034-
(hsCb)(&ssl->handShakeInfo);
8035+
XMEMCPY(&savedHandShakeInfo, &ssl->handShakeInfo,
8036+
sizeof(HandShakeInfo));
80358037
ssl->hsInfoOn = 0;
8038+
/* Null out the ssl pointer -- the callback must not free the
8039+
* session through it, and ssl may already have been freed by
8040+
* toCb above. */
8041+
savedHandShakeInfo.ssl = NULL;
8042+
(hsCb)(&savedHandShakeInfo);
80368043
}
80378044
return ret;
80388045
}

wolfcrypt/src/cryptocb.c

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

443+
if (devId == INVALID_DEVID) {
444+
return BAD_FUNC_ARG;
445+
}
446+
443447
/* find existing or new */
444448
CryptoCb* dev = wc_CryptoCb_GetDevice(devId);
445449
if (dev == NULL)

wolfcrypt/src/memory.c

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

720723
/* Cap the listSz to the actual number of items allocated in the list. */
721724
if (listSz > WOLFMEM_MAX_BUCKETS) {
@@ -832,6 +835,9 @@ int wolfSSL_StaticBufferSz_ex(unsigned int listSz,
832835
if (buffer == NULL || sizeList == NULL || distList == NULL) {
833836
return BAD_FUNC_ARG;
834837
}
838+
if (listSz == 0) {
839+
return BAD_FUNC_ARG;
840+
}
835841

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

wolfcrypt/src/wc_pkcs11.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3696,6 +3696,8 @@ static int Pkcs11ECDSASig_Decode(const byte* in, word32 inSz, byte* sig,
36963696
ret = ASN_PARSE_E;
36973697
if (ret == 0 && (len = in[i++]) > sz + 1)
36983698
ret = ASN_PARSE_E;
3699+
if (ret == 0 && len == 0)
3700+
ret = ASN_PARSE_E;
36993701
/* Check there is space for INT data */
37003702
if (ret == 0 && i + len > inSz)
37013703
ret = ASN_PARSE_E;
@@ -3720,6 +3722,8 @@ static int Pkcs11ECDSASig_Decode(const byte* in, word32 inSz, byte* sig,
37203722
ret = ASN_PARSE_E;
37213723
if (ret == 0 && (len = in[i++]) > sz + 1)
37223724
ret = ASN_PARSE_E;
3725+
if (ret == 0 && len == 0)
3726+
ret = ASN_PARSE_E;
37233727
/* Check there is space for INT data */
37243728
if (ret == 0 && i + len > inSz)
37253729
ret = ASN_PARSE_E;
@@ -3764,6 +3768,12 @@ static int Pkcs11GetEccParams(Pkcs11Session* session, CK_OBJECT_HANDLE privKey,
37643768
ret = WC_HW_E;
37653769
}
37663770
PKCS11_DUMP_TEMPLATE("Ec Params", template, 1);
3771+
if (ret == 0) {
3772+
if (template[0].ulValueLen < 2 ||
3773+
template[0].ulValueLen > sizeof(oid)) {
3774+
ret = WC_HW_E;
3775+
}
3776+
}
37673777
if (ret == 0) {
37683778
/* PKCS #11 wraps the OID in ASN.1 */
37693779
curveId = wc_ecc_get_curve_id_from_oid(oid + 2,

0 commit comments

Comments
 (0)