Received: from list by lists.gnu.org with archive (Exim 4.71) id 1dLIsI-0006w8-TE for mharc-grub-devel@gnu.org; Wed, 14 Jun 2017 20:43:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49064) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <3EdhBWQUKCpgEB8Xb8GG8D6.4GE8JM3-56N6D8FM.GJ8@flex--matthewgarrett.bounces.google.com>) id 1dLIsG-0006uS-Tm 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 <3EdhBWQUKCpgEB8Xb8GG8D6.4GE8JM3-56N6D8FM.GJ8@flex--matthewgarrett.bounces.google.com>) id 1dLIsG-0007AA-56 for grub-devel@gnu.org; Wed, 14 Jun 2017 20:43:00 -0400 Received: from mail-pg0-x249.google.com ([2607:f8b0:400e:c05::249]:35488) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from <3EdhBWQUKCpgEB8Xb8GG8D6.4GE8JM3-56N6D8FM.GJ8@flex--matthewgarrett.bounces.google.com>) id 1dLIsG-00078n-0Y for grub-devel@gnu.org; Wed, 14 Jun 2017 20:43:00 -0400 Received: by mail-pg0-x249.google.com with SMTP id v18so550132pgb.2 for ; Wed, 14 Jun 2017 17:42:57 -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=uB+x9o3K4lVTPs5jFy7eHxBQnwgkzBV4oLF3Hq4s8pg=; b=afPbx+0s34uSe4xbXkiHAfj1jiltzJe0NkYGdhNF0swTMpLo6EMa5c6ujOnXuyO5mQ TAphF7s8tM47wYgHkRY1VH6cKB/skZJuSsyv5P+047lpA1Q8ISlJKqYemjAeNM3hhDYy RgOOBVMYvrnSRo9uoyAkGroiZGmdwMpBe3OucKQz6lhbFQkg39BkWwk7UoxC9yX14vfl Rxrd6ezPsqTMN2XFdtKMCtsOBhBRJtrXsPGpqW2Y7rDEjUnaVnLmZu1Ea8MvF4mRUvVO W0GFK6J75RYAzDxH5Qa4GVFvsQ5hVuj56TydM2N9HbB8JDlveb3pG419tbl7cs5zfjrJ r7yA== 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=uB+x9o3K4lVTPs5jFy7eHxBQnwgkzBV4oLF3Hq4s8pg=; b=HElhXZqVbE4Td2IL7BUkMGSFVKFrL9McgfQX2hImLK0Oql1s8jc4vaSc4Q1Iyuf+3z PW3OOaovyDV/xJ2FZVThEph2Qhg9NW3zLtIdU17WPOpfBVHyp7V8Mv6RC57054u9Rlgi BiarYRfH+WLrTBfOvy+TjPY1R0UJ55/LDw5cywfov5wwElkm+Me/Hd/Ke51bDUZZIisP 3XjiIixw0Vj7SuSKCvfDDnwMjsqq4hkHT6Nuy+f8UbwLm/mNylmJQT4S6oKo8ahusx0r 23t2N+Zaq0//dR9Gcl9g+UxtbrlwV9aTPmTzEMGQn0+YmeJaK84wSyBU+lcsi3lVdSM7 8+eQ== X-Gm-Message-State: AKS2vOw3vWDZy42mKp/BzigGW5FquFG+0oH3EpqyTH/vhTGhkwW33sm0 KLTy48UAEOZhuSuy/iY/GudMUlsUTjy3O69ziIR/IQ0F7HvB0JAfHxwYU3u/9BaDoso1+vTTUeW 4cDrQM+6Z MIME-Version: 1.0 X-Received: by 10.99.140.9 with SMTP id m9mr1604508pgd.18.1497487377090; Wed, 14 Jun 2017 17:42:57 -0700 (PDT) Date: Wed, 14 Jun 2017 17:42:44 -0700 In-Reply-To: <20170615004245.127430-1-mjg59@google.com> Message-Id: <20170615004245.127430-3-mjg59@google.com> References: <20170615004245.127430-1-mjg59@google.com> X-Mailer: git-send-email 2.13.1.518.g3df882009-goog Subject: [PATCH 2/3] 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: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 Pass commands to the verification code. We want to be able to log these in the TPM verification case. --- 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 891036eb4..317b6efaf 100644 --- a/include/grub/verify.h +++ b/include/grub/verify.h @@ -11,6 +11,7 @@ enum grub_verify_string_type { GRUB_VERIFY_KERNEL_CMDLINE, GRUB_VERIFY_MODULE_CMDLINE, + GRUB_VERIFY_COMMAND, }; struct grub_file_verifier -- 2.13.1.518.g3df882009-goog