preload_search_info: make sure mod is set

Add a check to preload_search_info to make sure mod is set. Most of the
callers of preload_search_info don't check that the mod parameter is
set, which can cause page faults. While at it, remove some now unnecessary
checks before calling preload_search_info.

Sponsored by:		Citrix Systems R&D
Reviewed by:		kib
Differential Revision:	https://reviews.freebsd.org/D3440
This commit is contained in:
royger 2015-08-21 15:57:57 +00:00
parent ef7f753c04
commit 5b319fbe38
8 changed files with 13 additions and 23 deletions

View File

@ -1621,8 +1621,8 @@ hammer_time(u_int64_t modulep, u_int64_t physfree)
* Use vt(4) by default for UEFI boot (during the sc(4)/vt(4)
* transition).
*/
if (kmdp != NULL && preload_search_info(kmdp,
MODINFO_METADATA | MODINFOMD_EFI_MAP) != NULL)
if (preload_search_info(kmdp, MODINFO_METADATA | MODINFOMD_EFI_MAP)
!= NULL)
vty_set_preferred(VTY_VT);
identify_cpu(); /* Final stage of CPU initialization */

View File

@ -1534,10 +1534,7 @@ initarm(struct arm_boot_params *abp)
* Find the dtb passed in by the boot loader.
*/
kmdp = preload_search_by_type("elf kernel");
if (kmdp != NULL)
dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t);
else
dtbp = (vm_offset_t)NULL;
dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t);
#if defined(FDT_DTB_STATIC)
/*
* In case the device tree blob was not retrieved (from metadata) try

View File

@ -2097,9 +2097,8 @@ getmemsize(int first)
kmdp = preload_search_by_type("elf kernel");
if (kmdp == NULL)
kmdp = preload_search_by_type("elf32 kernel");
if (kmdp != NULL)
smapbase = (struct bios_smap *)preload_search_info(kmdp,
MODINFO_METADATA | MODINFOMD_SMAP);
smapbase = (struct bios_smap *)preload_search_info(kmdp,
MODINFO_METADATA | MODINFOMD_SMAP);
if (smapbase != NULL) {
add_smap_entries(smapbase, physmap, &physmap_idx);
has_smap = 1;
@ -2778,8 +2777,6 @@ smap_sysctl_handler(SYSCTL_HANDLER_ARGS)
kmdp = preload_search_by_type("elf kernel");
if (kmdp == NULL)
kmdp = preload_search_by_type("elf32 kernel");
if (kmdp == NULL)
return (0);
smapbase = (struct bios_smap *)preload_search_info(kmdp,
MODINFO_METADATA | MODINFOMD_SMAP);
if (smapbase == NULL)

View File

@ -400,8 +400,7 @@ link_elf_init(void* arg)
modptr = preload_search_by_type("elf" __XSTRING(__ELF_WORD_SIZE) " kernel");
if (modptr == NULL)
modptr = preload_search_by_type("elf kernel");
if (modptr != NULL)
modname = (char *)preload_search_info(modptr, MODINFO_NAME);
modname = (char *)preload_search_info(modptr, MODINFO_NAME);
if (modname == NULL)
modname = "kernel";
linker_kernel_file = linker_make_file(modname, &link_elf_class);

View File

@ -160,6 +160,9 @@ preload_search_info(caddr_t mod, int inf)
uint32_t type = 0;
int next;
if (mod == NULL)
return (NULL);
curp = mod;
for (;;) {
hdr = (uint32_t *)curp;

View File

@ -251,10 +251,7 @@ platform_start(__register_t a0, __register_t a1, __register_t a2,
* Find the dtb passed in by the boot loader (currently fictional).
*/
kmdp = preload_search_by_type("elf kernel");
if (kmdp != NULL)
dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t);
else
dtbp = (vm_offset_t)NULL;
dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t);
#if defined(FDT_DTB_STATIC)
/*

View File

@ -54,7 +54,7 @@ x86_init_fdt(void)
mdp = preload_search_by_type("elf kernel");
if (mdp == NULL)
mdp = preload_search_by_type("elf32 kernel");
dtbp = (mdp != NULL) ? MD_FETCH(mdp, MODINFOMD_DTBP, void *) : NULL;
dtbp = MD_FETCH(mdp, MODINFOMD_DTBP, void *);
#if defined(FDT_DTB_STATIC)
/*

View File

@ -690,11 +690,8 @@ ram_attach(device_t dev)
kmdp = preload_search_by_type("elf kernel");
if (kmdp == NULL)
kmdp = preload_search_by_type(ELF_KERN_STR);
if (kmdp != NULL)
smapbase = (struct bios_smap *)preload_search_info(kmdp,
MODINFO_METADATA | MODINFOMD_SMAP);
else
smapbase = NULL;
smapbase = (struct bios_smap *)preload_search_info(kmdp,
MODINFO_METADATA | MODINFOMD_SMAP);
if (smapbase != NULL) {
smapsize = *((u_int32_t *)smapbase - 1);
smapend = (struct bios_smap *)((uintptr_t)smapbase + smapsize);