Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/wolfsshd/wolfsshd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,8 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
}
}

ForceZero(channelBuffer, sizeof channelBuffer);
ForceZero(shellBuffer, sizeof shellBuffer);
(void)conn;
return WS_SUCCESS;
}
Expand Down
4 changes: 2 additions & 2 deletions src/agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -1582,10 +1582,10 @@ void wolfSSH_AGENT_ID_free(WOLFSSH_AGENT_ID* id, void* heap)

if (id != NULL) {
if (id->keyBuffer != NULL) {
WMEMSET(id->keyBuffer, 0, id->keyBufferSz);
ForceZero(id->keyBuffer, id->keyBufferSz);
WFREE(id->keyBuffer, heap, DYNTYPE_STRING);
}
WMEMSET(id, 0, sizeof(WOLFSSH_AGENT_ID));
ForceZero(id, sizeof(WOLFSSH_AGENT_ID));
WFREE(id, heap, DYNTYPE_AGENT_ID);
}

Expand Down
38 changes: 37 additions & 1 deletion src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,10 @@ void SshResourceFree(WOLFSSH* ssh, void* heap)
HandshakeInfoFree(ssh->handshake, heap);
ForceZero(&ssh->keys, sizeof(Keys));
ForceZero(&ssh->peerKeys, sizeof(Keys));
ForceZero(ssh->h, sizeof(ssh->h));
ssh->hSz = 0;
ForceZero(ssh->sessionId, sizeof(ssh->sessionId));
ssh->sessionIdSz = 0;
if (ssh->rng) {
wc_FreeRng(ssh->rng);
WFREE(ssh->rng, heap, DYNTYPE_RNG);
Expand Down Expand Up @@ -2794,6 +2798,11 @@ static int SetHostPrivateKey(WOLFSSH_CTX* ctx,
}

if (destIdx >= WOLFSSH_MAX_PVT_KEYS) {
/* CTX is full and keyId is new: der cannot be stored, so this
* function takes ownership and zeroizes+frees it to avoid leaking
* the private key material. */
ForceZero(der, derSz);
WFREE(der, ctx->heap, dynamicType);
ret = WS_CTX_KEY_COUNT_E;
}
else {
Expand Down Expand Up @@ -3552,6 +3561,8 @@ void ChannelDelete(WOLFSSH_CHANNEL* channel, void* heap)
if (channel->origin)
WFREE(channel->origin, heap, DYNTYPE_STRING);
#endif /* WOLFSSH_FWD */
if (channel->inputBuffer.buffer)
ForceZero(channel->inputBuffer.buffer, channel->inputBuffer.bufferSz);
WFREE(channel->inputBuffer.buffer,
channel->inputBuffer.heap, DYNTYPE_BUFFER);
if (channel->command)
Expand Down Expand Up @@ -6664,6 +6675,9 @@ static int KeyAgreeEcdhMlKem_client(WOLFSSH* ssh, byte hashId,
ret);
}

/* Zero the ML-KEM private key material in handshake->x now that
* decapsulation is done, matching the DH path's post-use ForceZero. */
ForceZero(ssh->handshake->x, ssh->handshake->xSz);
wc_MlKemKey_Free(&kem);

/* Replace the concatenated shared secrets with the hash. That
Expand Down Expand Up @@ -8274,8 +8288,11 @@ static int DoUserAuthRequestRsa(WOLFSSH* ssh, WS_UserAuthData_PublicKey* pk,
WFREE(key, ssh->ctx->heap, DYNTYPE_PUBKEY);
}
if (encDigest) {
ForceZero(encDigest, MAX_ENCODED_SIG_SZ);
WFREE(encDigest, ssh->ctx->heap, DYNTYPE_BUFFER);
}
#else
ForceZero(encDigest, sizeof(encDigest));
#endif

WLOG(WS_LOG_DEBUG, "Leaving DoUserAuthRequestRsa(), ret = %d", ret);
Expand Down Expand Up @@ -8435,8 +8452,11 @@ static int DoUserAuthRequestRsaCert(WOLFSSH* ssh, WS_UserAuthData_PublicKey* pk,
WFREE(key, ssh->ctx->heap, DYNTYPE_PUBKEY);
}
if (encDigest) {
ForceZero(encDigest, MAX_ENCODED_SIG_SZ);
WFREE(encDigest, ssh->ctx->heap, DYNTYPE_BUFFER);
}
#else
ForceZero(encDigest, sizeof(encDigest));
#endif

WLOG(WS_LOG_DEBUG, "Leaving DoUserAuthRequestRsaCert(), ret = %d", ret);
Expand Down Expand Up @@ -9477,6 +9497,8 @@ static int DoUserAuthRequestPublicKey(WOLFSSH* ssh, WS_UserAuthData* authData,
ret = WS_INVALID_ALGO_ID;
}
}

ForceZero(digest, sizeof(digest));
}

if (ret != WS_SUCCESS) {
Expand Down Expand Up @@ -14059,9 +14081,14 @@ static int SignHRsa(WOLFSSH* ssh, byte* sig, word32* sigSz,
&sigKey->sk.rsa.key, heap, "SignHRsa");
}

ForceZero(digest, sizeof(digest));
#ifdef WOLFSSH_SMALL_STACK
if (encSig != NULL)
if (encSig != NULL) {
ForceZero(encSig, MAX_ENCODED_SIG_SZ);
WFREE(encSig, heap, DYNTYPE_TEMP);
}
#else
ForceZero(encSig, MAX_ENCODED_SIG_SZ);
#endif
WLOG(WS_LOG_DEBUG, "Leaving SignHRsa(), ret = %d", ret);
return ret;
Expand Down Expand Up @@ -14203,6 +14230,7 @@ static int SignHEcdsa(WOLFSSH* ssh, byte* sig, word32* sigSz,
WMEMCPY(sig + idx, s, sSz);
}

ForceZero(digest, sizeof(digest));
#ifdef WOLFSSH_SMALL_STACK
if (r)
WFREE(r, heap, DYNTYPE_BUFFER);
Expand Down Expand Up @@ -16227,6 +16255,8 @@ static int BuildUserAuthRequestRsa(WOLFSSH* ssh,

if (ret == WS_SUCCESS)
begin += keySig->sigSz;

ForceZero(encDigest, sizeof(encDigest));
}
}

Expand All @@ -16238,6 +16268,7 @@ static int BuildUserAuthRequestRsa(WOLFSSH* ssh,
WFREE(checkData, ssh->ctx->heap, DYNTYPE_TEMP);
}

ForceZero(digest, sizeof(digest));
return ret;
} /* END BuildUserAuthRequestRsa */

Expand Down Expand Up @@ -16407,6 +16438,8 @@ static int BuildUserAuthRequestRsaCert(WOLFSSH* ssh,

if (ret == WS_SUCCESS)
begin += keySig->sigSz;

ForceZero(encDigest, sizeof(encDigest));
}
}

