Commit f030c8e3 authored by Lorenzo "Palinuro" Faletra's avatar Lorenzo "Palinuro" Faletra
Browse files

Import Upstream version 2.02+dfsg1

parent d48f3a3d
/* i386 CPU-specific part of loadcore.c for 32-bit mode */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/err.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/efiemu/efiemu.h>
#include <grub/cpu/efiemu.h>
#include <grub/elf.h>
#include <grub/i18n.h>
/* Check if EHDR is a valid ELF header. */
int
grub_arch_efiemu_check_header64 (void *ehdr)
{
Elf64_Ehdr *e = ehdr;
return (e->e_ident[EI_CLASS] == ELFCLASS64
&& e->e_ident[EI_DATA] == ELFDATA2LSB
&& e->e_machine == EM_X86_64);
}
/* Relocate symbols. */
grub_err_t
grub_arch_efiemu_relocate_symbols64 (grub_efiemu_segment_t segs,
struct grub_efiemu_elf_sym *elfsyms,
void *ehdr)
{
unsigned i;
Elf64_Ehdr *e = ehdr;
Elf64_Shdr *s;
grub_err_t err;
for (i = 0, s = (Elf64_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
i++, s = (Elf64_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_RELA)
{
grub_efiemu_segment_t seg;
grub_dprintf ("efiemu", "shtrel\n");
/* Find the target segment. */
for (seg = segs; seg; seg = seg->next)
if (seg->section == s->sh_info)
break;
if (seg)
{
Elf64_Rela *rel, *max;
for (rel = (Elf64_Rela *) ((char *) e + s->sh_offset),
max = rel + (unsigned long) s->sh_size
/ (unsigned long)s->sh_entsize;
rel < max;
rel++)
{
void *addr;
grub_uint32_t *addr32;
grub_uint64_t *addr64;
struct grub_efiemu_elf_sym sym;
if (seg->size < rel->r_offset)
return grub_error (GRUB_ERR_BAD_MODULE,
"reloc offset is out of the segment");
addr =
((char *) grub_efiemu_mm_obtain_request (seg->handle)
+ seg->off + rel->r_offset);
addr32 = (grub_uint32_t *) addr;
addr64 = (grub_uint64_t *) addr;
sym = elfsyms[ELF64_R_SYM (rel->r_info)];
switch (ELF64_R_TYPE (rel->r_info))
{
case R_X86_64_64:
err = grub_efiemu_write_value (addr,
*addr64 + rel->r_addend
+ sym.off, sym.handle,
0, seg->ptv_rel_needed,
sizeof (grub_uint64_t));
if (err)
return err;
break;
case R_X86_64_PC32:
err = grub_efiemu_write_value (addr,
*addr32 + rel->r_addend
+ sym.off
- rel->r_offset - seg->off,
sym.handle, seg->handle,
seg->ptv_rel_needed,
sizeof (grub_uint32_t));
if (err)
return err;
break;
case R_X86_64_32:
case R_X86_64_32S:
err = grub_efiemu_write_value (addr,
*addr32 + rel->r_addend
+ sym.off, sym.handle,
0, seg->ptv_rel_needed,
sizeof (grub_uint32_t));
if (err)
return err;
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%x is not implemented yet"),
ELF_R_TYPE (rel->r_info));
}
}
}
}
return GRUB_ERR_NONE;
}
/* dl-x86_64.c - arch-dependent part of loadable module support */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2005,2007,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/dl.h>
#include <grub/elf.h>
#include <grub/misc.h>
#include <grub/err.h>
#include <grub/i18n.h>
/* Check if EHDR is a valid ELF header. */
grub_err_t
grub_arch_dl_check_header (void *ehdr)
{
Elf64_Ehdr *e = ehdr;
/* Check the magic numbers. */
if (e->e_ident[EI_CLASS] != ELFCLASS64
|| e->e_ident[EI_DATA] != ELFDATA2LSB
|| e->e_machine != EM_X86_64)
return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic"));
return GRUB_ERR_NONE;
}
/* Relocate symbols. */
grub_err_t
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
Elf_Shdr *s, grub_dl_segment_t seg)
{
Elf64_Rela *rel, *max;
for (rel = (Elf64_Rela *) ((char *) ehdr + s->sh_offset),
max = (Elf64_Rela *) ((char *) rel + s->sh_size);
rel < max;
rel = (Elf64_Rela *) ((char *) rel + s->sh_entsize))
{
Elf64_Word *addr32;
Elf64_Xword *addr64;
Elf64_Sym *sym;
if (seg->size < rel->r_offset)
return grub_error (GRUB_ERR_BAD_MODULE,
"reloc offset is out of the segment");
addr32 = (Elf64_Word *) ((char *) seg->addr + rel->r_offset);
addr64 = (Elf64_Xword *) addr32;
sym = (Elf64_Sym *) ((char *) mod->symtab
+ mod->symsize * ELF_R_SYM (rel->r_info));
switch (ELF_R_TYPE (rel->r_info))
{
case R_X86_64_64:
*addr64 += rel->r_addend + sym->st_value;
break;
case R_X86_64_PC32:
{
grub_int64_t value;
value = ((grub_int32_t) *addr32) + rel->r_addend + sym->st_value -
(Elf64_Xword) (grub_addr_t) seg->addr - rel->r_offset;
if (value != (grub_int32_t) value)
return grub_error (GRUB_ERR_BAD_MODULE, "relocation out of range");
*addr32 = value;
}
break;
case R_X86_64_PC64:
{
*addr64 += rel->r_addend + sym->st_value -
(Elf64_Xword) (grub_addr_t) seg->addr - rel->r_offset;
}
break;
case R_X86_64_32:
{
grub_uint64_t value = *addr32 + rel->r_addend + sym->st_value;
if (value != (grub_uint32_t) value)
return grub_error (GRUB_ERR_BAD_MODULE, "relocation out of range");
*addr32 = value;
}
break;
case R_X86_64_32S:
{
grub_int64_t value = ((grub_int32_t) *addr32) + rel->r_addend + sym->st_value;
if (value != (grub_int32_t) value)
return grub_error (GRUB_ERR_BAD_MODULE, "relocation out of range");
*addr32 = value;
}
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%x is not implemented yet"),
ELF_R_TYPE (rel->r_info));
}
}
return GRUB_ERR_NONE;
}
This diff is collapsed.
#include <stdio.h>
#include <string.h>
#include <grub/elf.h>
#include <grub/module_verifier.h>
#include <grub/misc.h>
#include <grub/util/misc.h>
struct grub_module_verifier_arch archs[] = {
{ "i386", 4, 0, EM_386, GRUB_MODULE_VERIFY_SUPPORTS_REL, (int[]){
R_386_32,
R_386_PC32,
-1
} },
{ "x86_64", 8, 0, EM_X86_64, GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_X86_64_64,
R_X86_64_PC64,
/* R_X86_64_32, R_X86_64_32S are supported but shouldn't be used because of their limited range. */
-1
}, (int[]){
R_X86_64_PC32,
-1
}
},
{ "powerpc", 4, 1, EM_PPC, GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
GRUB_ELF_R_PPC_ADDR16_LO,
GRUB_ELF_R_PPC_REL24, /* It has limited range but GRUB adds trampolines when necessarry. */
GRUB_ELF_R_PPC_ADDR16_HA,
GRUB_ELF_R_PPC_ADDR32,
GRUB_ELF_R_PPC_REL32,
-1
} },
{ "sparc64", 8, 1, EM_SPARCV9, GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_SPARC_WDISP30, /* It has limited range but GRUB adds trampolines when necessarry. */
R_SPARC_HH22,
R_SPARC_HM10,
R_SPARC_LM22,
R_SPARC_LO10,
R_SPARC_64,
R_SPARC_OLO10,
/* Following 2 relocations have limited range but unfortunately
clang generates them, as it doesn't implement mcmodel=large properly.
At least our heap and core are under 4G, so it's not a problem
usually. */
R_SPARC_HI22,
R_SPARC_32,
-1
} },
{ "ia64", 8, 0, EM_IA_64, GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_IA64_PCREL21B, /* We should verify that it's pointing either
to a function or to a section in the same module.
Checking that external symbol is a function is
non-trivial and I have never seen this relocation used
for anything else, so assume that it always points to a
function.
*/
R_IA64_SEGREL64LSB,
R_IA64_FPTR64LSB,
R_IA64_DIR64LSB,
R_IA64_PCREL64LSB,
R_IA64_LTOFF22X,
R_IA64_LTOFF22,
R_IA64_GPREL64I,
R_IA64_LTOFF_FPTR22,
R_IA64_LDXMOV,
-1
}, (int[]){
R_IA64_GPREL22,
-1
} },
{ "mipsel", 4, 0, EM_MIPS, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_MIPS_HI16,
R_MIPS_LO16,
R_MIPS_32,
R_MIPS_GPREL32,
R_MIPS_26,
R_MIPS_GOT16,
R_MIPS_CALL16,
R_MIPS_JALR,
-1
} },
{ "mips", 4, 1, EM_MIPS, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_MIPS_HI16,
R_MIPS_LO16,
R_MIPS_32,
R_MIPS_GPREL32,
R_MIPS_26,
R_MIPS_GOT16,
R_MIPS_CALL16,
R_MIPS_JALR,
-1
} },
{ "arm", 4, 0, EM_ARM, GRUB_MODULE_VERIFY_SUPPORTS_REL, (int[]){
/* Some relocations are range-limited but trampolines are added when necessarry. */
R_ARM_ABS32,
R_ARM_CALL,
R_ARM_JUMP24,
R_ARM_THM_CALL,
R_ARM_THM_JUMP24,
R_ARM_V4BX,
R_ARM_THM_MOVW_ABS_NC,
R_ARM_THM_MOVT_ABS,
R_ARM_THM_JUMP19,
-1
} },
{ "arm64", 8, 0, EM_AARCH64, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_AARCH64_ABS64,
R_AARCH64_CALL26,
R_AARCH64_JUMP26,
R_AARCH64_ADR_GOT_PAGE,
R_AARCH64_LD64_GOT_LO12_NC,
-1
}, (int[]){
R_AARCH64_ADR_PREL_PG_HI21,
R_AARCH64_ADD_ABS_LO12_NC,
R_AARCH64_LDST64_ABS_LO12_NC,
R_AARCH64_PREL32,
-1
}
},
};
struct platform_whitelist {
const char *arch;
const char *platform;
const char **whitelist_empty;
};
static struct platform_whitelist whitelists[] = {
{"i386", "xen", (const char *[]) {"all_video", 0}},
{"x86_64", "xen", (const char *[]) {"all_video", 0}},
{"sparc64", "ieee1275", (const char *[]) {"all_video", 0}},
/* video is compiled-in on MIPS. */
{"mipsel", "loongson", (const char *[]) {"all_video", 0}},
{"mipsel", "qemu_mips", (const char *[]) {"all_video", 0}},
{"mipsel", "arc", (const char *[]) {"all_video", 0}},
{"mips", "qemu_mips", (const char *[]) {"all_video", 0}},
{"mips", "arc", (const char *[]) {"all_video", 0}},
};
int
main (int argc, char **argv)
{
size_t module_size;
unsigned arch, whitelist;
const char **whitelist_empty = 0;
char *module_img;
if (argc != 4) {
fprintf (stderr, "usage: %s FILE ARCH PLATFORM\n", argv[0]);
return 1;
}
for (arch = 0; arch < ARRAY_SIZE(archs); arch++)
if (strcmp(archs[arch].name, argv[2]) == 0)
break;
if (arch == ARRAY_SIZE(archs))
grub_util_error("unknown arch: %s", argv[2]);
for (whitelist = 0; whitelist < ARRAY_SIZE(whitelists); whitelist++)
if (strcmp(whitelists[whitelist].arch, argv[2]) == 0
&& strcmp(whitelists[whitelist].platform, argv[3]) == 0)
break;
if (whitelist != ARRAY_SIZE(whitelists))
whitelist_empty = whitelists[whitelist].whitelist_empty;
module_size = grub_util_get_image_size (argv[1]);
module_img = grub_util_read_image (argv[1]);
if (archs[arch].voidp_sizeof == 8)
grub_module_verify64(module_img, module_size, &archs[arch], whitelist_empty);
else
grub_module_verify32(module_img, module_size, &archs[arch], whitelist_empty);
return 0;
}
replace-libgcrypt-crc.patch
olpc_prefix_hack.patch
core_in_fs.patch
dpkg_version_comparison.patch
grub_legacy_0_based_partitions.patch
disable_floppies.patch
grub.cfg_400.patch
gfxpayload_keep_default.patch
install_stage2_confusion.patch
mkrescue_efi_modules.patch
mkconfig_loopback.patch
restore_mkdevicemap.patch
gettext_quiet.patch
mkconfig_mid_upgrade.patch
install_efi_fallback.patch
mkconfig_ubuntu_recovery.patch
install_locale_langpack.patch
mkconfig_nonexistent_loopback.patch
no_insmod_on_sb.patch
default_grub_d.patch
blacklist_1440x900x32.patch
uefi_firmware_setup.patch
mkconfig_ubuntu_distributor.patch
linuxefi.patch
linuxefi_debug.patch
linuxefi_require_shim.patch
linuxefi_non_sb_fallback.patch
mkconfig_signed_kernel.patch
install_signed.patch
sleep_shift.patch
wubi_no_windows.patch
maybe_quiet.patch
install_efi_ubuntu_flavours.patch
quick_boot.patch
gfxpayload_dynamic.patch
vt_handoff.patch
probe_fusionio.patch
ignore_grub_func_test_failures.patch
mkconfig_recovery_title.patch
skip_gettext_strings_test.patch
install_powerpc_machtypes.patch
ieee1275-clear-reset.patch
ppc64el-disable-vsx.patch
grub-install-pvxen-paths.patch
insmod-xzio-and-lzopio-on-xen.patch
grub-install-extra-removable.patch
mkconfig_other_inits.patch
syslinux-test-out-of-tree.patch
zpool_full_device_name.patch
misc-fix-invalid-char-strtol.patch
net_read_bracketed_ipv6_addr.patch
bootp_new_net_bootp6_command.patch
efinet_uefi_ipv6_pxe_support.patch
bootp_process_dhcpack_http_boot.patch
efinet_set_network_from_uefi_devpath.patch
efinet_set_dns_from_uefi_proto.patch
grub-install-efibootmgr-check.patch
ext4_feature_encrypt.patch
tsc_efi_default_to_pmtimer.patch
freetype-capitalise-variables.patch
freetype-pkg-config.patch
fix-yylex-build.patch
sparc64-support.patch
printf-unit-test-gcc7.patch
xen-multiboot2.patch
linuxefi_disable_sb_fallback.patch
fix_lockdown.patch
tests-disable-sercon-in-seabios.patch
tests-fix-uhci-qemu-options.patch
R_X86_64_PLT32.patch
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2010,2011 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/net.h>
#include <grub/env.h>
#include <grub/i18n.h>
#include <grub/command.h>
#include <grub/net/ip.h>
#include <grub/net/netbuff.h>
#include <grub/net/udp.h>
#include <grub/datetime.h>
static void
parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask)
{
const grub_uint8_t *ptr, *ptr0;
ptr = ptr0 = vend;
if (ptr[0] != GRUB_NET_BOOTP_RFC1048_MAGIC_0
|| ptr[1] != GRUB_NET_BOOTP_RFC1048_MAGIC_1
|| ptr[2] != GRUB_NET_BOOTP_RFC1048_MAGIC_2
|| ptr[3] != GRUB_NET_BOOTP_RFC1048_MAGIC_3)
return;
ptr = ptr + sizeof (grub_uint32_t);
while (ptr - ptr0 < limit)
{
grub_uint8_t tagtype;
grub_uint8_t taglength;
tagtype = *ptr++;
/* Pad tag. */
if (tagtype == GRUB_NET_BOOTP_PAD)
continue;
/* End tag. */
if (tagtype == GRUB_NET_BOOTP_END)
return;
taglength = *ptr++;
switch (tagtype)
{
case GRUB_NET_BOOTP_NETMASK:
if (taglength == 4)
{
int i;
for (i = 0; i < 32; i++)
if (!(ptr[i / 8] & (1 << (7 - (i % 8)))))
break;
*mask = i;
}
break;
case GRUB_NET_BOOTP_ROUTER:
if (taglength == 4)
{
grub_net_network_level_netaddress_t target;
grub_net_network_level_address_t gw;
char *rname;
target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
target.ipv4.base = 0;
target.ipv4.masksize = 0;
gw.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
grub_memcpy (&gw.ipv4, ptr, sizeof (gw.ipv4));
rname = grub_xasprintf ("%s:default", name);
if (rname)
grub_net_add_route_gw (rname, target, gw, NULL);
grub_free (rname);
}
break;
case GRUB_NET_BOOTP_DNS:
{
int i;
for (i = 0; i < taglength / 4; i++)
{