Received: from list by lists.gnu.org with archive (Exim 4.71) id 1dLIsI-0006vp-MV for mharc-grub-devel@gnu.org; Wed, 14 Jun 2017 20:43:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49047) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <3DthBWQUKCpUB85UY5DD5A3.1DB5GJ0-23K3A5CJ.DG5@flex--matthewgarrett.bounces.google.com>) id 1dLIsF-0006tn-NW for grub-devel@gnu.org; Wed, 14 Jun 2017 20:43:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <3DthBWQUKCpUB85UY5DD5A3.1DB5GJ0-23K3A5CJ.DG5@flex--matthewgarrett.bounces.google.com>) id 1dLIsE-000797-4P for grub-devel@gnu.org; Wed, 14 Jun 2017 20:42:59 -0400 Received: from mail-pg0-x249.google.com ([2607:f8b0:400e:c05::249]:34736) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from <3DthBWQUKCpUB85UY5DD5A3.1DB5GJ0-23K3A5CJ.DG5@flex--matthewgarrett.bounces.google.com>) id 1dLIsD-00075t-Uy for grub-devel@gnu.org; Wed, 14 Jun 2017 20:42:58 -0400 Received: by mail-pg0-x249.google.com with SMTP id m19so552317pgd.1 for ; Wed, 14 Jun 2017 17:42:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:in-reply-to:message-id:references:subject:from:to :cc; bh=oBtUzOpi+KLMnriRxZi1hchkK1weryjEKhl9o6GwlCU=; b=NokPltN3tryvbL50YkIqe7wDGLsMK1xQ1HkUTbOGoKb/sTi7ko+MyLYnz+HlHKK6dq 8disYj/zKboZ6EFpQNMJLb5vz+Ejrva1+yKgG6nbY6tXweGAcvvyAqGphr1Vrcg8Dn2l 75OxXHyWEEQ552JuUAGCm+HKW2F+Ni3yX7quQlZFgVCGov2jFh/1qTJYx9xn9sAJ9Zek 1V8BE1rZcB3I4Va9k/2dU84t9YzH8ae2lMBOLRiBeaQWdQTgWWLEyvqYq7onhSgnPtU3 5aPCUj20L0sLq1vDJk3xC4O/NuhZ6ikX7aHIi9ZAU8HUilbIvfv/b//6xbV2bdpqI9uY 17zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:in-reply-to:message-id :references:subject:from:to:cc; bh=oBtUzOpi+KLMnriRxZi1hchkK1weryjEKhl9o6GwlCU=; b=ECbvuGeDBjxt6yNSBPJePWeXcGI6q/gzd+cYLiUt4oKjlH3+sAVD8H5O0fVFZw9afB kP9FxUQ3f2cVVZwmnT+BJfCnoPu8fO85Sie4TX/oSwbZPC+v9usW5Dyv3Gmtc771bUdq gC8VysTVgptVAK+KpOQLcuWFmVCEihn8STGlHRWiX6WDzIcv4E00NYjBoiLllurB1DpL uA9IPtTnynmbiANk+7gWn03vUenMnh3g6hsnnNO9QvptNx6027cnitDH2MIo7K/oHqET Umli+G68jH6eySClLnUMJ2gmLWVE5eUMWbGMR4OO1l3p9zbjYMwPNosecVQo5XPG2FyC 2TEA== X-Gm-Message-State: AKS2vOygvSVbbV0Cm39L/rvv91XKbx+XCjsIEbXOy1lJghKtDrNnlN6w n01WpTnvZSqljQrsc5RUAndlTLLiFtDAtKrQ56HUifXxD0AXDd7KQiixh/Ja+CekC8vica1su4f eDk/vER6C MIME-Version: 1.0 X-Received: by 10.98.159.18 with SMTP id g18mr1350167pfe.13.1497487374728; Wed, 14 Jun 2017 17:42:54 -0700 (PDT) Date: Wed, 14 Jun 2017 17:42:43 -0700 In-Reply-To: <20170615004245.127430-1-mjg59@google.com> Message-Id: <20170615004245.127430-2-mjg59@google.com> References: <20170615004245.127430-1-mjg59@google.com> X-Mailer: git-send-email 2.13.1.518.g3df882009-goog Subject: [PATCH 1/3] Move verifiers to the kernel From: Matthew Garrett To: grub-devel@gnu.org Cc: Matthew Garrett Content-Type: text/plain; charset="UTF-8" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::249 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Jun 2017 00:43:01 -0000 We want to be able to measure stuff right from the very beginning of grub execution, so it makes sense for the core verifiers code to be present in-kernel rather than having it as an external module. --- grub-core/Makefile.am | 1 + grub-core/Makefile.core.def | 6 +--- grub-core/kern/main.c | 3 ++ .../{commands/verify_helper.c => kern/verifiers.c} | 35 +++++++++++++++++----- include/grub/verify.h | 16 +++------- 5 files changed, 36 insertions(+), 25 deletions(-) rename grub-core/{commands/verify_helper.c => kern/verifiers.c} (78%) diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 104513847..ef2b66e0f 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -93,6 +93,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/verify.h if COND_i386_pc KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 16c4d0ea5..ab0f29960 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -129,6 +129,7 @@ kernel = { common = kern/rescue_parser.c; common = kern/rescue_reader.c; common = kern/term.c; + common = kern/verifiers.c; noemu = kern/compiler-rt.c; noemu = kern/mm.c; @@ -899,11 +900,6 @@ module = { cppflags = '-I$(srcdir)/lib/posix_wrap'; }; -module = { - name = verify_helper; - common = commands/verify_helper.c; -}; - module = { name = hdparm; common = commands/hdparm.c; diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c index 9cad0c448..b5a43c155 100644 --- a/grub-core/kern/main.c +++ b/grub-core/kern/main.c @@ -29,6 +29,7 @@ #include #include #include +#include #ifdef GRUB_MACHINE_PCBIOS #include @@ -274,6 +275,8 @@ grub_main (void) grub_printf ("Welcome to GRUB!\n\n"); grub_setcolorstate (GRUB_TERM_COLOR_STANDARD); + grub_file_filter_register (GRUB_FILE_FILTER_VERIFY, grub_verify_helper_open); + grub_load_config (); grub_boot_time ("Before loading embedded modules."); diff --git a/grub-core/commands/verify_helper.c b/grub-core/kern/verifiers.c similarity index 78% rename from grub-core/commands/verify_helper.c rename to grub-core/kern/verifiers.c index 5a55927e3..f8e47b009 100644 --- a/grub-core/commands/verify_helper.c +++ b/grub-core/kern/verifiers.c @@ -1,8 +1,25 @@ +/* verifiers.c - core verifiers support code */ +/* + * 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 . + */ + #include #include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); +#include struct grub_file_verifier *grub_file_verifiers; @@ -55,7 +72,7 @@ struct grub_fs verified_fs = .close = verified_close }; -static grub_file_t +grub_file_t grub_verify_helper_open (grub_file_t io, enum grub_file_type type) { grub_verified_t verified = 0; @@ -175,12 +192,14 @@ grub_verify_string (char *str, enum grub_verify_string_type type) return GRUB_ERR_NONE; } -GRUB_MOD_INIT(verify_helper) +void +grub_verifier_register (struct grub_file_verifier *ver) { - grub_file_filter_register (GRUB_FILE_FILTER_VERIFY, grub_verify_helper_open); + grub_list_push (GRUB_AS_LIST_P (&grub_file_verifiers), GRUB_AS_LIST (ver)); } -GRUB_MOD_FINI(verify_helper) +void +grub_verifier_unregister (struct grub_file_verifier *ver) { - grub_file_filter_unregister (GRUB_FILE_FILTER_VERIFY); + grub_list_remove (GRUB_AS_LIST (ver)); } diff --git a/include/grub/verify.h b/include/grub/verify.h index acab4f437..891036eb4 100644 --- a/include/grub/verify.h +++ b/include/grub/verify.h @@ -37,17 +37,9 @@ struct grub_file_verifier extern struct grub_file_verifier *grub_file_verifiers; -static inline void -grub_verifier_register (struct grub_file_verifier *ver) -{ - grub_list_push (GRUB_AS_LIST_P (&grub_file_verifiers), GRUB_AS_LIST (ver)); -} - -static inline void -grub_verifier_unregister (struct grub_file_verifier *ver) -{ - grub_list_remove (GRUB_AS_LIST (ver)); -} +grub_file_t grub_verify_helper_open(grub_file_t io, enum grub_file_type type); +void EXPORT_FUNC(grub_verifier_register) (struct grub_file_verifier *ver); +void EXPORT_FUNC(grub_verifier_unregister) (struct grub_file_verifier *ver); grub_err_t -grub_verify_string (char *str, enum grub_verify_string_type type); +EXPORT_FUNC(grub_verify_string) (char *str, enum grub_verify_string_type type); -- 2.13.1.518.g3df882009-goog