Fix zapping of static hints and env in init_static_kenv(). Environments
are terminated by 2 NULs, but only 1 NUL was zapped. Zapping only 1 NUL just splits the first string into an empty string and a corrupted string. All other strings in static hints and env remained live early in the boot when they were supposed to be disabled. Support calling init_static_kenv() very early in the boot, so as to use the env very early in the boot. Then the pointer to the loader env may change after the first call due to enabling paging or otherwise remapping the pointer. Another call is needed to register the change. Don't use the previous pointer in this (or any) later call. Reviewed by: kib
This commit is contained in:
parent
75f4f3ed51
commit
6fd2dcd428
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=343777
@ -250,6 +250,23 @@ init_static_kenv(char *buf, size_t len)
|
||||
char *eval;
|
||||
|
||||
KASSERT(!dynamic_kenv, ("kenv: dynamic_kenv already initialized"));
|
||||
|
||||
/*
|
||||
* We may be called twice, with the second call needed to relocate
|
||||
* md_envp after enabling paging. md_envp is then garbage if it is
|
||||
* not null and the relocation will move it. Discard it so as to
|
||||
* not crash using its old value in our first call to kern_getenv().
|
||||
*
|
||||
* The second call gives the same environment as the first except
|
||||
* in silly configurations where the static env disables itself.
|
||||
*
|
||||
* Other env calls don't handle possibly-garbage pointers, so must
|
||||
* not be made between enabling paging and calling here.
|
||||
*/
|
||||
md_envp = NULL;
|
||||
md_env_len = 0;
|
||||
md_env_pos = 0;
|
||||
|
||||
/*
|
||||
* Give the static environment a chance to disable the loader(8)
|
||||
* environment first. This is done with loader_env.disabled=1.
|
||||
@ -275,12 +292,16 @@ init_static_kenv(char *buf, size_t len)
|
||||
md_env_pos = 0;
|
||||
|
||||
eval = kern_getenv("static_env.disabled");
|
||||
if (eval != NULL && strcmp(eval, "1") == 0)
|
||||
*kern_envp = '\0';
|
||||
if (eval != NULL && strcmp(eval, "1") == 0) {
|
||||
kern_envp[0] = '\0';
|
||||
kern_envp[1] = '\0';
|
||||
}
|
||||
}
|
||||
eval = kern_getenv("static_hints.disabled");
|
||||
if (eval != NULL && strcmp(eval, "1") == 0)
|
||||
*static_hints = '\0';
|
||||
if (eval != NULL && strcmp(eval, "1") == 0) {
|
||||
static_hints[0] = '\0';
|
||||
static_hints[1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user