Received: from list by lists.gnu.org with archive (Exim 4.71) id 1aR0oL-0002MN-Si for mharc-grub-devel@gnu.org; Wed, 03 Feb 2016 12:01:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aR0oJ-0002H6-9R for grub-devel@gnu.org; Wed, 03 Feb 2016 12:01:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aR0oF-0006bN-9s for grub-devel@gnu.org; Wed, 03 Feb 2016 12:01:43 -0500 Received: from mail-lb0-x22d.google.com ([2a00:1450:4010:c04::22d]:35172) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aR0oE-0006bD-T1 for grub-devel@gnu.org; Wed, 03 Feb 2016 12:01:39 -0500 Received: by mail-lb0-x22d.google.com with SMTP id bc4so15983483lbc.2 for ; Wed, 03 Feb 2016 09:01:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TMvcEmZY1wklHztUfQErPSt/jT3vGujoPDkFYIDzYiE=; b=AYW+3bcxtgAE/ML72jATPzwYobGYBN+giXVm2liGwLAAbAYy4li0ZSwxr1ERcCEvfd bG2dbYPdlBRHXka1F3eRDm4Bg3kWnwpakvJLktzl+RNN+V4lCPZnMxODt/jUGl8Jqkf5 bd/IIDJHY2k76OSsePsAmrEh0KpoOxd4EqhZ5bw6GJJDjaoiQ+lMdEa9E9YMpD8MWbgO 4HgP29qNIhgG/VzVBAnJK7zeuqOgIcSVWf13w96OtYWih1pdEe+/JOkiCFFJBHn3M8nw QoP+CS74fZ+zfaw01KrPPoLLp8fE63TlS30LvOfbHkVxUvaHE+S+uxNqrrA6qic0xhtg dNZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TMvcEmZY1wklHztUfQErPSt/jT3vGujoPDkFYIDzYiE=; b=kD3ELNY11cJardqqaVKSFFPkW5Tltj7agE5247w7lwzI0hXes7qH92HS62ptRZa6YJ pD8DSE7DzCH07Lddra78QcHaIPfB00Uuxwxjl14IYALA0gHChDuEJ+Ty2m/5cJKMVxdq J0e4eMc5h903awfIIp00IC173HPP4R8EiRZAyiIPxNTUk4lYLTB6FYm7UHNJOzrr+inq rpzT41Ibqqes3eOEFne9VMEsdPxShK+rEzxHq1u8qhebNjLeq7+FqCmPlB5XD3vX3QII +E7NFEIqDfh0rmHdkSTYOplD4mxrkn7a8pXMQzRo1I6tgrYWvE/QqafcVTiAgNVj/Tnz 7aDA== X-Gm-Message-State: AG10YOSYC3LovV1Rbu3aVt+kea0jcC+gZV2wvf7yl8IFwd4JD2WZ9NmD57HhcANmFYMzHg== X-Received: by 10.112.172.200 with SMTP id be8mr1304996lbc.78.1454518897901; Wed, 03 Feb 2016 09:01:37 -0800 (PST) Received: from localhost.localdomain (ppp109-252-76-159.pppoe.spdop.ru. [109.252.76.159]) by smtp.gmail.com with ESMTPSA id mp1sm1003496lbb.22.2016.02.03.09.01.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 03 Feb 2016 09:01:36 -0800 (PST) From: Andrei Borzenkov To: grub-devel@gnu.org Subject: [PATCH v2] support modules without symbol table Date: Wed, 3 Feb 2016 20:01:24 +0300 Message-Id: <1454518884-31352-1-git-send-email-arvidjaar@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c04::22d Cc: bergerkos@yahoo.co.uk X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Feb 2016 17:01:44 -0000 all_video module does not have any code or data and exists solely for .moddeps section to pull in dependencies. This makes all symbols unneeded. While in current binutils (last released version as of this commit is 2.26) ``strip --strip-unneeded'' unintentionally adds section symbols for each existing section, this behavior was considered a bug and changed in commit 14f2c699ddca1e2f706342dffc59a6c7e23e844c to completely strip symbol table in this case. Older binutils (verified with 2.17) and some other toolchains (at least elftoolchain r3223M), both used in FreeBSD, remove symbol table in all_video as well. Relax run-time check and do not return error for modules without symbol table. Add additional checks to module verifier to make sure such modules a) have non-empty .moddeps section. Without either externally visible symbols or .moddeps modules are completely useless and should not be built. b) do not have any relocations. Closes: 46986 v2: add run-time check for empty symbol table if relocations are present as suggested by Vladimir. --- grub-core/kern/dl.c | 8 +++++++- util/grub-module-verifierXX.c | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index 59a6ef4..e394cd9 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -333,8 +333,11 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e) if (s->sh_type == SHT_SYMTAB) break; + /* Module without symbol table may still be used to pull in dependencies. + We verify at build time that such modules do not contain any relocations + that may reference symbol table. */ if (i == e->e_shnum) - return grub_error (GRUB_ERR_BAD_MODULE, N_("no symbol table")); + return GRUB_ERR_NONE; #ifdef GRUB_MODULES_MACHINE_READONLY mod->symtab = grub_malloc (s->sh_size); @@ -576,6 +579,9 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr) if (seg) { + if (!mod->symtab) + return grub_error (GRUB_ERR_BAD_MODULE, "relocation without symbol table"); + err = grub_arch_dl_relocate_symbols (mod, ehdr, s, seg); if (err) return err; diff --git a/util/grub-module-verifierXX.c b/util/grub-module-verifierXX.c index f612d51..f8c15b0 100644 --- a/util/grub-module-verifierXX.c +++ b/util/grub-module-verifierXX.c @@ -176,7 +176,7 @@ get_symtab (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, Elf_Word break; if (i == grub_target_to_host16 (e->e_shnum)) - grub_util_error ("no symbol table"); + return NULL; sym = (Elf_Sym *) ((char *) e + grub_target_to_host (s->sh_offset)); *size = grub_target_to_host (s->sh_size); @@ -191,7 +191,21 @@ check_symbols (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e) Elf_Word size, entsize; unsigned i; + /* Module without symbol table and without .moddeps section is useless + at boot time, so catch it early to prevent build errors */ sym = get_symtab (arch, e, &size, &entsize); + if (!sym) + { + Elf_Shdr *s = find_section (arch, e, ".moddeps"); + + if (!s) + grub_util_error ("no symbol table and no .moddeps section"); + + if (!s->sh_size) + grub_util_error ("no symbol table and empty .moddeps section"); + + return; + } for (i = 0; i < size / entsize; @@ -243,6 +257,8 @@ section_check_relocations (const struct grub_module_verifier_arch *arch, void *e Elf_Word symtabsize, symtabentsize; symtab = get_symtab (arch, ehdr, &symtabsize, &symtabentsize); + if (!symtab) + grub_util_error ("relocation without symbol table"); for (rel = (Elf_Rel *) ((char *) ehdr + grub_target_to_host (s->sh_offset)), max = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_size)); @@ -272,6 +288,7 @@ section_check_relocations (const struct grub_module_verifier_arch *arch, void *e break; if (arch->short_relocations[i] == -1) grub_util_error ("unsupported relocation 0x%x", type); + sym = (Elf_Sym *) ((char *) symtab + symtabentsize * ELF_R_SYM (grub_target_to_host (rel->r_info))); if (is_symbol_local (sym)) -- tg: (7290bb5..) bug/46986 (depends on: master)