diff options
author | Pierre-Clément Tosi <ptosi@google.com> | 2021-08-12 15:28:31 +0000 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-09-23 08:55:06 -0400 |
commit | f6bc5d17afa9fe12418edaf1fc9f82beeda06132 (patch) | |
tree | fc6f2322920f6271331dea3f7b3292ba5f96ce65 /env | |
parent | 7b57e56739ed2c550d17a072a7f4c8326c0c83dc (diff) | |
download | u-boot-f6bc5d17afa9fe12418edaf1fc9f82beeda06132.tar.gz u-boot-f6bc5d17afa9fe12418edaf1fc9f82beeda06132.tar.bz2 u-boot-f6bc5d17afa9fe12418edaf1fc9f82beeda06132.zip |
env: Make _init() expect _INVALID when _IS_NOWHERE
Avoid applying the "fix" introduced by commit 5557eec01cbf ("env: Fix
invalid env handling in env_init()") to the environment "nowhere".
This is necessary as that commit, by setting the return value of
env_init() to -ENOENT if gd->env_valid is ENV_INVALID, forces that
function to reset gd->env_valid to ENV_VALID. By doing so, it breaks the
assumption (required by ENV_IS_NOWHERE) that gd->env_valid must be
ENV_INVALID.
This, in turn, results in env_relocate() calling env_load() (it should
not), which itself, calls U_BOOT_ENV_LOCATION(nowhere).load() i.e.
env_nowhere_load(). That function, being implemented under the
assumption mentioned above, calls env_set_default(), which in turn,
seeing that gd->env_valid is ENV_VALID (it should not), tries to
dereference whatever lies in gd->env_addr (most likely garbage), leading
to a faulty memory access.
Note that other env_locations might be concerned by this bug but that
this commit only intends to fix it for when ENV_IS_NOWHERE.
Fixes: 5557eec01cbf ("env: Fix invalid env handling in env_init()")
Signed-off-by: Pierre-Clément Tosi <ptosi@google.com>
Diffstat (limited to 'env')
-rw-r--r-- | env/env.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -336,7 +336,7 @@ int env_init(void) debug("%s: Environment %s init done (ret=%d)\n", __func__, drv->name, ret); - if (gd->env_valid == ENV_INVALID) + if (gd->env_valid == ENV_INVALID && drv->location != ENVL_NOWHERE) ret = -ENOENT; } |