From 4c60f80f4438eadbb9d82bcd2d308d23e193e81c Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Thu, 17 Feb 2022 10:44:40 +0100 Subject: [PATCH] feat(legacy): Add state sanity check to fsm_msg*Ack() functions. --- legacy/firmware/fsm.c | 6 ++++++ legacy/firmware/fsm_msg_coin.h | 2 ++ legacy/firmware/fsm_msg_common.h | 6 +++++- legacy/firmware/fsm_msg_ethereum.h | 2 ++ legacy/firmware/fsm_msg_stellar.h | 26 ++++++++++++++++++++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/legacy/firmware/fsm.c b/legacy/firmware/fsm.c index c919084337..6ed250815b 100644 --- a/legacy/firmware/fsm.c +++ b/legacy/firmware/fsm.c @@ -100,6 +100,12 @@ static uint8_t msg_resp[MSG_OUT_DECODED_SIZE] __attribute__((aligned)); return; \ } +#define CHECK_UNLOCKED \ + if (!session_isUnlocked()) { \ + layoutHome(); \ + return; \ + } + #define CHECK_PARAM(cond, errormsg) \ if (!(cond)) { \ fsm_sendFailure(FailureType_Failure_DataError, (errormsg)); \ diff --git a/legacy/firmware/fsm_msg_coin.h b/legacy/firmware/fsm_msg_coin.h index 36c5901a76..529b657b22 100644 --- a/legacy/firmware/fsm_msg_coin.h +++ b/legacy/firmware/fsm_msg_coin.h @@ -146,6 +146,8 @@ void fsm_msgSignTx(const SignTx *msg) { } void fsm_msgTxAck(TxAck *msg) { + CHECK_UNLOCKED + CHECK_PARAM(msg->has_tx, _("No transaction provided")); signing_txack(&(msg->tx)); diff --git a/legacy/firmware/fsm_msg_common.h b/legacy/firmware/fsm_msg_common.h index 594ae34db1..8b396d1c8b 100644 --- a/legacy/firmware/fsm_msg_common.h +++ b/legacy/firmware/fsm_msg_common.h @@ -516,7 +516,11 @@ void fsm_msgRecoveryDevice(const RecoveryDevice *msg) { msg->has_u2f_counter ? msg->u2f_counter : 0, dry_run); } -void fsm_msgWordAck(const WordAck *msg) { recovery_word(msg->word); } +void fsm_msgWordAck(const WordAck *msg) { + CHECK_UNLOCKED + + recovery_word(msg->word); +} void fsm_msgSetU2FCounter(const SetU2FCounter *msg) { layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL, diff --git a/legacy/firmware/fsm_msg_ethereum.h b/legacy/firmware/fsm_msg_ethereum.h index 3834335342..a03b66294f 100644 --- a/legacy/firmware/fsm_msg_ethereum.h +++ b/legacy/firmware/fsm_msg_ethereum.h @@ -125,6 +125,8 @@ void fsm_msgEthereumSignTxEIP1559(const EthereumSignTxEIP1559 *msg) { } void fsm_msgEthereumTxAck(const EthereumTxAck *msg) { + CHECK_UNLOCKED + ethereum_signing_txack(msg); } diff --git a/legacy/firmware/fsm_msg_stellar.h b/legacy/firmware/fsm_msg_stellar.h index 44d920d872..b2ab413e61 100644 --- a/legacy/firmware/fsm_msg_stellar.h +++ b/legacy/firmware/fsm_msg_stellar.h @@ -97,6 +97,8 @@ void fsm_msgStellarSignTx(const StellarSignTx *msg) { } void fsm_msgStellarCreateAccountOp(const StellarCreateAccountOp *msg) { + CHECK_UNLOCKED + if (!stellar_confirmCreateAccountOp(msg)) return; if (stellar_allOperationsConfirmed()) { @@ -115,6 +117,8 @@ void fsm_msgStellarCreateAccountOp(const StellarCreateAccountOp *msg) { } void fsm_msgStellarPaymentOp(const StellarPaymentOp *msg) { + CHECK_UNLOCKED + // This will display additional dialogs to the user if (!stellar_confirmPaymentOp(msg)) return; @@ -136,6 +140,8 @@ void fsm_msgStellarPaymentOp(const StellarPaymentOp *msg) { void fsm_msgStellarPathPaymentStrictReceiveOp( const StellarPathPaymentStrictReceiveOp *msg) { + CHECK_UNLOCKED + if (!stellar_confirmPathPaymentStrictReceiveOp(msg)) return; if (stellar_allOperationsConfirmed()) { @@ -155,6 +161,8 @@ void fsm_msgStellarPathPaymentStrictReceiveOp( void fsm_msgStellarPathPaymentStrictSendOp( const StellarPathPaymentStrictSendOp *msg) { + CHECK_UNLOCKED + if (!stellar_confirmPathPaymentStrictSendOp(msg)) return; if (stellar_allOperationsConfirmed()) { @@ -173,6 +181,8 @@ void fsm_msgStellarPathPaymentStrictSendOp( } void fsm_msgStellarManageBuyOfferOp(const StellarManageBuyOfferOp *msg) { + CHECK_UNLOCKED + if (!stellar_confirmManageBuyOfferOp(msg)) return; if (stellar_allOperationsConfirmed()) { @@ -191,6 +201,8 @@ void fsm_msgStellarManageBuyOfferOp(const StellarManageBuyOfferOp *msg) { } void fsm_msgStellarManageSellOfferOp(const StellarManageSellOfferOp *msg) { + CHECK_UNLOCKED + if (!stellar_confirmManageSellOfferOp(msg)) return; if (stellar_allOperationsConfirmed()) { @@ -210,6 +222,8 @@ void fsm_msgStellarManageSellOfferOp(const StellarManageSellOfferOp *msg) { void fsm_msgStellarCreatePassiveSellOfferOp( const StellarCreatePassiveSellOfferOp *msg) { + CHECK_UNLOCKED + if (!stellar_confirmCreatePassiveSellOfferOp(msg)) return; if (stellar_allOperationsConfirmed()) { @@ -228,6 +242,8 @@ void fsm_msgStellarCreatePassiveSellOfferOp( } void fsm_msgStellarSetOptionsOp(const StellarSetOptionsOp *msg) { + CHECK_UNLOCKED + if (!stellar_confirmSetOptionsOp(msg)) return; if (stellar_allOperationsConfirmed()) { @@ -246,6 +262,8 @@ void fsm_msgStellarSetOptionsOp(const StellarSetOptionsOp *msg) { } void fsm_msgStellarChangeTrustOp(const StellarChangeTrustOp *msg) { + CHECK_UNLOCKED + if (!stellar_confirmChangeTrustOp(msg)) return; if (stellar_allOperationsConfirmed()) { @@ -264,6 +282,8 @@ void fsm_msgStellarChangeTrustOp(const StellarChangeTrustOp *msg) { } void fsm_msgStellarAllowTrustOp(const StellarAllowTrustOp *msg) { + CHECK_UNLOCKED + if (!stellar_confirmAllowTrustOp(msg)) return; if (stellar_allOperationsConfirmed()) { @@ -282,6 +302,8 @@ void fsm_msgStellarAllowTrustOp(const StellarAllowTrustOp *msg) { } void fsm_msgStellarAccountMergeOp(const StellarAccountMergeOp *msg) { + CHECK_UNLOCKED + if (!stellar_confirmAccountMergeOp(msg)) return; if (stellar_allOperationsConfirmed()) { @@ -300,6 +322,8 @@ void fsm_msgStellarAccountMergeOp(const StellarAccountMergeOp *msg) { } void fsm_msgStellarManageDataOp(const StellarManageDataOp *msg) { + CHECK_UNLOCKED + if (!stellar_confirmManageDataOp(msg)) return; if (stellar_allOperationsConfirmed()) { @@ -318,6 +342,8 @@ void fsm_msgStellarManageDataOp(const StellarManageDataOp *msg) { } void fsm_msgStellarBumpSequenceOp(const StellarBumpSequenceOp *msg) { + CHECK_UNLOCKED + if (!stellar_confirmBumpSequenceOp(msg)) return; if (stellar_allOperationsConfirmed()) {