Received: from list by lists.gnu.org with archive (Exim 4.71) id 1aQgpf-0003uu-7i for mharc-grub-devel@gnu.org; Tue, 02 Feb 2016 14:41:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60127) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQgpc-0003tw-TA for grub-devel@gnu.org; Tue, 02 Feb 2016 14:41:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aQgpY-00048Y-O4 for grub-devel@gnu.org; Tue, 02 Feb 2016 14:41:44 -0500 Received: from mail-lf0-x234.google.com ([2a00:1450:4010:c07::234]:35816) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQgpY-00048L-Ap for grub-devel@gnu.org; Tue, 02 Feb 2016 14:41:40 -0500 Received: by mail-lf0-x234.google.com with SMTP id l143so58944334lfe.2 for ; Tue, 02 Feb 2016 11:41:40 -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; bh=EQQTprhk/reETw6WD6rVqlojW7yQi2aaOZLTirWTWUg=; b=lotE3uTr11CUeIH+WtMUMH4RlwAImS5cmTOl1tV6Sy5jisY2ovkI2nq6f9nyfSKGOD LLl65dF/0DmP7MLtBJBSOK3ktBc7TbcoBNSR9XKdxhPK5H+/rA3lQGD/dIP+t/u4aOHH HrZidr19xQr7o380BXjjA/Po43lovHQlN+n98+ifqtBtX9QDfL9bBx4s5+OpuEtZILUY f1mP7uKpw9idsX85z5WGJmkW7k7oq+7ZwKTztAq9MCiZXE1O12V9GEa69LYLRel2z1Hx +jHqdY8enQgAbaSyZJsyPDbM2TcH7xSATAb02dqya9CzcmCNzAzQtMNrwY+AMq8BBQxY D8eQ== 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; bh=EQQTprhk/reETw6WD6rVqlojW7yQi2aaOZLTirWTWUg=; b=AlzosR+vlPTYPqadlWodFmWmeDJ4Rltb7FwCq1aknkoKqz5FcH9UzDaJYGHWVb/v9/ 6uaaBF9ZH17sYrB90lsZlJ9WkYqgcDaX9KBXCdFflATa88NRsxVyzC6Q3RrwPwEiHY2h /Y1cOhxJUqTZQFi2Llb+DebTA3DNbR4O6T0xzXO28KD8c2LLCSQWA4aGMHNf9npTBQzJ cEhHvvl15JC86mpEDhkw3sKLx750Oa+iQf8XkSp5QT2zisWGYSqc9ONMCGkC+SzAQ4R3 siiqaid9HDyCRoa3SM1nvJfJByuLn6THPSjTgJagtkWBl8WQCOuErSyNFP15RcyZRP/P uCJg== X-Gm-Message-State: AG10YOT6lTiC1AnJ/dFaGrSCHqlVJDI6Kc2XuBD8xC+IEunvb5D1Hj+88nybbrjzrKnXlw== X-Received: by 10.25.167.74 with SMTP id q71mr9956823lfe.22.1454442099282; Tue, 02 Feb 2016 11:41:39 -0800 (PST) Received: from localhost.localdomain (ppp109-252-76-159.pppoe.spdop.ru. [109.252.76.159]) by smtp.gmail.com with ESMTPSA id b10sm413724lbs.37.2016.02.02.11.41.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Feb 2016 11:41:38 -0800 (PST) From: Andrei Borzenkov To: grub-devel@gnu.org Subject: [PATCH] support modules without symbol table Date: Tue, 2 Feb 2016 22:41:30 +0300 Message-Id: <1454442090-23054-1-git-send-email-arvidjaar@gmail.com> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::234 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: Tue, 02 Feb 2016 19:41:46 -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 --- grub-core/kern/dl.c | 5 ++++- util/grub-module-verifierXX.c | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index 59a6ef4..5ce6fed 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); 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)