Expand All @@ -16418,6 +16451,7 @@ static int BuildUserAuthRequestRsaCert(WOLFSSH* ssh,
WFREE(checkData, ssh->ctx->heap, DYNTYPE_TEMP);
}

ForceZero(digest, sizeof(digest));
WLOG(WS_LOG_DEBUG, "Leaving BuildUserAuthRequestRsaCert(), ret = %d",
ret);
return ret;
Expand Down Expand Up @@ -16685,6 +16719,7 @@ static int BuildUserAuthRequestEcc(WOLFSSH* ssh,
WFREE(checkData, ssh->ctx->heap, DYNTYPE_TEMP);
}

ForceZero(digest, sizeof(digest));
#ifdef WOLFSSH_SMALL_STACK
if (r_ptr)
WFREE(r_ptr, ssh->ctx->heap, DYNTYPE_BUFFER);
Expand Down Expand Up @@ -16945,6 +16980,7 @@ static int BuildUserAuthRequestEccCert(WOLFSSH* ssh,
WFREE(checkData, ssh->ctx->heap, DYNTYPE_TEMP);
}

ForceZero(digest, sizeof(digest));
return ret;
}

Expand Down
4 changes: 4 additions & 0 deletions src/wolfsftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ static void wolfSSH_SFTP_ClearState(WOLFSSH* ssh, enum WS_SFTP_STATE_ID state)

if (state & STATE_ID_GET) {
if (ssh->getState) {
ForceZero(ssh->getState, sizeof(WS_SFTP_GET_STATE));
WFREE(ssh->getState, ssh->ctx->heap, DYNTYPE_SFTP_STATE);
ssh->getState = NULL;
}
Expand Down Expand Up @@ -928,6 +929,7 @@ static void wolfSSH_SFTP_ClearState(WOLFSSH* ssh, enum WS_SFTP_STATE_ID state)

if (state & STATE_ID_PUT) {
if (ssh->putState) {
ForceZero(ssh->putState, sizeof(WS_SFTP_PUT_STATE));
WFREE(ssh->putState, ssh->ctx->heap, DYNTYPE_SFTP_STATE);
ssh->putState = NULL;
}
Expand Down Expand Up @@ -9775,6 +9777,7 @@ int wolfSSH_SFTP_Get(WOLFSSH* ssh, char* from,
case STATE_GET_CLEANUP:
WLOG(WS_LOG_SFTP, "SFTP GET STATE: CLEANUP");
if (ssh->getState != NULL) {
ForceZero(ssh->getState, sizeof(WS_SFTP_GET_STATE));
WFREE(ssh->getState, ssh->ctx->heap, DYNTYPE_SFTP_STATE);
ssh->getState = NULL;
}
Expand Down Expand Up @@ -9998,6 +10001,7 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume,
case STATE_PUT_CLEANUP:
WLOG(WS_LOG_SFTP, "SFTP PUT STATE: CLEANUP");
if (ssh->putState != NULL) {
ForceZero(ssh->putState, sizeof(WS_SFTP_PUT_STATE));
WFREE(ssh->putState, ssh->ctx->heap, DYNTYPE_SFTP_STATE);
ssh->putState = NULL;
}
Expand Down
Loading