fix(core): relocate const globals to .rodata
What changed, and why it matters
This commit marks several fixed data objects as read-only constants so the compiler can place them in flash memory (.rodata) instead of writable RAM. This is a hardening change: it prevents accidental or malicious code from modifying values like the device model name, USB product strings, firmware revision, and the base32 alphabet. There is no direct evidence in the commit that an actual exploit exists; it is a defensive memory-layout fix.
Treat as a low-risk hardening improvement. No urgent action required, but ensure the build linker script actually maps const globals to read-only memory and that downstream firmware builds pick up this change. Review whether other similar global constants in the codebase should receive the same treatment.
Security signals we found
Adds const qualifier to global data objects to enable placement in read-only memory (.rodata)
Protects device identity/revision strings and version tuple from runtime modification
Protects base32 encoding alphabet from runtime modification
No changelog entry provided, suggesting minor/internal hardening rather than a disclosed vulnerability fix
Evidence from the diff
The patch adds const qualifiers to global objects in modtrezorutils.c (MicroPython string/tuple objects exposing SCM_REVISION, MODEL_NAME, MODEL_FULL_NAME, MODEL_USB_MANUFACTURER, MODEL_USB_PRODUCT, and version tuple) and makes BASE32_ALPHABET_RFC4648 a const char *const in crypto/base32.c/base32.h. The intent is to allow the linker to place these globals in .rodata rather than .data/RAM, enforcing immutability at runtime and reducing writable attack surface.
Changed components
core/embed/upymod/modtrezorutils/modtrezorutils.ccrypto/base32.ccrypto/base32.hInspect captured patch +9 / −8
diff --git a/core/embed/upymod/modtrezorutils/modtrezorutils.c b/core/embed/upymod/modtrezorutils/modtrezorutils.c
index f9caa5df..59fe844a 100644
--- a/core/embed/upymod/modtrezorutils/modtrezorutils.c
+++ b/core/embed/upymod/modtrezorutils/modtrezorutils.c
@@ -655,31 +655,31 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_nrf_get_version_obj,
mod_trezorutils_nrf_get_version);
#endif
-STATIC mp_obj_str_t mod_trezorutils_revision_obj = {
+STATIC const mp_obj_str_t mod_trezorutils_revision_obj = {
{&mp_type_bytes}, 0, sizeof(SCM_REVISION), (const byte *)SCM_REVISION};
-STATIC mp_obj_str_t mod_trezorutils_model_name_obj = {
+STATIC const mp_obj_str_t mod_trezorutils_model_name_obj = {
{&mp_type_str}, 0, sizeof(MODEL_NAME) - 1, (const byte *)MODEL_NAME};
-STATIC mp_obj_str_t mod_trezorutils_full_name_obj = {
+STATIC const mp_obj_str_t mod_trezorutils_full_name_obj = {
{&mp_type_str},
0,
sizeof(MODEL_FULL_NAME) - 1,
(const byte *)MODEL_FULL_NAME};
-STATIC mp_obj_str_t mod_trezorutils_model_usb_manufacturer_obj = {
+STATIC const mp_obj_str_t mod_trezorutils_model_usb_manufacturer_obj = {
{&mp_type_str},
0,
sizeof(MODEL_USB_MANUFACTURER) - 1,
(const byte *)MODEL_USB_MANUFACTURER};
-STATIC mp_obj_str_t mod_trezorutils_model_usb_product_obj = {
+STATIC const mp_obj_str_t mod_trezorutils_model_usb_product_obj = {
{&mp_type_str},
0,
sizeof(MODEL_USB_PRODUCT) - 1,
(const byte *)MODEL_USB_PRODUCT};
-STATIC mp_obj_tuple_t mod_trezorutils_version_obj = {
+STATIC const mp_obj_tuple_t mod_trezorutils_version_obj = {
{&mp_type_tuple},
4,
{MP_OBJ_NEW_SMALL_INT(VERSION_MAJOR), MP_OBJ_NEW_SMALL_INT(VERSION_MINOR),
diff --git a/crypto/base32.c b/crypto/base32.c
index ef9b76be..bef40b1b 100644
--- a/crypto/base32.c
+++ b/crypto/base32.c
@@ -24,7 +24,8 @@
#include <string.h>
-const char *BASE32_ALPHABET_RFC4648 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ23456789";
+const char *const BASE32_ALPHABET_RFC4648 =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ23456789";
static inline void base32_5to8(const uint8_t *in, uint8_t length, uint8_t *out);
static inline bool base32_8to5(const uint8_t *in, uint8_t length, uint8_t *out,
diff --git a/crypto/base32.h b/crypto/base32.h
index 8b5cc851..2fc2518f 100644
--- a/crypto/base32.h
+++ b/crypto/base32.h
@@ -27,7 +27,7 @@
#include <stddef.h>
#include <stdint.h>
-extern const char *BASE32_ALPHABET_RFC4648;
+extern const char *const BASE32_ALPHABET_RFC4648;
char *base32_encode(const uint8_t *in, size_t inlen, char *out, size_t outlen,
const char *alphabet);
Why this scored 15/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.