fix(core): lower maximum auto-lock delay to 149 hours
What changed, and why it matters
This update fixes a bug in Trezor hardware wallets where setting the screen auto-lock delay to its maximum value caused the device to crash every time it restarted. The old maximum was chosen so that it hit a limit inside the device's timekeeping code, triggering an overflow error. The fix lowers the maximum allowed auto-lock delay to 149 hours and adds a safety check so the device cannot accept a value that would cause the crash. A device already stuck with the old maximum will recover after updating because the firmware clamps the stored value down to a safe range.
Apply the firmware update. Users who previously set the auto-lock delay to the old maximum should update; the device will recover automatically. No further user action is required.
Security signals we found
Denial-of-service via configuration: setting a legitimate setting to its maximum value caused a persistent boot crash
Integer/overflow boundary issue in MicroPython ticks_add()
Missing input validation on user-configurable auto-lock delay
Recovery path exists after update because stored value is clamped at read time
Evidence from the diff
The commit lowers the BTC/BTC-like auto-lock delay maximum from 0x2000_0000 ms (~6 days) to 149 hours. The old maximum equals half the MicroPython tick period on 32-bit MCUs, which is the smallest delta rejected by utime.ticks_add() with OverflowError. The crash occurred in IdleTimer.touch() when the scheduler called ticks_add() with the stored delay. The patch exposes a new utime.MAX_DELTA_MS constant from modutime.c, uses it to bound AUTOLOCK_DELAY_USB_MAX_MS in storage/device.py, and adds a runtime ensure() check. Existing stored values are clamped by get_autolaut_delay_ms(), so recovery does not require rewriting storage.
Changed components
Trezor Core firmwarecore/embed/upymod/modutime.ccore/src/storage/device.pyIdleTimer schedulerBTC/BTC-like auto-lock delay settingInspect captured patch +28 / −13
### core/.changelog.d/8304.changed
@@ -0,0 +1 @@
+Lowered the maximum auto-lock delay to 149 hours.
### core/.changelog.d/8304.fixed
@@ -0,0 +1 @@
+Fixed a crash on every boot after setting the auto-lock delay to its maximum value.
### core/embed/upymod/modutime.c
@@ -25,6 +25,7 @@
*/
#include "extmod/modtime.h"
+#include "py/smallint.h"
#include "shared/timeutils/timeutils.h"
// 32-bit signed integer will overflow at 2038.
@@ -35,6 +36,10 @@ _Static_assert(
sizeof(mp_timestamp_t) == sizeof(timeutils_timestamp_t),
"mp_timestamp_t and timeutils_timestamp_t have different widths");
+// The largest value of the `delta` argument that does not make `ticks_add()`
+// raise `OverflowError`
+#define UTIME_MAX_DELTA_MS (MICROPY_PY_TIME_TICKS_PERIOD / 2 - 1)
+
// copy of ports/stm32/modutime.c:time_localtime, without support
// for getting current clock time (i.e., timestamp must always be provided)
static mp_obj_t time_gmtime1970(mp_obj_t timestamp) {
@@ -68,6 +73,8 @@ static const mp_rom_map_elem_t time_module_globals_table[] = {
{MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_time_ticks_cpu_obj)},
{MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_time_ticks_add_obj)},
{MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_time_ticks_diff_obj)},
+
+ {MP_ROM_QSTR(MP_QSTR_MAX_DELTA_MS), MP_ROM_INT(UTIME_MAX_DELTA_MS)},
};
static MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table);
### core/mocks/utime.pyi
@@ -1,3 +1,5 @@
+MAX_DELTA_MS: int
+
def sleep(s: int) -> None: ...
def sleep_ms(ms: int) -> None: ...
def sleep_us(us: int) -> None: ...
### core/src/main.py
@@ -14,7 +14,8 @@
utils.presize_module(trezor, 30)
# storage imports storage.common, storage.cache and storage.device.
-# These import trezor, trezor.config (which is a C module), trezor.utils, and each other.
+# These import trezor, trezor.config and utime (which are C modules),
+# trezor.utils, and each other.
import storage
# we will need space for XX items in the storage module
utils.presize_module(storage, 20)
### core/src/storage/device.py
@@ -1,3 +1,4 @@
+import utime
from micropython import const
from typing import TYPE_CHECKING
@@ -71,8 +72,10 @@
AUTOLOCK_DELAY_USB_MIN_MS = 60 * 1000 # 1 minute
AUTOLOCK_DELAY_USB_DEFAULT_MS = const(10 * 60 * 1000) # 10 minutes
-# autolock intervals larger than AUTOLOCK_DELAY_MAXIMUM cause issues in the scheduler
-AUTOLOCK_DELAY_USB_MAX_MS = const(0x2000_0000) # ~6 days
+AUTOLOCK_DELAY_USB_MAX_MS = const(149 * 60 * 60 * 1000) # 149 hours
+# Delays over `utime.MAX_DELTA_MS` make the scheduler raise `OverflowError`
+# in `IdleTimer.touch()`
+utils.ensure(AUTOLOCK_DELAY_USB_MAX_MS <= utime.MAX_DELTA_MS)
if utils.USE_POWER_MANAGER:
AUTODIM_DELAY_MS = 30 * 1000 # 30 seconds
### tests/device_tests/test_autolock.py
@@ -68,19 +68,19 @@ def test_apply_auto_lock_delay(session: Session):
@pytest.mark.parametrize(
- "seconds",
+ "milliseconds",
[
- 10, # 10 seconds, minimum
- 60, # 1 minute
- 123, # 2 minutes
- 3601, # 1 hour
- 7227, # 2 hours
- 536870, # 149 hours, maximum
+ 10 * 1000, # 10 seconds, minimum
+ 60 * 1000, # 1 minute
+ 123 * 1000, # 2 minutes
+ 3601 * 1000, # 1 hour
+ 7227 * 1000, # 2 hours
+ 149 * 60 * 60 * 1000, # 149 hours, maximum
],
)
-def test_apply_auto_lock_delay_valid(session: Session, seconds):
- set_autolock_delay(session, seconds * 1000)
- assert session.features.auto_lock_delay_ms == seconds * 1000
+def test_apply_auto_lock_delay_valid(session: Session, milliseconds):
+ set_autolock_delay(session, milliseconds)
+ assert session.features.auto_lock_delay_ms == milliseconds
def test_autolock_default_value(session: Session):Why this scored 41/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.