From patchwork Fri Mar 22 10:33:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chun-Yi Lee X-Patchwork-Id: 10865479 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 71DE915AC for ; Fri, 22 Mar 2019 10:34:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 524DF2A60B for ; Fri, 22 Mar 2019 10:34:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 451F52A65B; Fri, 22 Mar 2019 10:34:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAF2E2A60B for ; Fri, 22 Mar 2019 10:34:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727754AbfCVKeB (ORCPT ); Fri, 22 Mar 2019 06:34:01 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:44085 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727739AbfCVKeB (ORCPT ); Fri, 22 Mar 2019 06:34:01 -0400 Received: by mail-pg1-f195.google.com with SMTP id i2so1223444pgj.11; Fri, 22 Mar 2019 03:34:00 -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; bh=dZhxDdC/Qe4tqiAOQJ+sInBhscxUK5dRSwY91CjQlSQ=; b=ElTP5n1wpgt0y5iAgi21gAuo0spGZDqhq68weaFLRtb/NTJpNuS/SmTJuodnaovfNb s8QfcHzkt0JFGkh3dWrXzyp9fvNSOvsFNBO6AU6KMU4iBwBZzBWvSVKZfdy5rlGa7w7y B+8iLCF5LgWAHKQ1K4RHmOMR+KONTWv9YpQbD94sWrs51PHlZS0PR1MSLxqEIWYUzfFS yk5losiWqVwmIfSEXhE8oh0ZOD2LbyZwSLsu3BteUR15Rcr416lbZYBELexaKKn0Ci1i Q0aKFXMWirJXl2YZp6qXEphFJuwkrWiVuUrFdPidx82fg2q8sUeaY98BvmB0vpb7Un8v OFFQ== 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; bh=dZhxDdC/Qe4tqiAOQJ+sInBhscxUK5dRSwY91CjQlSQ=; b=py4q7EGWJ2ZWWx+ckg1So/9l6rSIL9tE+yaHHIrdpuFJdOU4xaHW6r/5ax2VIPi+hp 34E9XTh0jCTJHhokWMZaJwyOONg0VbAl6VaeITZ+Tz2wbwyFOvI2OYse7umB6qDLgp1c 57aduKqX8qeY6sZCS6uD07FMhA58/an1cPEv5HTyfUjPNdkz4efejxjnoMUfG2z1NcxU 4t5wHn2aJFGczZLS6drl1nGiYjKF/rGwlmWCsmUe2dKHfWyDoCk1J7RQt4q9ex2uS9lm KQFAFBokJNubDhaL6BH2/x9Cw5UazZo8YgHprKipS3+caX37FSrCLqVbrXkj+iEvXdGu mNRw== X-Gm-Message-State: APjAAAVh0ULpej+4RRtZm7S4zcXA2H7mKFDc59eNBOPdtSz2Mo3b9hyX w/+5ztu5iLcjXvnLEjjNYoA= X-Google-Smtp-Source: APXvYqzFJDtBWBT3GBBFqyLcyjpgdZ0DyM2Oh+tkI21b/hNCJ5Z10Wo4bnls5DBP/C+epVuShVOwvw== X-Received: by 2002:aa7:8b93:: with SMTP id r19mr8223640pfd.163.1553250840143; Fri, 22 Mar 2019 03:34:00 -0700 (PDT) Received: from linux-l9pv.suse ([202.47.205.198]) by smtp.gmail.com with ESMTPSA id l7sm22276889pfj.162.2019.03.22.03.33.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Mar 2019 03:33:59 -0700 (PDT) From: "Lee, Chun-Yi" X-Google-Original-From: "Lee, Chun-Yi" To: Ard Biesheuvel , James Morris , "Serge E . Hallyn" , David Howells , Josh Boyer , Nayna Jain , Mimi Zohar Cc: linux-efi@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, "Lee, Chun-Yi" , Kees Cook , Anton Vorontsov , Colin Cross , Tony Luck Subject: [PATCH 1/2] efi: add a function for transferring status to string Date: Fri, 22 Mar 2019 18:33:49 +0800 Message-Id: <20190322103350.27764-1-jlee@suse.com> X-Mailer: git-send-email 2.12.3 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This function can be used to transfer EFI status code to string for printing out debug message. Using this function can improve the readability of log. Cc: Ard Biesheuvel Cc: Kees Cook Cc: Anton Vorontsov Cc: Colin Cross Cc: Tony Luck Signed-off-by: "Lee, Chun-Yi" --- include/linux/efi.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/linux/efi.h b/include/linux/efi.h index 54357a258b35..a43cb0dc37af 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1768,4 +1768,32 @@ struct linux_efi_memreserve { #define EFI_MEMRESERVE_COUNT(size) (((size) - sizeof(struct linux_efi_memreserve)) \ / sizeof(((struct linux_efi_memreserve *)0)->entry[0])) +#define EFI_STATUS_STR(_status) \ +case EFI_##_status: \ + return "EFI_" __stringify(_status); + +static inline char * +efi_status_to_str(efi_status_t status) +{ + switch (status) { + EFI_STATUS_STR(SUCCESS) + EFI_STATUS_STR(LOAD_ERROR) + EFI_STATUS_STR(INVALID_PARAMETER) + EFI_STATUS_STR(UNSUPPORTED) + EFI_STATUS_STR(BAD_BUFFER_SIZE) + EFI_STATUS_STR(BUFFER_TOO_SMALL) + EFI_STATUS_STR(NOT_READY) + EFI_STATUS_STR(DEVICE_ERROR) + EFI_STATUS_STR(WRITE_PROTECTED) + EFI_STATUS_STR(OUT_OF_RESOURCES) + EFI_STATUS_STR(NOT_FOUND) + EFI_STATUS_STR(ABORTED) + EFI_STATUS_STR(SECURITY_VIOLATION) + default: + pr_warn("Unknown efi status: 0x%lx", status); + } + + return "Unknown efi status"; +} + #endif /* _LINUX_EFI_H */ From patchwork Fri Mar 22 10:33:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chun-Yi Lee X-Patchwork-Id: 10865481 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 80513922 for ; Fri, 22 Mar 2019 10:34:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6449628DDD for ; Fri, 22 Mar 2019 10:34:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5880E28E84; Fri, 22 Mar 2019 10:34:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B78EB28DDD for ; Fri, 22 Mar 2019 10:34:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728075AbfCVKeF (ORCPT ); Fri, 22 Mar 2019 06:34:05 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:42819 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727985AbfCVKeF (ORCPT ); Fri, 22 Mar 2019 06:34:05 -0400 Received: by mail-pg1-f194.google.com with SMTP id p6so1230077pgh.9; Fri, 22 Mar 2019 03:34:04 -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=XTYPASRGMg0q/uWZzsJSXvakCs0yqwCjmkSLykQSBrU=; b=sdemoHNJefqNMY39D7WWWxEJsg1U6wNnj5Cq/fU7JOZCKqJOtoia/qVwWjtz2SQPBt Mjv3qMaSiLjR5fyEtuyuJFrMggTGei9r1kmqGGy9EEZAuEXOfDjxAI9Bd+lmic8G8Diy U/u47rlm/5cOemYDNQpakBdsfhiEx0jh4wVJjdLIQKncGB6oMO8qGqhYBjMBw0nJMfAy G5+yAzEeSZ51U+fKlylDV85JjEa4C1CrVPaTuTJyiwflFBv2VRcYNGIWjGGaa7hrxc99 LTB/AvWXPDSldI+djBDChTLnTsrRKJ7Y60cEk0CmRnO5FEtIqyJNbUm0RFeZ5oWGa9b+ BzAg== 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=XTYPASRGMg0q/uWZzsJSXvakCs0yqwCjmkSLykQSBrU=; b=gpEVvBWRn3ofubF+Xhp46esHC5WNVfONJi5iGTZkDjeNroyZNmotRrTHfT5NQFSDt4 1SDssRVcLB/aWjaw7SSBcBb2D9UKHqH3pKwyRkj8W9po/s8QWYfbbyyzh7eALWhU/hBg /ihi8ATx/XDAqbCmU5Z3bcoFRnTTcG4eGH+6jBYYF88TYtv1Z2S0q9AQ9Kp4WesaGAk8 +9+4D8M0LJvqgEtSp8zWRThfiSCa50unsXKqivK/mL8efUsVSmroT5JWLtMA8nQ/vE7E TwnWtmkxv/JEg/3wRTAyFNcCAV/yw8gwnZDISLleJ9s9UBfJxbYhbT+RTg90F25ZjoxY VIeg== X-Gm-Message-State: APjAAAXj5LV3PT/+GxTxw5VQxDohh25FigAqajOpFMDdO6jupJpb8cum QsqcrWLpIfJ81JN9X8i/7OU= X-Google-Smtp-Source: APXvYqzPUdfWgIIlAW0XqLkR5mcW0Pb4CmOX0wux8eNkSVHoC6lUGnsTGnOTdO1nX26LI6GtHxdCNw== X-Received: by 2002:aa7:92c1:: with SMTP id k1mr8443187pfa.246.1553250844332; Fri, 22 Mar 2019 03:34:04 -0700 (PDT) Received: from linux-l9pv.suse ([202.47.205.198]) by smtp.gmail.com with ESMTPSA id l7sm22276889pfj.162.2019.03.22.03.34.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Mar 2019 03:34:03 -0700 (PDT) From: "Lee, Chun-Yi" X-Google-Original-From: "Lee, Chun-Yi" To: Ard Biesheuvel , James Morris , "Serge E . Hallyn" , David Howells , Josh Boyer , Nayna Jain , Mimi Zohar Cc: linux-efi@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, "Lee, Chun-Yi" Subject: [PATCH 2/2] efi: print appropriate status message when loading certificates Date: Fri, 22 Mar 2019 18:33:50 +0800 Message-Id: <20190322103350.27764-2-jlee@suse.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20190322103350.27764-1-jlee@suse.com> References: <20190322103350.27764-1-jlee@suse.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP When loading certificates list from UEFI variable, the original error message direct shows the efi status code from UEFI firmware. It looks ugly: [ 2.335031] Couldn't get size: 0x800000000000000e [ 2.335032] Couldn't get UEFI MokListRT [ 2.339985] Couldn't get size: 0x800000000000000e [ 2.339987] Couldn't get UEFI dbx list So, this patch shows the status string instead of status code. On the other hand, the error message of EFI_NOT_FOUND (0x800000000000000e) doesn't need to be exposed because kernel already prints "Couldn't get UEFI..." message. This patch also filtered out it. Link: https://forums.opensuse.org/showthread.php/535324-MODSIGN-Couldn-t-get-UEFI-db-list?p=2897516#post2897516 Cc: James Morris Cc: Serge E. Hallyn" Cc: David Howells Cc: Nayna Jain Cc: Josh Boyer Cc: Mimi Zohar Signed-off-by: "Lee, Chun-Yi" --- security/integrity/platform_certs/load_uefi.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/security/integrity/platform_certs/load_uefi.c b/security/integrity/platform_certs/load_uefi.c index 81b19c52832b..fe261166621f 100644 --- a/security/integrity/platform_certs/load_uefi.c +++ b/security/integrity/platform_certs/load_uefi.c @@ -48,7 +48,9 @@ static __init void *get_cert_list(efi_char16_t *name, efi_guid_t *guid, status = efi.get_variable(name, guid, NULL, &lsize, &tmpdb); if (status != EFI_BUFFER_TOO_SMALL) { - pr_err("Couldn't get size: 0x%lx\n", status); + if (status != EFI_NOT_FOUND) + pr_err("Couldn't get size: %s\n", + efi_status_to_str(status)); return NULL; } @@ -59,7 +61,8 @@ static __init void *get_cert_list(efi_char16_t *name, efi_guid_t *guid, status = efi.get_variable(name, guid, NULL, &lsize, db); if (status != EFI_SUCCESS) { kfree(db); - pr_err("Error reading db var: 0x%lx\n", status); + pr_err("Error reading db var: %s\n", + efi_status_to_str(status)); return NULL; }