Skip to content

Commit

Permalink
Merge pull request #79 from blooo-io/fix/LDG-696--nano-app-audit-fix-…
Browse files Browse the repository at this point in the history
…part-2

Fix/ldg 696  nano app audit fix part 2
  • Loading branch information
keiff3r authored Mar 6, 2025
2 parents 4699695 + 91b0f72 commit a5197db
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ APPNAME = "Concordium"
# Application version
APPVERSION_M = 5
APPVERSION_N = 1
APPVERSION_P = 1
APPVERSION_P = 2
APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)"

DEFINES += APPVERSION=\"$(APPVERSION)\"
Expand Down
14 changes: 9 additions & 5 deletions src/common/sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ void buildAndSignTransactionHash() {
}

void readCborInitial(uint8_t *cdata, uint8_t dataLength) {
uint8_t remainingDataLength = dataLength;
if (remainingDataLength < 1) {
THROW(ERROR_BUFFER_OVERFLOW);
}
uint8_t header = cdata[0];
cdata += 1;
remainingDataLength -= 1;
ctx->cborLength -= 1;
// the first byte of an cbor encoding contains the type (3 high bits) and the shortCount (5
// lower bits);
Expand All @@ -48,25 +53,25 @@ void readCborInitial(uint8_t *cdata, uint8_t dataLength) {
// shortCount is the length, no extra bytes are used.
length = shortCount;
} else if (shortCount == CBOR_ONE_BYTE_LENGTH) {
if (dataLength < 1) {
if (remainingDataLength < 1) {
THROW(ERROR_BUFFER_OVERFLOW);
}
length = cdata[0];
sizeLength = 1;
} else if (shortCount == CBOR_TWO_BYTE_LENGTH) {
if (dataLength < 2) {
if (remainingDataLength < 2) {
THROW(ERROR_BUFFER_OVERFLOW);
}
length = U2BE(cdata, 0);
sizeLength = 2;
} else if (shortCount == CBOR_FOUR_BYTE_LENGTH) {
if (dataLength < 4) {
if (remainingDataLength < 4) {
THROW(ERROR_BUFFER_OVERFLOW);
}
length = U4BE(cdata, 0);
sizeLength = 4;
} else if (shortCount == CBOR_EIGHT_BYTE_LENGTH) {
if (dataLength < 8) {
if (remainingDataLength < 8) {
THROW(ERROR_BUFFER_OVERFLOW);
}
length = U8BE(cdata, 0);
Expand All @@ -77,7 +82,6 @@ void readCborInitial(uint8_t *cdata, uint8_t dataLength) {
THROW(ERROR_INVALID_PARAM);
}
cdata += sizeLength;

ctx->cborLength -= sizeLength;
switch (ctx->majorType) {
case 0:
Expand Down
6 changes: 6 additions & 0 deletions src/exportPrivateKey.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ void exportPrivateKeyBls(void) {
ctx->path[lastSubPathIndex] = lastSubPath | HARDENED_OFFSET;
getBlsPrivateKey(ctx->path, lastSubPathIndex + 1, privateKey, sizeof(privateKey));
uint8_t tx = 0;
if (sizeof(privateKey) > sizeof(G_io_apdu_buffer)) {
THROW(ERROR_BUFFER_OVERFLOW);
}
memmove(G_io_apdu_buffer, privateKey, sizeof(privateKey));
tx += sizeof(privateKey);

Expand All @@ -76,6 +79,9 @@ void exportPrivateKeyBls(void) {
}
ctx->path[lastSubPathIndex] = lastSubPath | HARDENED_OFFSET;
getBlsPrivateKey(ctx->path, lastSubPathIndex + 1, privateKey, sizeof(privateKey));
if (sizeof(privateKey) + tx > sizeof(G_io_apdu_buffer)) {
THROW(ERROR_BUFFER_OVERFLOW);
}
memmove(G_io_apdu_buffer + tx, privateKey, sizeof(privateKey));
tx += sizeof(privateKey);
}
Expand Down
7 changes: 6 additions & 1 deletion src/signConfigureBaker.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ void handleSignConfigureBaker(uint8_t *cdata,
if (!ctx_conf_baker->hasMetadataUrl) {
THROW(ERROR_INVALID_TRANSACTION);
}

if (dataLength < 2) {
THROW(ERROR_BUFFER_OVERFLOW);
}
ctx_conf_baker->url.urlLength = U2BE(cdata, 0);
if (ctx_conf_baker->url.urlLength > 2048) {
THROW(ERROR_INVALID_TRANSACTION);
Expand Down Expand Up @@ -322,6 +324,9 @@ void handleSignConfigureBaker(uint8_t *cdata,
handleCommissionRates(cdata, dataLength);
*flags |= IO_ASYNCH_REPLY;
} else if (P1_SUSPENDED == p1 && ctx_conf_baker->state == CONFIGURE_BAKER_SUSPENDED) {
if (dataLength < 1) {
THROW(ERROR_INVALID_TRANSACTION);
}
uint8_t suspended = cdata[0];
updateHash((cx_hash_t *)&tx_state->hash, cdata, 1);
dataLength -= 1;
Expand Down
5 changes: 4 additions & 1 deletion src/signCredentialDeployment.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ void processNextVerificationKey(void) {

void parseVerificationKey(uint8_t *buffer, uint8_t dataLength) {
// Hash key index
updateHash((cx_hash_t *)&tx_state->hash, buffer, 1);
if (dataLength < 1) {
THROW(ERROR_BUFFER_OVERFLOW); // Ensure safe access
}
updateHash((cx_hash_t *)&tx_state->hash, buffer, 1);
dataLength -= 1;
buffer += 1;

Expand Down Expand Up @@ -267,6 +267,9 @@ void handleSignCredentialDeployment(uint8_t *dataBuffer,
int offset = numberToText(ctx->anonymityRevocationThreshold,
sizeof(ctx->anonymityRevocationThreshold),
dataBuffer[0]);
if ((size_t)(offset + 8) > sizeof(ctx->anonymityRevocationThreshold)) {
THROW(ERROR_BUFFER_OVERFLOW);
}
memmove(ctx->anonymityRevocationThreshold + offset, " out of ", 8);
offset += 8;
updateHash((cx_hash_t *)&tx_state->hash, dataBuffer, 1);
Expand Down
Binary file modified tests/snapshots/flex/test_app_mainmenu/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/flex/test_credential_deployment_new/key0/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/flex/test_credential_deployment_new/key1/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanosp/test_app_mainmenu/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanox/test_app_mainmenu/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_app_mainmenu/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_credential_deployment_new/key0/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_credential_deployment_new/key1/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a5197db

Please sign in to comment.