env: Enhancements for establishing variable protection
cover env: Enhancements for establishing variable protection
This was factored out of [1] upon request in the hope of easing the merge.
Jan
[1] https://lore.kernel.org/u-boot/[email protected]
Jan Kiszka (2):
env: Complete generic support for writable list
env: Couple networking-related variable flags to CONFIG_NET
env/Kconfig | 1 + env/env.c | 8 ++++++++ env/flags.c | 10 +++++----- include/env_flags.h | 4 ++-- 4 files changed, 16 insertions(+), 7 deletions(-)
Signature · 1 line
2.35.3
PATCH 1/2 env: Complete generic support for writable list
From: Jan Kiszka <[email protected]>
This completes what 890feecaab72 started by selecting ENV_APPEND and loading the default env before any other sources. This ensures that load operations pick up all non-writable vars from the default env and only permitted parts from other locations according to the regular priorities.
With this change, boards only need to define the list of writable variables but no longer have to provide a custom env_get_location implementation.
--- env/Kconfig | 1 + env/env.c | 8 ++++++++ 2 files changed, 9 insertions(+)
env/Kconfig +1 -0
@@ -733,6 +733,7 @@ config ENV_APPEND config ENV_WRITEABLE_LIST bool "Permit write access only to listed variables" + select ENV_APPEND help If defined, only environment variables which explicitly set the 'w' writeable flag can be written and modified at runtime. No variables
env/env.c +8 -0
@@ -195,6 +195,14 @@ int env_load(void)int best_prio =-1 ;int prio; +if (CONFIG_IS_ENABLED (ENV_WRITEABLE_LIST )) { +/* +* When using a list of writeable variables, the baseline comes +* from the built-in default env. So load this first. +*/ +env_set_default (NULL ,0 ); + } +for (prio =0 ; (drv =env_driver_lookup (ENVOP_LOAD , prio)); prio++) {int ret;
Signature · 1 line
2.35.3
Re: [PATCH 1/2] env: Complete generic support for writable list
Hi Jan,
Quoted 55 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
This completes what
890feecaab72started by selectingENV_APPENDand loading the default env before any other sources. This ensures that load operations pick up all non-writable vars from the default env and only permitted parts from other locations according to the regular priorities.With this change, boards only need to define the list of writable variables but no longer have to provide a custom
env_get_locationimplementation.CC Joe Hershberger <[email protected]>CC Marek Vasut <[email protected]>CC Stefan Herbrechtsmeier <[email protected]>Signed-off-by Jan Kiszka <[email protected]>Reviewed-by Marek Vasut <[email protected]>--- env/Kconfig | 1 + env/env.c | 8 ++++++++ 2 files changed, 9 insertions(+)env/Kconfig +1
-0@@ -733,6 +733,7 @@ config ENV_APPEND config ENV_WRITEABLE_LIST bool "Permit write access only to listed variables" + select ENV_APPEND help If defined, only environment variables which explicitly set the 'w' writeable flag can be written and modified at runtime. No variablesenv/env.c +8
-1@@ -195,6 +195,14 @@ int env_load(void)int best_prio =-1 ;int prio; +if (CONFIG_IS_ENABLED (ENV_WRITEABLE_LIST )) { +/* +* When using a list of writeable variables, the baseline comes +* from the built-in default env. So load this first. +*/ +env_set_default (NULL ,0 ); + } +for (prio =0 ; (drv =env_driver_lookup (ENVOP_LOAD , prio)); prio++) {int ret; --
Quoted 2 lines
2.35.3
This looks OK, but please can you write some tests in test/env ?
Regards,
SImon
Re: [PATCH 1/2] env: Complete generic support for writable list
Quoted 57 lines · Simon Glass
Hi Jan,
Quoted 54 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
This completes what
890feecaab72started by selectingENV_APPENDand loading the default env before any other sources. This ensures that load operations pick up all non-writable vars from the default env and only permitted parts from other locations according to the regular priorities.With this change, boards only need to define the list of writable variables but no longer have to provide a custom
env_get_locationimplementation.CC Joe Hershberger <[email protected]>CC Marek Vasut <[email protected]>CC Stefan Herbrechtsmeier <[email protected]>Signed-off-by Jan Kiszka <[email protected]>Reviewed-by Marek Vasut <[email protected]>--- env/Kconfig | 1 + env/env.c | 8 ++++++++ 2 files changed, 9 insertions(+)env/Kconfig +1
-0@@ -733,6 +733,7 @@ config ENV_APPEND config ENV_WRITEABLE_LIST bool "Permit write access only to listed variables" + select ENV_APPEND help If defined, only environment variables which explicitly set the 'w' writeable flag can be written and modified at runtime. No variablesenv/env.c +8
-0@@ -195,6 +195,14 @@ int env_load(void)int best_prio =-1 ;int prio; +if (CONFIG_IS_ENABLED (ENV_WRITEABLE_LIST )) { +/* +* When using a list of writeable variables, the baseline comes +* from the built-in default env. So load this first. +*/ +env_set_default (NULL ,0 ); + } +for (prio =0 ; (drv =env_driver_lookup (ENVOP_LOAD , prio)); prio++) {int ret;
Quoted 5 lines
Quoted 3 lines
--
2.35.3This looks OK, but please can you write some tests in test/env ?
Looking at those, it seems there is nothing at all regarding access flags yet. Any suggestions how to first of all build up that infrastructure are welcome. Then I could add this aspect here on top.
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
Re: [PATCH 1/2] env: Complete generic support for writable list
()Hi Jan,
Quoted 65 lines · Jan Kiszka
Quoted 57 lines · Simon Glass
Hi Jan,
Quoted 54 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
This completes what
890feecaab72started by selectingENV_APPENDand loading the default env before any other sources. This ensures that load operations pick up all non-writable vars from the default env and only permitted parts from other locations according to the regular priorities.With this change, boards only need to define the list of writable variables but no longer have to provide a custom
env_get_locationimplementation.CC Joe Hershberger <[email protected]>CC Marek Vasut <[email protected]>CC Stefan Herbrechtsmeier <[email protected]>Signed-off-by Jan Kiszka <[email protected]>Reviewed-by Marek Vasut <[email protected]>--- env/Kconfig | 1 + env/env.c | 8 ++++++++ 2 files changed, 9 insertions(+)env/Kconfig +1
-0@@ -733,6 +733,7 @@ config ENV_APPEND config ENV_WRITEABLE_LIST bool "Permit write access only to listed variables" + select ENV_APPEND help If defined, only environment variables which explicitly set the 'w' writeable flag can be written and modified at runtime. No variablesenv/env.c +8
-0@@ -195,6 +195,14 @@ int env_load(void)int best_prio =-1 ;int prio; +if (CONFIG_IS_ENABLED (ENV_WRITEABLE_LIST )) { +/* +* When using a list of writeable variables, the baseline comes +* from the built-in default env. So load this first. +*/ +env_set_default (NULL ,0 ); + } +for (prio =0 ; (drv =env_driver_lookup (ENVOP_LOAD , prio)); prio++) {int ret;Quoted 5 lines
Quoted 3 lines
--
2.35.3This looks OK, but please can you write some tests in test/env ?
Quoted 3 lines
Looking at those, it seems there is nothing at all regarding access flags yet. Any suggestions how to first of all build up that infrastructure are welcome. Then I could add this aspect here on top.
Yes, starting something a bit new is always harder. My approach is normally to just start small. Anything is better than nothing, and it provides something for others to build on.
There are a few tests for hashtable which could be a way to start this.
I suggest starting a new env.c file in there with a few env_get() and env_set() calls. You could also use himport_r() to test out different flags.
I'm not sure how easy it would be to call env_load() in a test, but it might work.
The trickier thing (perhaps to worry about later) is that you are (correctly) using a CONFIG option to enable the feature. For sandbox tests we typically want all features to be enabled at build time (e.g. default y if SANDBOX), then select them at runtime, so we can test them. See test_eth_enabled() for an example of how this is done.
Regards,
Simon
Re: [PATCH 1/2] env: Complete generic support for writable list
In reply to Jan KiszkaQuoted 12 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
This completes what
890feecaab72started by selectingENV_APPENDand loading the default env before any other sources. This ensures that load operations pick up all non-writable vars from the default env and only permitted parts from other locations according to the regular priorities.With this change, boards only need to define the list of writable variables but no longer have to provide a custom
env_get_locationimplementation.
Quoted 5 lines
CC Joe Hershberger <[email protected]>CC Marek Vasut <[email protected]>CC Stefan Herbrechtsmeier <[email protected]>Signed-off-by Jan Kiszka <[email protected]>Reviewed-by Marek Vasut <[email protected]>
Applied to u-boot/master, thanks!
Signature · 1 line
Tom
PATCH 2/2 env: Couple networking-related variable flags to CONFIG_NET
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
Boards may set networking variables programmatically, thus may have CONFIG_NET on but CONFIG_CMD_NET off. The IOT2050 is an example.
--- env/flags.c | 10 +++++----- include/env_flags.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-)
env/flags.c +5 -5
@@ -22,7 +22,7 @@#include <env_internal.h> #endif -#ifdef CONFIG_CMD_NET +#ifdef CONFIG_NET #define ENV_FLAGS_NET_VARTYPE_REPS "im"#else #define ENV_FLAGS_NET_VARTYPE_REPS ""
@@ -57,7 +57,7 @@ static const char * const env_flags_vartype_names[] = {"decimal" ,"hexadecimal" ,"boolean" , -#ifdef CONFIG_CMD_NET +#ifdef CONFIG_NET"IP address" , "MAC address", #endif
@@ -211,7 +211,7 @@ static void skip_num(int hex, const char *value, const char **end, *end = value; } -#ifdef CONFIG_CMD_NET +#ifdef CONFIG_NET int eth_validate_ethaddr_str (const char *addr) {const char *end;
@@ -244,7 +244,7 @@ static int _env_flags_validate_type(const char *value, enum env_flags_vartype type) {const char *end; -#ifdef CONFIG_CMD_NET +#ifdef CONFIG_NET const char *cur;int i;#endif
@@ -273,7 +273,7 @@ static int _env_flags_validate_type(const char *value,if (value[1 ] !='\0' )return -1 ;break ; -#ifdef CONFIG_CMD_NET +#ifdef CONFIG_NET case env_flags_vartype_ipaddr: cur = value;for (i =0 ; i <4 ; i++) {
include/env_flags.h +2 -2
@@ -12,7 +12,7 @@ enum env_flags_vartype { env_flags_vartype_decimal, env_flags_vartype_hex, env_flags_vartype_bool, -#ifdef CONFIG_CMD_NET +#ifdef CONFIG_NET env_flags_vartype_ipaddr, env_flags_vartype_macaddr, #endif
@@ -121,7 +121,7 @@ enum env_flags_varaccess env_flags_parse_varaccess(const char *flags);*/ enum env_flags_varaccess env_flags_parse_varaccess_from_binflags (int binflags); -#ifdef CONFIG_CMD_NET +#ifdef CONFIG_NET /* * Check if a string has the format of an Ethernet MAC address */
Signature · 1 line
2.35.3
Re: [PATCH 2/2] env: Couple networking-related variable flags to CONFIG_NET
Quoted 7 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
Boards may set networking variables programmatically, thus may have
CONFIG_NETon butCONFIG_CMD_NEToff. The IOT2050 is an example.CC Joe Hershberger <[email protected]>Signed-off-by Jan Kiszka <[email protected]>
Signature · 1 line
Tom
Re: [PATCH 2/2] env: Couple networking-related variable flags to CONFIG_NET
In reply to Jan KiszkaQuoted 8 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
Boards may set networking variables programmatically, thus may have
CONFIG_NETon butCONFIG_CMD_NEToff. The IOT2050 is an example.CC Joe Hershberger <[email protected]>Signed-off-by Jan Kiszka <[email protected]>Reviewed-by Tom Rini <[email protected]>
Applied to u-boot/master, thanks!
Signature · 1 line
Tom