Received: from list by lists.gnu.org with archive (Exim 4.71) id 1gSRzg-0004E7-PA for mharc-grub-devel@gnu.org; Thu, 29 Nov 2018 14:29:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56261) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <39D0AXA4KClcBzII63L5zGG3II5DD5A3.1DB5GJ0-23K3A5CJ.DG5@flex--matthewgarrett.bounces.google.com>) id 1gSRzc-0004Dy-UI for grub-devel@gnu.org; Thu, 29 Nov 2018 14:28:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <39D0AXA4KClcBzII63L5zGG3II5DD5A3.1DB5GJ0-23K3A5CJ.DG5@flex--matthewgarrett.bounces.google.com>) id 1gSRzb-0001jM-CS for grub-devel@gnu.org; Thu, 29 Nov 2018 14:28:56 -0500 Received: from mail-io1-xd49.google.com ([2607:f8b0:4864:20::d49]:49946) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from <39D0AXA4KClcBzII63L5zGG3II5DD5A3.1DB5GJ0-23K3A5CJ.DG5@flex--matthewgarrett.bounces.google.com>) id 1gSRzb-0001ip-4I for grub-devel@gnu.org; Thu, 29 Nov 2018 14:28:55 -0500 Received: by mail-io1-xd49.google.com with SMTP id s10so2951880iop.16 for ; Thu, 29 Nov 2018 11:28:53 -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=F2/dZ4aRyNxLUYC/9Qh1+KxQdzYmEIGelXCBDdGqDHI=; b=LZk/3e0daM6gfHyQQXRe6jILcbmzkWQBwS1wEWPw/66ffGAfTgLxdZkOv+SG4ji3wG ycgYIUl04if3VzDFVIileMYfQdmF7QFiO5c9G6iE9JXHsP86nbnAhbVy5LzbIrUvnojl ujEhW8sMAemEb7pD0ZXaDtFtc1sqVTlxeOUukPVCfEViBZYgIcaJmklocrTQ0HGIzB8Y CV7HUWiQIaodRvDpEb0OJ5M6Ygy+G4NEG2GLNTmlZx+d4PKDocz8bfA/hl0u4beO1u53 2riWRIAKVNGZpOH0ZwDxx6FSmv+5VbaRkkyc8erQ+d+zL6nXud0HKnn71WMQu+A27v+h V/2w== 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=F2/dZ4aRyNxLUYC/9Qh1+KxQdzYmEIGelXCBDdGqDHI=; b=rgN+lk9hulyu0kIODOib/cInyW9Pr9wnOoepwOQ2lcS/kxjMQZ9ZFBG6UInoSrSoZb QziRzmoLb91ylxZeYojqVlgp+GMZiy4D9MrgEC+e8Tdq2zxtJ/0wV+85kpkREenp82ww VqaAg5N8B1dMXeFDPy12P5F1Cj0Y9HG7E54cKMUjhc3swyVuFjsuuTmdY+MPZeJN8Hyq E9rvA5oVOeWrMx4DCeVZi22KP5lYiULAmEVMZSN2zh51YY7K5l2P3qUJZUEWbByyi7JT 5/k5230NX4x4jsFxY2mdG3MPEolfh/Qe8tNExhQhCidzjPbc9uGJ+xkQsjHMLHRC4QwE wN2Q== X-Gm-Message-State: AA+aEWYXxS/j41Nkp5qJWVRk0mZrplfaW2JBMcStTvJCOjfhf1TeUmQZ Z5xUg4FC6Gg5/zbW/ythsurEq1olmoBqosi6Ynxcdnjd1u0bCxn6Jbrwrvlt5/KjpoKWwCWtZMD Ngglz+687vrBAEBl+hud2kDcs5GQv9mkNiMxRQNNJZ/9/EThhZI3iazxuour1PSMYqjPUBaIHwJ niXQ== X-Google-Smtp-Source: AFSGD/WOWHfxdYzg5Et1l1cH3wVZh+yMryPiRnakgdLBOLzN4uzW9+QWduVoFIw2/qJV7Rnx1jHZDyzKd5vBRs20nigsGQ== X-Received: by 2002:a24:2c4d:: with SMTP id i74mr2310103iti.12.1543519732785; Thu, 29 Nov 2018 11:28:52 -0800 (PST) Date: Thu, 29 Nov 2018 11:28:08 -0800 Message-Id: <20181129192810.190769-1-matthewgarrett@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-goog Subject: [PATCH V3 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::d49 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, 29 Nov 2018 19:28:58 -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.20.0.rc0.387.gc7a69e6b6c-goog