fix(core): wake up device on USB HID and VCP communication too
What changed, and why it matters
This commit fixes a power-management bug in Trezor hardware wallets. Previously, USB HID (button/keyboard-like) and VCP (serial port-like) traffic did not wake the device from suspend/sleep. The patch makes any incoming USB data on these interfaces trigger a wakeup, so the device responds promptly instead of staying asleep.
Treat as a low-to-moderate reliability/security fix. Review whether the missing wakeup could have allowed a suspended device to ignore or delay security-critical USB commands (e.g., transaction approval prompts, PIN entry). Verify that wakeup_flags_set is safe to call from interrupt context and that no race exists with suspend entry. No immediate emergency action is indicated by the diff alone.
Security signals we found
Power-management / suspend wakeup inconsistency
USB HID/VCP input path previously failed to set WAKEUP_FLAG_USB
Fix only active when USE_SUSPEND is defined; no change otherwise
No changelog entry provided
Evidence from the diff
The change adds calls to wakeup_flags_set(WAKEUP_FLAG_USB) inside the USB HID and VCP class data-out callbacks (usb_hid_class_data_out and usb_vcp_class_data_out) when USE_SUSPEND is enabled. This aligns HID/VCP behavior with other USB wakeup paths so that incoming USB packets wake the device from suspend. It is a 15-line, two-file addition guarded by the USE_SUSPEND preprocessor flag.
Changed components
core/embed/io/usb/stm32/usb_class_hid.ccore/embed/io/usb/stm32/usb_class_vcp.cTrezor Core USB HID/VCP driversDevice suspend/resume subsystem (USE_SUSPEND builds)Inspect captured patch +15 / −0
diff --git a/core/embed/io/usb/stm32/usb_class_hid.c b/core/embed/io/usb/stm32/usb_class_hid.c
index ac13879af..c9c026f28 100644
--- a/core/embed/io/usb/stm32/usb_class_hid.c
+++ b/core/embed/io/usb/stm32/usb_class_hid.c
@@ -25,6 +25,10 @@
#include <sec/random_delays.h>
#include <sys/sysevent_source.h>
+#ifdef USE_SUSPEND
+#include <sys/suspend.h>
+#endif
+
#include "usb_internal.h"
#define USB_CLASS_HID 0x03
@@ -334,6 +338,9 @@ static uint8_t usb_hid_class_data_out(USBD_HandleTypeDef *dev, uint8_t ep_num) {
// Save the report length to indicate we have read something, but don't
// schedule next reading until user reads this one
state->last_read_len = USBD_LL_GetRxDataSize(dev, ep_num);
+#ifdef USE_SUSPEND
+ wakeup_flags_set(WAKEUP_FLAG_USB);
+#endif
}
return USBD_OK;
diff --git a/core/embed/io/usb/stm32/usb_class_vcp.c b/core/embed/io/usb/stm32/usb_class_vcp.c
index f2b102bbc..0bcfab1c5 100644
--- a/core/embed/io/usb/stm32/usb_class_vcp.c
+++ b/core/embed/io/usb/stm32/usb_class_vcp.c
@@ -24,6 +24,10 @@
#include <io/usb_vcp.h>
#include <sys/sysevent_source.h>
+#ifdef USE_SUSPEND
+#include <sys/suspend.h>
+#endif
+
#include "usb_internal.h"
// Communications Device Class Code (bFunctionClass, bInterfaceClass)
@@ -493,6 +497,10 @@ static uint8_t usb_vcp_class_data_out(USBD_HandleTypeDef *dev, uint8_t ep_num) {
// Prepare the OUT EP to receive next packet
USBD_LL_PrepareReceive(dev, state->ep_out, state->rx_packet,
state->max_packet_len);
+
+#ifdef USE_SUSPEND
+ wakeup_flags_set(WAKEUP_FLAG_USB);
+#endif
}
return USBD_OK;
Why this scored 35/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.