Received: by 10.213.65.68 with SMTP id h4csp262945imn; Tue, 13 Mar 2018 03:40:32 -0700 (PDT) X-Google-Smtp-Source: AG47ELub8kD5fgwKNzoj6+z04+6j3v4RookVBHRxeItcWBbvHo99Dcclg9WwBGfK7ObQecg/UP/L X-Received: by 10.101.86.198 with SMTP id w6mr92098pgs.434.1520937632847; Tue, 13 Mar 2018 03:40:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520937632; cv=none; d=google.com; s=arc-20160816; b=gMvki6vTLxsmHXsWUr89cMzBXbB7Zwu/leVSWmrjNwBRTyCpR/48BNKRN9THOZlgsJ 6Nv6ZGk0m4MH74ozbivef1u64gWBRpENWo8OPrHKHgiU/jiJQqZ8F6Qi43Ehbm+B64JS ajDI3IKbSDvWy6MnqrO7aLtNkBLPpIy5e+vo6NTyOuLxMSyRPsC62B2JqG1xefaVqE38 7qBgtOeKOY2+Wo3gt6VFlMrtjlReInZ66bE6IG4UYkUnzCEOqrYr5ZsL49bDxDSzlXSM unCgLJB3Imz8WpZkZwmR723S8XmO/fI07fyc8DalpxelEjqZiUVybg1vfeAEhvG2F5Bu 15fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=4jXFqFew+PjuccGwW8McFHwihVbpyehO0Jw3WRLPQEs=; b=pveRZzYa0SeQHHmL22WcHOQhNfX7OFPQTuxqD7AOrdeTVmZgieJR29HQdM3vlBw2om BqAwE1mbMs98PTgLZPOz/CHg9UP6+daUOZOWZ3YnHPiSmTYwmXZB0etBkbc3lEXvWugI X6XYF4UEn2pgT7jE33BKYl7k/J6Xofrq/i194n3opsGhlbpXDWl0cAcWeeV98cYTd/6C M+JGmzXBEJiqKpbHOrpyqAAOhwrssxV0fVv4XeAa7vlEgnstRFeaC/HME32zExP3NPrg /u8RwGk8+LEwkwA+UQMV5IZN8fp+/BDskXpSsZ3924Nd8F+A79vJa0qAAfeS3+/n6Mcp Pr/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=btuf75ye; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w24-v6si16400plq.553.2018.03.13.03.40.18; Tue, 13 Mar 2018 03:40:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=btuf75ye; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932965AbeCMKip (ORCPT + 99 others); Tue, 13 Mar 2018 06:38:45 -0400 Received: from mail-it0-f67.google.com ([209.85.214.67]:51899 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932866AbeCMKic (ORCPT ); Tue, 13 Mar 2018 06:38:32 -0400 Received: by mail-it0-f67.google.com with SMTP id u66so15142932ith.1; Tue, 13 Mar 2018 03:38:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4jXFqFew+PjuccGwW8McFHwihVbpyehO0Jw3WRLPQEs=; b=btuf75yexsEtz23xstoJuryYompBSsX6ko0wbq7DfaHU9zGdCrCiQuq/zDXqBrZR2s uvwVRBlMNSb0PhaPR6NUEO5wfXbFVL50hpxY6XuiqGD33cG97hxc9+JkVNwfYVOJev+L AgCs8BlNJpOx303jUOFgd9Cp7s+3mV3Jw0oNVKD3a0fmfYI7QkEsOv/itrsdNoL97nY1 bmCqwFU5sj6GmqsSDYyfqM29uirZ9ljeq8XF18FLpwaUbczOB1Hw9nVV2uhfGL0CTSIn HscDSiZAx2J+QWeTYzCzwP7C1IaSoLEhhgcQTZuOGW+89FHLPX0DiwM/1t2EJNPnpPHq j30A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4jXFqFew+PjuccGwW8McFHwihVbpyehO0Jw3WRLPQEs=; b=RJlUAei75/VwI68rZKXq2mEhgrCHr6NNNnsvlWFnx4WclD2zMnTsqc5XcvHIq/2gLy 0YFOSBVWmWm+vF3NwwpOJlzHmdd++Gyw6H2idd87DXYHtblPJ0+h1wdGO7VkpAE9PwNX PwzacvuGXAaw4spJcAE7Vk5MieeU59t0WBovuF07XIwnMHR258FYvg2t4MAO8FUY9kEf OXj5EIhpmIUgMSqcjhO9Hro1fySm33PZ3gOw9u7+aA8Xdi0GnglJCra2FJu5LIYC+egK nDafvxV4IH6uN+stK9tqRvxgsHBcTCLSbgnY0LcKw7pJFCsNny064s5JbtAhRFna9DOD iJCA== X-Gm-Message-State: AElRT7EZn7cywVx5KspC7QfOyRVJTTgKLqH8QT9wqTlDjprZRwcCl2rQ Nm7yQiFfXQwoHIiKvIBpGZk= X-Received: by 10.36.31.21 with SMTP id d21mr278086itd.71.1520937512134; Tue, 13 Mar 2018 03:38:32 -0700 (PDT) Received: from linux-l9pv.suse ([134.159.103.118]) by smtp.gmail.com with ESMTPSA id y128sm282657itb.39.2018.03.13.03.38.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Mar 2018 03:38:31 -0700 (PDT) From: "Lee, Chun-Yi" X-Google-Original-From: "Lee, Chun-Yi" To: David Howells Cc: linux-fs@vger.kernel.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, "Lee, Chun-Yi" , Josh Boyer , James Bottomley Subject: [PATCH 5/5] MODSIGN: check the attributes of db and mok Date: Tue, 13 Mar 2018 18:38:03 +0800 Message-Id: <20180313103803.13388-6-jlee@suse.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180313103803.13388-1-jlee@suse.com> References: <20180313103803.13388-1-jlee@suse.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org That's better for checking the attributes of db and mok variables before loading certificates to kernel keyring. For db and dbx, both of them are authenticated variables. Which means that they can only be modified by manufacturer's key. So the kernel should checks EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute before we trust it. For mok-rt and mokx-rt, both of them are created by shim boot loader to forward the mok/mokx content to runtime. They must be runtime-volatile variables. So kernel should checks that the attributes map did not set EFI_VARIABLE_NON_VOLATILE bit before we trust it. Cc: David Howells Cc: Josh Boyer Cc: James Bottomley Signed-off-by: "Lee, Chun-Yi" --- certs/load_uefi.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/certs/load_uefi.c b/certs/load_uefi.c index dc66a79..52526bd 100644 --- a/certs/load_uefi.c +++ b/certs/load_uefi.c @@ -33,7 +33,8 @@ static __init bool uefi_check_ignore_db(void) return status == EFI_SUCCESS; } -static __init void print_get_fail(efi_char16_t *char16_str, efi_status_t status) +static __init void print_get_fail(efi_char16_t *char16_str, efi_status_t status, + u32 attr) { char *utf8_str; unsigned long utf8_size; @@ -46,8 +47,8 @@ static __init void print_get_fail(efi_char16_t *char16_str, efi_status_t status) return; ucs2_as_utf8(utf8_str, char16_str, utf8_size); - pr_info("MODSIGN: Couldn't get UEFI %s: %s\n", - utf8_str, efi_status_to_str(status)); + pr_info("MODSIGN: Couldn't get UEFI %s: %s Attributes: 0x%016x\n", + utf8_str, efi_status_to_str(status), attr); kfree(utf8_str); } @@ -55,12 +56,13 @@ static __init void print_get_fail(efi_char16_t *char16_str, efi_status_t status) * Get a certificate list blob from the named EFI variable. */ static __init void *get_cert_list(efi_char16_t *name, efi_guid_t *guid, - unsigned long *size) + unsigned long *size, u32 pos_attr, u32 neg_attr) { efi_status_t status; unsigned long lsize = 4; unsigned long tmpdb[4]; void *db; + u32 attr = 0; status = efi.get_variable(name, guid, NULL, &lsize, &tmpdb); if (status != EFI_BUFFER_TOO_SMALL) { @@ -75,17 +77,22 @@ static __init void *get_cert_list(efi_char16_t *name, efi_guid_t *guid, goto err; } - status = efi.get_variable(name, guid, NULL, &lsize, db); + status = efi.get_variable(name, guid, &attr, &lsize, db); if (status != EFI_SUCCESS) { - kfree(db); pr_err("Error reading db var: 0x%lx\n", status); - goto err; + goto free; } + /* must have positive attributes and no negative attributes */ + if ((pos_attr && !(attr & pos_attr)) || + (neg_attr && (attr & neg_attr))) + goto free; *size = lsize; return db; +free: + kfree(db); err: - print_get_fail(name, status); + print_get_fail(name, status, attr); return NULL; } @@ -175,7 +182,8 @@ static int __init load_uefi_certs(void) * an error if we can't get them. */ if (!uefi_check_ignore_db()) { - db = get_cert_list(L"db", &secure_var, &dbsize); + db = get_cert_list(L"db", &secure_var, &dbsize, + EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS, 0); if (db) { rc = parse_efi_signature_list("UEFI:db", db, dbsize, get_handler_for_db); @@ -185,7 +193,8 @@ static int __init load_uefi_certs(void) } } - dbx = get_cert_list(L"dbx", &secure_var, &dbxsize); + dbx = get_cert_list(L"dbx", &secure_var, &dbxsize, + EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS, 0); if (dbx) { rc = parse_efi_signature_list("UEFI:dbx", dbx, dbxsize, @@ -199,7 +208,8 @@ static int __init load_uefi_certs(void) if (!efi_enabled(EFI_SECURE_BOOT)) return 0; - mok = get_cert_list(L"MokListRT", &mok_var, &moksize); + mok = get_cert_list(L"MokListRT", &mok_var, &moksize, + 0, EFI_VARIABLE_NON_VOLATILE); if (mok) { rc = parse_efi_signature_list("UEFI:MokListRT", mok, moksize, get_handler_for_db); @@ -208,7 +218,8 @@ static int __init load_uefi_certs(void) kfree(mok); } - mokx = get_cert_list(L"MokListXRT", &mok_var, &mokxsize); + mokx = get_cert_list(L"MokListXRT", &mok_var, &mokxsize, + 0, EFI_VARIABLE_NON_VOLATILE); if (mokx) { rc = parse_efi_signature_list("UEFI:mokx", mokx, mokxsize, -- 2.10.2