env: Add support for explicit write access list
PATCH 1/1 env: Add support for explicit write access list
This option marks any U-Boot variable which does not have explicit 'w' writeable flag set as read-only. This way the environment can be locked down and only variables explicitly configured to be writeable can ever be changed by either 'env import', 'env set' or loading user environment from environment storage.
Signed-off-by Marek Vasut <[email protected]>
--- env/Kconfig | 8 ++++ env/flags.c | 92 +++++++++++++++++++++++++++++++++++++++------ include/env_flags.h | 6 ++- lib/hashtable.c | 5 ++- 4 files changed, 98 insertions(+), 13 deletions(-)
env/Kconfig +8 -0
@@ -613,6 +613,14 @@ config ENV_APPEND with newly imported data. This may be used in combination with static flags to e.g. to protect variables which must not be modified. +config ENV_WRITEABLE_LIST + bool "Permit write access only to listed variables" + default n + help + If defined, only environment variables which explicitly set the 'w' + writeable flag can be written and modified at runtime. No variables + can be otherwise created, written or imported into the environment. + config ENV_ACCESS_IGNORE_FORCE bool "Block forced environment operations" default n
env/flags.c +81 -11
173 lines not on this page · raw message
include/env_flags.h +5 -1
@@ -24,6 +24,9 @@ enum env_flags_varaccess { env_flags_varaccess_readonly, env_flags_varaccess_writeonce, env_flags_varaccess_changedefault, +#if CONFIG_IS_ENABLED(ENV_WRITEABLE_LIST) + env_flags_varaccess_writeable, +#endif env_flags_varaccess_end };
@@ -173,6 +176,7 @@ int env_flags_validate(const struct env_entry *item, const char *newval,#define ENV_FLAGS_VARACCESS_PREVENT_CREATE 0x00000010#define ENV_FLAGS_VARACCESS_PREVENT_OVERWR 0x00000020#define ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR 0x00000040 -#define ENV_FLAGS_VARACCESS_BIN_MASK 0x00000078 +#define ENV_FLAGS_VARACCESS_WRITEABLE 0x00000080 +#define ENV_FLAGS_VARACCESS_BIN_MASK 0x000000f8#endif /* __ENV_FLAGS_H__ */
lib/hashtable.c +4 -1
@@ -946,9 +946,12 @@ int himport_r(struct hsearch_data *htab, e.data = value;hsearch_r (e,ENV_ENTER , &rv, htab, flag); -if (rv ==NULL ) +#if !CONFIG_IS_ENABLED (ENV_WRITEABLE_LIST ) +if (rv ==NULL ) {printf ("himport_r: can't insert \"%s=%s\" into hash table\n" , name, value); + } +#endif debug("INSERT: table %p, filled %d/%d rv %p ==> name=\"%s\" value=\"%s\"\n", htab, htab->filled, htab->size,
Signature · 1 line
2.25.1