Received: from list by lists.gnu.org with archive (Exim 4.71) id 1gN4XA-0006IP-Fh for mharc-grub-devel@gnu.org; Wed, 14 Nov 2018 18:25:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <3267sWw4KCtA8wFF30I2wDD0FF2AA270.yA82DGx-z0H0729G.AD2@flex--matthewgarrett.bounces.google.com>) id 1gN4X7-0006IH-WC for grub-devel@gnu.org; Wed, 14 Nov 2018 18:25:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <3267sWw4KCtA8wFF30I2wDD0FF2AA270.yA82DGx-z0H0729G.AD2@flex--matthewgarrett.bounces.google.com>) id 1gN4X7-0002uM-4M for grub-devel@gnu.org; Wed, 14 Nov 2018 18:25:17 -0500 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]:45282) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from <3267sWw4KCtA8wFF30I2wDD0FF2AA270.yA82DGx-z0H0729G.AD2@flex--matthewgarrett.bounces.google.com>) id 1gN4X6-0002tz-JX for grub-devel@gnu.org; Wed, 14 Nov 2018 18:25:16 -0500 Received: by mail-pl1-x64a.google.com with SMTP id s24-v6so13118828plp.12 for ; Wed, 14 Nov 2018 15:25:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=p/Ati9uE3Vvjs2RH/5sL6cEtuv7RRqVdEQkjJ30YWWI=; b=pXoLODnll1AAGdD/TqyaGWanMAdMU37ENPnA30yFP7bOaLDZL+BE2JEdOdK6FmsmUf U2UsYrf65ImUl+4SEtB6h7hK1tzOIC5juzvgH0AOR4/FF5DPpppkrkZo+vnFGtMOUZT9 9NZjYa/zSSNeT/79+GvxQ8VjoolwVB6AkCffCUTU+Y6q0nwu9PJfeV6Fl2coeSdENQ0b ZxAh0FizkrRHv6myjLsohrZ1qR3P+iKt7eO/nGBx5/Bzfca9jS+xA9wk6RtQr0uiimJ6 Rq5RBjUqg3sH1pfV02LumfKBj4Oqxqio9eXRFUxzt6jPXvqAgEPcIgESWms+ksvTkmFw JvXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=p/Ati9uE3Vvjs2RH/5sL6cEtuv7RRqVdEQkjJ30YWWI=; b=ZII6UUEEAr7HHfGtL3cJBnNpaynePY4EVXvqwlTBOVjHLMv3XgVVNLib/wpBLEKOnW Y1wR5bNsxeryR6rfC9jCBRm/6f7+rBsGxTkIwp6lJPVqw+jDuAP7CTPPAdmgSthQg3ph cjI2/uFD3Y30LS7Vqeziq63/USiTYpZ0BXepQVyaqf81NDZMz6bIXhYvxbDMxDcvmjl0 H/2M68exiRV0F2HzuiHHR80RXGCBWhydj0m6iVWIY8XXitkIOsVUz87DabKPVrwbNGCT uA/YG+y+5lvuTtm+6n4aurHx7WRNZiXkZgBaLuIQHYw3ynl6HgosZ6XQPrfsNjO5+2oN hFqA== X-Gm-Message-State: AGRZ1gLgNGbjp8I7Uafij62N0PS4+UQQvHo/1kyrygJOgY9uvZ1q10dH Olwm+60ximoNkyv4iEoPsUUlhGYX2ZSxIYJNLb3OFaFxg+AM/pHsk7ZLDEsvb+92uH+/T+NFfgX C1zJc4JLNWYL2EmKMo+6yy9YkwU4Qukh6qaeoettR4gh9rMn5YexwxrkNEN6GtCqyfK55DnynUn sWFw== X-Google-Smtp-Source: AJdET5f4y1pvswolEqjChfX9b8TJCJfuzayVl5/S+Klbbsfwl3OYDyLu2JhfWI4DDcPr4w8O6uVCaQkeFtvGxuLpak2f/Q== X-Received: by 2002:a17:902:14e:: with SMTP id 72-v6mr294687plb.41.1542237915126; Wed, 14 Nov 2018 15:25:15 -0800 (PST) Date: Wed, 14 Nov 2018 15:24:52 -0800 Message-Id: <20181114232454.45350-1-matthewgarrett@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog Subject: [PATCH V2 1/3] verifiers: Verify commands executed by grub 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:4864:20::64a 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: Wed, 14 Nov 2018 23:25:18 -0000 From: Matthew Garrett Pass all commands executed by grub to the verifiers layer. Most verifiers will ignore this, but some (such as the TPM verifier) want to be able to measure and log each command executed in order to ensure that the boot state is as expected. Signed-off-by: Matthew Garrett --- grub-core/script/execute.c | 27 ++++++++++++++++++++++++--- include/grub/verify.h | 1 + 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c index a8502d907..ee299fd0e 100644 --- a/grub-core/script/execute.c +++ b/grub-core/script/execute.c @@ -27,6 +27,7 @@ #include #include #include +#include /* Max digits for a char is 3 (0xFF is 255), similarly for an int it is sizeof (int) * 3, and one extra for a possible -ve sign. */ @@ -929,8 +930,9 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) grub_err_t ret = 0; grub_script_function_t func = 0; char errnobuf[18]; - char *cmdname; - int argc; + char *cmdname, *cmdstring; + int argc, offset = 0, cmdlen = 0; + unsigned int i; char **args; int invert; struct grub_script_argv argv = { 0, 0, 0 }; @@ -939,6 +941,26 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) if (grub_script_arglist_to_argv (cmdline->arglist, &argv) || ! argv.args[0]) return grub_errno; + for (i = 0; i < argv.argc; i++) + { + cmdlen += grub_strlen (argv.args[i]) + 1; + } + + cmdstring = grub_malloc (cmdlen); + if (!cmdstring) + { + return grub_error (GRUB_ERR_OUT_OF_MEMORY, + N_("cannot allocate command buffer")); + } + + for (i = 0; i < argv.argc; i++) + { + offset += grub_snprintf (cmdstring + offset, cmdlen - offset, "%s ", + argv.args[i]); + } + cmdstring[cmdlen - 1] = '\0'; + grub_verify_string (cmdstring, GRUB_VERIFY_COMMAND); + grub_free (cmdstring); invert = 0; argc = argv.argc - 1; args = argv.args + 1; @@ -1163,4 +1185,3 @@ grub_script_execute (struct grub_script *script) return grub_script_execute_cmd (script->cmd); } - diff --git a/include/grub/verify.h b/include/grub/verify.h index 79022b422..460f2e20a 100644 --- a/include/grub/verify.h +++ b/include/grub/verify.h @@ -31,6 +31,7 @@ enum grub_verify_string_type { GRUB_VERIFY_KERNEL_CMDLINE, GRUB_VERIFY_MODULE_CMDLINE, + GRUB_VERIFY_COMMAND, }; struct grub_file_verifier -- 2.19.1.930.g4563a0d9d0-goog