From patchwork Wed Apr 5 09:23:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 96793 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp173369qgd; Wed, 5 Apr 2017 02:23:45 -0700 (PDT) X-Received: by 10.98.71.151 with SMTP id p23mr27549057pfi.252.1491384225571; Wed, 05 Apr 2017 02:23:45 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y73si20044853pgd.394.2017.04.05.02.23.45; Wed, 05 Apr 2017 02:23:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933076AbdDEJXb (ORCPT + 2 others); Wed, 5 Apr 2017 05:23:31 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:36282 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932632AbdDEJXa (ORCPT ); Wed, 5 Apr 2017 05:23:30 -0400 Received: by mail-wm0-f41.google.com with SMTP id o81so44872550wmb.1 for ; Wed, 05 Apr 2017 02:23:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bHcTYY1QGmzaEu59N+/dWbxmEtlmMr4EIgSwpX4l6gY=; b=CWG86LL147yWHW0QIGX0919qzZ8H+PwAx0mrVu+25qDtx4lO1Z5gi2mwGF8WQu1y22 yEZatlsUUkUqxhY90PoouofkHo7Fo/f6PA1eRGHWgaC6jZZzK55Wf4DPkUbLj9uvwJDH ZfJRdLYZjxRg2ITG070kdUtyMfWJd3B/Is9ek= 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=bHcTYY1QGmzaEu59N+/dWbxmEtlmMr4EIgSwpX4l6gY=; b=SA3EDi3CIvZeLt0URP0zhdNSET9Pu8xYTWSM/Gh/zF91vKrFkyN6oPqYsq8FlLqa3J LTusHpsheezQpYZ+dx6f20ETazJLMDzXalkwVSTmRH7fllx0dM9G89yMXoDvnGrQ/la6 YMRPK7Fi9mUBXMghTe5hVwH4HLMzYVJN7yv/raWK8i/icRTA7Y+JtzZkJRyL/DTBz/10 En1zHRbe3WGydEWdNSSoQQK42KcePxZBclyu/VGJpSDTjzcU0PkojHYIL4faBCWjFOh5 Y8iyGzgtZBnkM9MZnXoJhs6RT/NH7vdv+g8zfLfBPzuz/HGlkLR/hOpKnyaVqz0Ins7g wI8A== X-Gm-Message-State: AFeK/H3gviPLmV5vJQv//qziaBi+NWWoE//f0IK2dXZLlslNursfglXr RaLZ4ufx+k//ClDhcJxm8Q== X-Received: by 10.28.137.208 with SMTP id l199mr17416187wmd.65.1491384208961; Wed, 05 Apr 2017 02:23:28 -0700 (PDT) Received: from localhost.localdomain ([160.163.145.113]) by smtp.gmail.com with ESMTPSA id b66sm23935271wrd.29.2017.04.05.02.23.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 02:23:28 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: matt@codeblueprint.co.uk, andy.shevchenko@gmail.com, pure.logic@nexus-software.ie, hock.leong.kweh@intel.com, bp@alien8.de, sascha.weisenberger@siemens.com, jan.kiszka@siemens.com, Ard Biesheuvel Subject: [PATCH 1/8] efi/capsule: Fix return code on failing kmap/vmap Date: Wed, 5 Apr 2017 10:23:10 +0100 Message-Id: <20170405092317.27921-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170405092317.27921-1-ard.biesheuvel@linaro.org> References: <20170405092317.27921-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Jan Kiszka If kmap or vmap fail, it means we ran out of memory. There are no user-provided addressed involved that would justify EFAULT. Signed-off-by: Jan Kiszka Cc: Matt Fleming Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/capsule-loader.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Reviewed-by: Matt Fleming diff --git a/drivers/firmware/efi/capsule-loader.c b/drivers/firmware/efi/capsule-loader.c index 9ae6c116c474..91e91f7a8807 100644 --- a/drivers/firmware/efi/capsule-loader.c +++ b/drivers/firmware/efi/capsule-loader.c @@ -113,7 +113,7 @@ static ssize_t efi_capsule_submit_update(struct capsule_info *cap_info) VM_MAP, PAGE_KERNEL); if (!cap_hdr_temp) { pr_debug("%s: vmap() failed\n", __func__); - return -EFAULT; + return -ENOMEM; } ret = efi_capsule_update(cap_hdr_temp, cap_info->pages); @@ -185,7 +185,7 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff, kbuff = kmap(page); if (!kbuff) { pr_debug("%s: kmap() failed\n", __func__); - ret = -EFAULT; + ret = -ENOMEM; goto failed; } kbuff += PAGE_SIZE - cap_info->page_bytes_remain; From patchwork Wed Apr 5 09:23:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 96795 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp173374qgd; Wed, 5 Apr 2017 02:23:46 -0700 (PDT) X-Received: by 10.84.222.4 with SMTP id w4mr13937181pls.184.1491384225952; Wed, 05 Apr 2017 02:23:45 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y73si20044853pgd.394.2017.04.05.02.23.45; Wed, 05 Apr 2017 02:23:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933094AbdDEJXe (ORCPT + 2 others); Wed, 5 Apr 2017 05:23:34 -0400 Received: from mail-wm0-f49.google.com ([74.125.82.49]:36910 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932632AbdDEJXd (ORCPT ); Wed, 5 Apr 2017 05:23:33 -0400 Received: by mail-wm0-f49.google.com with SMTP id x124so8373181wmf.0 for ; Wed, 05 Apr 2017 02:23:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NblNsCCdKsolqY0/mEOG3SpUSa3gIKzcKf00koxyk0Q=; b=TbjojhFj9WL9llJHaS/HwbTX15FvlVUe7yaVZYM8PgnmVEqk+UF4fZNpvrdzx5Dy6Z CODWipjcEruis0gNa5HIcHeAIWL509r2MvVQzTwco7cH15ylZSh2Ay0pDtXeBsCDciOA eDEEFnasw9n4gUBjwq2EuzZhuWFTfQ9LSOcM8= 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=NblNsCCdKsolqY0/mEOG3SpUSa3gIKzcKf00koxyk0Q=; b=J5iu/OXKHHB9fynK5uoyg+EwtEE+CvjWxr4EsIkJAnJOIni1ThSHsrkAl23Q5HIc8m DeVrGfQSKWaKlOv7D1Q9CbCXV4XqmsXbGviQ3vm9y38ZPAvyOgV+ObbhoO5h5VtWvG7o 07YLwTZfdrTHeZRZr7qkpOqZsXrl/yNpYj5QGgcfgMik0qne9CFjGnQddaBCJoDn/d+K BM2jOHc09cRhRux0Mm6Mig6mbG2NhfIwJcvtBPD0B8Xn4+bYMpHLUATPl7qoRNcEdKKg CVDcKgKcaCpmKqhHh07P1GEoB/EaMD0cMVNDLwVVboUfiLKtSbUSTbFp8Xol25r/APZh 66Jw== X-Gm-Message-State: AFeK/H3Rpj7QjuY7kKMBo3MLmNHe0eog5KyvKO3t59UtBV8ERb9PLVVS /Oepd6Q0pQOrtaa2 X-Received: by 10.28.23.194 with SMTP id 185mr18042505wmx.52.1491384211744; Wed, 05 Apr 2017 02:23:31 -0700 (PDT) Received: from localhost.localdomain ([160.163.145.113]) by smtp.gmail.com with ESMTPSA id b66sm23935271wrd.29.2017.04.05.02.23.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 02:23:31 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: matt@codeblueprint.co.uk, andy.shevchenko@gmail.com, pure.logic@nexus-software.ie, hock.leong.kweh@intel.com, bp@alien8.de, sascha.weisenberger@siemens.com, jan.kiszka@siemens.com, Ard Biesheuvel Subject: [PATCH 2/8] efi/capsule: Remove pr_debug on ENOMEM or EFAULT Date: Wed, 5 Apr 2017 10:23:11 +0100 Message-Id: <20170405092317.27921-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170405092317.27921-1-ard.biesheuvel@linaro.org> References: <20170405092317.27921-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Jan Kiszka Both cases are not worth a debug log message - the error code is telling enough. Signed-off-by: Jan Kiszka Cc: Matt Fleming Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/capsule-loader.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Reviewed-by: Matt Fleming diff --git a/drivers/firmware/efi/capsule-loader.c b/drivers/firmware/efi/capsule-loader.c index 91e91f7a8807..7b57dda2417d 100644 --- a/drivers/firmware/efi/capsule-loader.c +++ b/drivers/firmware/efi/capsule-loader.c @@ -88,10 +88,8 @@ static ssize_t efi_capsule_setup_info(struct capsule_info *cap_info, temp_page = krealloc(cap_info->pages, pages_needed * sizeof(void *), GFP_KERNEL | __GFP_ZERO); - if (!temp_page) { - pr_debug("%s: krealloc() failed\n", __func__); + if (!temp_page) return -ENOMEM; - } cap_info->pages = temp_page; cap_info->header_obtained = true; @@ -111,10 +109,8 @@ static ssize_t efi_capsule_submit_update(struct capsule_info *cap_info) cap_hdr_temp = vmap(cap_info->pages, cap_info->index, VM_MAP, PAGE_KERNEL); - if (!cap_hdr_temp) { - pr_debug("%s: vmap() failed\n", __func__); + if (!cap_hdr_temp) return -ENOMEM; - } ret = efi_capsule_update(cap_hdr_temp, cap_info->pages); vunmap(cap_hdr_temp); @@ -171,7 +167,6 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff, if (!cap_info->page_bytes_remain) { page = alloc_page(GFP_KERNEL); if (!page) { - pr_debug("%s: alloc_page() failed\n", __func__); ret = -ENOMEM; goto failed; } @@ -184,7 +179,6 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff, kbuff = kmap(page); if (!kbuff) { - pr_debug("%s: kmap() failed\n", __func__); ret = -ENOMEM; goto failed; } @@ -193,7 +187,6 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff, /* Copy capsule binary data from user space to kernel space buffer */ write_byte = min_t(size_t, count, cap_info->page_bytes_remain); if (copy_from_user(kbuff, buff, write_byte)) { - pr_debug("%s: copy_from_user() failed\n", __func__); ret = -EFAULT; goto fail_unmap; } From patchwork Wed Apr 5 09:23:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 96794 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp173376qgd; Wed, 5 Apr 2017 02:23:46 -0700 (PDT) X-Received: by 10.98.157.12 with SMTP id i12mr27148210pfd.166.1491384226127; Wed, 05 Apr 2017 02:23:46 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y73si20044853pgd.394.2017.04.05.02.23.46; Wed, 05 Apr 2017 02:23:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933109AbdDEJXh (ORCPT + 2 others); Wed, 5 Apr 2017 05:23:37 -0400 Received: from mail-wm0-f49.google.com ([74.125.82.49]:38293 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932632AbdDEJXf (ORCPT ); Wed, 5 Apr 2017 05:23:35 -0400 Received: by mail-wm0-f49.google.com with SMTP id t189so8330629wmt.1 for ; Wed, 05 Apr 2017 02:23:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5svIytWXYviLeylhPurJscFcOztDy+tX0Hx0VjTLmLQ=; b=PwT66zDv26i27GXIzg4Dn7UvlWqBgoHByXBohpl0rQvWLb6pK5VOT9AUeqnvjYnEWL /1JvIqUNA9x0hqNr3KAUOpt5G1NeKpMGjJgNAC6JJlr+gvffe9hfiEAkZFd59TE9APIQ bRLmBy2gk10hJtuq/3fwikUZF7k2Q6gkFqbGU= 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=5svIytWXYviLeylhPurJscFcOztDy+tX0Hx0VjTLmLQ=; b=ekum3oYTCieKPw/Zvs3uC4+FFIuQCUZ9hfgr3J7U4zlUIMWWCLXBmPwcsVDP9eBpDP om0DR4Jx2WaHjZeE8479MKzJxiSxI+riuZ6ZY4xtBNSwFTjSEa5BXXMRmJLV32s1g/Ei OzSQBwkXjDU28nF/UKcTKAqjUcTmOEjwMKhyZtTUMwwfEdsYWJUOtf+pw2w52z31wWvR /1pUzWeEDhb3KKBmUtdrBu+cP+wr7ETaTlRuvhQMICcTzFLYYxeZNm4pd/7+14Zs+ga9 PXd8ojzdCTLzCqrLY3yOclFjRLO/KS9Gn/DCuJXyyNBGo8lmx60d9uZTHEvbAHaEuJJ7 UnZw== X-Gm-Message-State: AFeK/H2qY+5mLGOiGy6A15wqK7lu56hZC2LFzkOOAXedMab9pVJr3nKa m6bG8tUsdsdLn0f2 X-Received: by 10.28.195.197 with SMTP id t188mr18712107wmf.61.1491384214277; Wed, 05 Apr 2017 02:23:34 -0700 (PDT) Received: from localhost.localdomain ([160.163.145.113]) by smtp.gmail.com with ESMTPSA id b66sm23935271wrd.29.2017.04.05.02.23.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 02:23:33 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: matt@codeblueprint.co.uk, andy.shevchenko@gmail.com, pure.logic@nexus-software.ie, hock.leong.kweh@intel.com, bp@alien8.de, sascha.weisenberger@siemens.com, jan.kiszka@siemens.com, Ard Biesheuvel Subject: [PATCH 3/8] efi/capsule: Clean up pr_err/info messages Date: Wed, 5 Apr 2017 10:23:12 +0100 Message-Id: <20170405092317.27921-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170405092317.27921-1-ard.biesheuvel@linaro.org> References: <20170405092317.27921-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Jan Kiszka Avoid __func__, improve the information provided by some of the messages. Signed-off-by: Jan Kiszka Cc: Matt Fleming Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/capsule-loader.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Reviewed-by: Matt Fleming diff --git a/drivers/firmware/efi/capsule-loader.c b/drivers/firmware/efi/capsule-loader.c index 7b57dda2417d..3fb91e1597a9 100644 --- a/drivers/firmware/efi/capsule-loader.c +++ b/drivers/firmware/efi/capsule-loader.c @@ -70,7 +70,7 @@ static ssize_t efi_capsule_setup_info(struct capsule_info *cap_info, pages_needed = ALIGN(cap_hdr->imagesize, PAGE_SIZE) >> PAGE_SHIFT; if (pages_needed == 0) { - pr_err("%s: pages count invalid\n", __func__); + pr_err("invalid capsule size"); return -EINVAL; } @@ -79,8 +79,7 @@ static ssize_t efi_capsule_setup_info(struct capsule_info *cap_info, cap_hdr->imagesize, &cap_info->reset_type); if (ret) { - pr_err("%s: efi_capsule_supported() failed\n", - __func__); + pr_err("capsule not supported\n"); return ret; } @@ -115,14 +114,14 @@ static ssize_t efi_capsule_submit_update(struct capsule_info *cap_info) ret = efi_capsule_update(cap_hdr_temp, cap_info->pages); vunmap(cap_hdr_temp); if (ret) { - pr_err("%s: efi_capsule_update() failed\n", __func__); + pr_err("capsule update failed\n"); return ret; } /* Indicate capsule binary uploading is done */ cap_info->index = NO_FURTHER_WRITE_ACTION; - pr_info("%s: Successfully upload capsule file with reboot type '%s'\n", - __func__, !cap_info->reset_type ? "RESET_COLD" : + pr_info("Successfully upload capsule file with reboot type '%s'\n", + !cap_info->reset_type ? "RESET_COLD" : cap_info->reset_type == 1 ? "RESET_WARM" : "RESET_SHUTDOWN"); return 0; @@ -207,8 +206,7 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff, if (cap_info->header_obtained && cap_info->count >= cap_info->total_size) { if (cap_info->count > cap_info->total_size) { - pr_err("%s: upload size exceeded header defined size\n", - __func__); + pr_err("capsule upload size exceeded header defined size\n"); ret = -EINVAL; goto failed; } @@ -242,7 +240,7 @@ static int efi_capsule_flush(struct file *file, fl_owner_t id) struct capsule_info *cap_info = file->private_data; if (cap_info->index > 0) { - pr_err("%s: capsule upload not complete\n", __func__); + pr_err("capsule upload not complete\n"); efi_free_all_buff_pages(cap_info); ret = -ECANCELED; } @@ -321,8 +319,7 @@ static int __init efi_capsule_loader_init(void) ret = misc_register(&efi_capsule_misc); if (ret) - pr_err("%s: Failed to register misc char file note\n", - __func__); + pr_err("Unable to register capsule loader device\n"); return ret; } From patchwork Wed Apr 5 09:23:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 96796 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp173381qgd; Wed, 5 Apr 2017 02:23:46 -0700 (PDT) X-Received: by 10.84.197.3 with SMTP id m3mr34816501pld.89.1491384226636; Wed, 05 Apr 2017 02:23:46 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y73si20044853pgd.394.2017.04.05.02.23.46; Wed, 05 Apr 2017 02:23:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933115AbdDEJXk (ORCPT + 2 others); Wed, 5 Apr 2017 05:23:40 -0400 Received: from mail-wr0-f172.google.com ([209.85.128.172]:33322 "EHLO mail-wr0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932632AbdDEJXi (ORCPT ); Wed, 5 Apr 2017 05:23:38 -0400 Received: by mail-wr0-f172.google.com with SMTP id w43so5206435wrb.0 for ; Wed, 05 Apr 2017 02:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wBBEVIkyPT5yx/BsijZ//J7/PZ9Qf2RCp+la0h2xcEc=; b=cY2h3l/CyWr+YTsGUU0B9Shd+gMOL4xaWTmpF+mDXgKzsGIxbUqPt8LXdrWJpmBRAg J/BJBYgpby3tBsxzU/d92ITRHgE3lKzRoVf6FsWRWWdTWEOccHWgN56pCzNmaeE0c5n+ Ci02jx1xj2U47AZ4SotnWRPtPP/oQ+NC3bdI4= 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=wBBEVIkyPT5yx/BsijZ//J7/PZ9Qf2RCp+la0h2xcEc=; b=E/AZJZ660Xg80ufgUFArMX+eWd92xVo08u8gPLkkdbZlA4pnsX0LxrIUjI4Gueu7cv LqyHZJ3YY6xYKME0TK91vsybaC8djGpwvJcH1YWnYg5lupINSvG6Sp7I3WVSSUA48eSV uBILFNdqBF9ul0XwiwrMBNiYKbXLfMRFmADvLqe4qjsCCTThSQuH3Ke0Jd9stN6mDLX2 T7h4KrKHLa0qqXM3h6a/2uPbSUZrN/VK6j6NcQjDr3ycGHdoa4mNWv9pudT1tIJ/ljA9 aHmHmghrUSff1DgpP2Hgb9s2d8bA5KN7x+2rJsaQ9qQfvIMi9YdH1sRgUqHLI3cmDT5y smog== X-Gm-Message-State: AFeK/H3DovNjuKoJc+gjjuWZUeCJ75u8qXfaQYst1PkFpE95hhlC6rKtIiLDDTZ2W8Ysrgxo X-Received: by 10.223.171.71 with SMTP id r7mr22372573wrc.199.1491384217107; Wed, 05 Apr 2017 02:23:37 -0700 (PDT) Received: from localhost.localdomain ([160.163.145.113]) by smtp.gmail.com with ESMTPSA id b66sm23935271wrd.29.2017.04.05.02.23.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 02:23:36 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: matt@codeblueprint.co.uk, andy.shevchenko@gmail.com, pure.logic@nexus-software.ie, hock.leong.kweh@intel.com, bp@alien8.de, sascha.weisenberger@siemens.com, jan.kiszka@siemens.com, Ard Biesheuvel Subject: [PATCH 4/8] efi/capsule: Adjust return type of efi_capsule_setup_info Date: Wed, 5 Apr 2017 10:23:13 +0100 Message-Id: <20170405092317.27921-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170405092317.27921-1-ard.biesheuvel@linaro.org> References: <20170405092317.27921-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Jan Kiszka We actually expect int at the caller and never return any size information. Signed-off-by: Jan Kiszka Cc: Matt Fleming Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/capsule-loader.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Reviewed-by: Matt Fleming diff --git a/drivers/firmware/efi/capsule-loader.c b/drivers/firmware/efi/capsule-loader.c index 3fb91e1597a9..37d3f6ec2d28 100644 --- a/drivers/firmware/efi/capsule-loader.c +++ b/drivers/firmware/efi/capsule-loader.c @@ -53,8 +53,8 @@ static void efi_free_all_buff_pages(struct capsule_info *cap_info) * @kbuff: a mapped first page buffer pointer * @hdr_bytes: the total received number of bytes for efi header **/ -static ssize_t efi_capsule_setup_info(struct capsule_info *cap_info, - void *kbuff, size_t hdr_bytes) +static int efi_capsule_setup_info(struct capsule_info *cap_info, + void *kbuff, size_t hdr_bytes) { efi_capsule_header_t *cap_hdr; size_t pages_needed; From patchwork Wed Apr 5 09:23:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 96797 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp173422qgd; Wed, 5 Apr 2017 02:23:54 -0700 (PDT) X-Received: by 10.84.215.215 with SMTP id g23mr34565577plj.22.1491384234122; Wed, 05 Apr 2017 02:23:54 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1si20066378pfg.225.2017.04.05.02.23.54; Wed, 05 Apr 2017 02:23:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933139AbdDEJXr (ORCPT + 2 others); Wed, 5 Apr 2017 05:23:47 -0400 Received: from mail-wm0-f54.google.com ([74.125.82.54]:35048 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933040AbdDEJXq (ORCPT ); Wed, 5 Apr 2017 05:23:46 -0400 Received: by mail-wm0-f54.google.com with SMTP id y22so44950534wmh.0 for ; Wed, 05 Apr 2017 02:23:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=41Z7HHNoqjVKsdbK5l0tHwG7pugUTu9QTLNi0I9NT2s=; b=hziy6PgSn5RdvDnj4S4qvZSatOisWeubVCRtQyWLRQSTn3/FSBWS+fgPhuOc5xDxa1 WJ0tf9PSd6CcZaV5PqVGzBcB+++BhYjcCiWyhOe2BAODpsNyidsYqERBveJnQhsLmFHV LxzmqZQLtt2YVeUJnLZzTzN54aiiyvR28sxlw= 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=41Z7HHNoqjVKsdbK5l0tHwG7pugUTu9QTLNi0I9NT2s=; b=RHU1Un0FnysLDm5bxAjE3rSgGWC1lhIjJtDg/aOBu0f/Yx8HWsa8ylDrcRvbVCAiF2 KERjRMY/zVYfsF8dE6SUmsfqK8lqT9k2ce2dt7h2PCObISoudkJZWRf0jaTfUJH6nRls 2E9kL7d0NLzP8qrYSVsUG3sx31+FSH3mfNQT6cnIGOitdQTJLGb6OKXF30roUqwilCvj w22L0hIjWgLv3aopGB1fdZYMlUCGzBLAOlLSI4jyXn1pi+bCqpJzQ9DgDikWm/zXtZ11 J2zuYPq3sjTp99TCRqsDLwdV119IRX0zV5DkhcMfHm6R3L7WvzgPn+PpUO6AuUzN54I+ rsCA== X-Gm-Message-State: AFeK/H18+2shkphnEEnBSVAAX5+9srwYM/4LSoI7i6F6MgJ0p7gAlECn k3g48QPGAggkVsnI X-Received: by 10.28.142.133 with SMTP id q127mr8446053wmd.116.1491384219820; Wed, 05 Apr 2017 02:23:39 -0700 (PDT) Received: from localhost.localdomain ([160.163.145.113]) by smtp.gmail.com with ESMTPSA id b66sm23935271wrd.29.2017.04.05.02.23.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 02:23:38 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: matt@codeblueprint.co.uk, andy.shevchenko@gmail.com, pure.logic@nexus-software.ie, hock.leong.kweh@intel.com, bp@alien8.de, sascha.weisenberger@siemens.com, jan.kiszka@siemens.com, Ard Biesheuvel Subject: [PATCH 5/8] efi/capsule-loader: use cached copy of capsule header Date: Wed, 5 Apr 2017 10:23:14 +0100 Message-Id: <20170405092317.27921-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170405092317.27921-1-ard.biesheuvel@linaro.org> References: <20170405092317.27921-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Instead of kmapping the capsule data twice, copy the capsule header into the capsule info struct we keep locally. This is an improvement by itself, but will also enable handling of non-standard header formats more easily. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/capsule-loader.c | 41 ++++++++------------ 1 file changed, 17 insertions(+), 24 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Reviewed-by: Matt Fleming diff --git a/drivers/firmware/efi/capsule-loader.c b/drivers/firmware/efi/capsule-loader.c index 37d3f6ec2d28..5b012a467d7d 100644 --- a/drivers/firmware/efi/capsule-loader.c +++ b/drivers/firmware/efi/capsule-loader.c @@ -21,13 +21,13 @@ #define NO_FURTHER_WRITE_ACTION -1 struct capsule_info { - bool header_obtained; - int reset_type; - long index; - size_t count; - size_t total_size; - struct page **pages; - size_t page_bytes_remain; + efi_capsule_header_t header; + int reset_type; + long index; + size_t count; + size_t total_size; + struct page **pages; + size_t page_bytes_remain; }; /** @@ -56,7 +56,6 @@ static void efi_free_all_buff_pages(struct capsule_info *cap_info) static int efi_capsule_setup_info(struct capsule_info *cap_info, void *kbuff, size_t hdr_bytes) { - efi_capsule_header_t *cap_hdr; size_t pages_needed; int ret; void *temp_page; @@ -66,8 +65,9 @@ static int efi_capsule_setup_info(struct capsule_info *cap_info, return 0; /* Reset back to the correct offset of header */ - cap_hdr = kbuff - cap_info->count; - pages_needed = ALIGN(cap_hdr->imagesize, PAGE_SIZE) >> PAGE_SHIFT; + kbuff -= cap_info->count; + memcpy(&cap_info->header, kbuff, sizeof(cap_info->header)); + pages_needed = ALIGN(cap_info->header.imagesize, PAGE_SIZE) / PAGE_SIZE; if (pages_needed == 0) { pr_err("invalid capsule size"); @@ -75,15 +75,16 @@ static int efi_capsule_setup_info(struct capsule_info *cap_info, } /* Check if the capsule binary supported */ - ret = efi_capsule_supported(cap_hdr->guid, cap_hdr->flags, - cap_hdr->imagesize, + ret = efi_capsule_supported(cap_info->header.guid, + cap_info->header.flags, + cap_info->header.imagesize, &cap_info->reset_type); if (ret) { pr_err("capsule not supported\n"); return ret; } - cap_info->total_size = cap_hdr->imagesize; + cap_info->total_size = cap_info->header.imagesize; temp_page = krealloc(cap_info->pages, pages_needed * sizeof(void *), GFP_KERNEL | __GFP_ZERO); @@ -91,7 +92,6 @@ static int efi_capsule_setup_info(struct capsule_info *cap_info, return -ENOMEM; cap_info->pages = temp_page; - cap_info->header_obtained = true; return 0; } @@ -104,15 +104,8 @@ static int efi_capsule_setup_info(struct capsule_info *cap_info, static ssize_t efi_capsule_submit_update(struct capsule_info *cap_info) { int ret; - void *cap_hdr_temp; - cap_hdr_temp = vmap(cap_info->pages, cap_info->index, - VM_MAP, PAGE_KERNEL); - if (!cap_hdr_temp) - return -ENOMEM; - - ret = efi_capsule_update(cap_hdr_temp, cap_info->pages); - vunmap(cap_hdr_temp); + ret = efi_capsule_update(&cap_info->header, cap_info->pages); if (ret) { pr_err("capsule update failed\n"); return ret; @@ -192,7 +185,7 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff, cap_info->page_bytes_remain -= write_byte; /* Setup capsule binary info structure */ - if (!cap_info->header_obtained) { + if (cap_info->header.headersize == 0) { ret = efi_capsule_setup_info(cap_info, kbuff, cap_info->count + write_byte); if (ret) @@ -203,7 +196,7 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff, kunmap(page); /* Submit the full binary to efi_capsule_update() API */ - if (cap_info->header_obtained && + if (cap_info->header.headersize > 0 && cap_info->count >= cap_info->total_size) { if (cap_info->count > cap_info->total_size) { pr_err("capsule upload size exceeded header defined size\n"); From patchwork Wed Apr 5 09:23:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 96798 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp173423qgd; Wed, 5 Apr 2017 02:23:54 -0700 (PDT) X-Received: by 10.99.130.193 with SMTP id w184mr28054696pgd.157.1491384234285; Wed, 05 Apr 2017 02:23:54 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1si20066378pfg.225.2017.04.05.02.23.54; Wed, 05 Apr 2017 02:23:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933038AbdDEJXs (ORCPT + 2 others); Wed, 5 Apr 2017 05:23:48 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:37008 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932632AbdDEJXn (ORCPT ); Wed, 5 Apr 2017 05:23:43 -0400 Received: by mail-wm0-f47.google.com with SMTP id x124so8377086wmf.0 for ; Wed, 05 Apr 2017 02:23:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=alxxoFbPwvSxDrH1mzruD6c5Eas1tu9JSKFFxVouSNY=; b=Ze449Ktui7WWoAHwDv1hX5WF57qsG3yZ58vv2b0sNbpXr2cYrNoGSanqkL2hqMfwNR HWbbiMwoEejnwak2RHT2nTZo5EN8Xteu61HsdnLctmhSM5KBCKuYFsKWdoRj1/l0M3kK adNnKOmQ6nKhYOqjcUjGqWuUtG8E9nMeM7alA= 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=alxxoFbPwvSxDrH1mzruD6c5Eas1tu9JSKFFxVouSNY=; b=hXFl50OCIpw6SpGCb1kGamAlonYim9J21NE8ZNsgAGJsOojr0PPbyfRrN3uB6ykVIg xPMejUIhHFG9OKw0N8W6fKKGG4OH4HXRRCaYEyYpGd6uA6ENT5biBPShJuDNWvQUZJoq X3cmCvqZto/aagyqozPdLXFDgwQWuLPntV0u4tIDqpVNLFA8n0GE9Va9I/aNnnfBWhPN k8PyiBM8OXrc9WIEW9jxELaxP+klCP7r8AypGILeP1xrApTs8D2BRgQdrOuZYcvnj7ab zoxgQtutakxz8zFR24jmjSXXODCTctRzuNbXOU+Uc0lIOMqlJrPfNBdf31Xm/XS1GkzO nLbg== X-Gm-Message-State: AFeK/H1DiAWZDgxBA5FKgr11LdczMlIrD6dhoHiP/lWaOJxTGLMi5ohhh4n1ambhqNZPtTHH X-Received: by 10.28.14.138 with SMTP id 132mr12906568wmo.141.1491384222152; Wed, 05 Apr 2017 02:23:42 -0700 (PDT) Received: from localhost.localdomain ([160.163.145.113]) by smtp.gmail.com with ESMTPSA id b66sm23935271wrd.29.2017.04.05.02.23.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 02:23:41 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: matt@codeblueprint.co.uk, andy.shevchenko@gmail.com, pure.logic@nexus-software.ie, hock.leong.kweh@intel.com, bp@alien8.de, sascha.weisenberger@siemens.com, jan.kiszka@siemens.com, Ard Biesheuvel Subject: [PATCH 6/8] efi/capsule-loader: indirect calls to efi_capsule_setup_info via weak alias Date: Wed, 5 Apr 2017 10:23:15 +0100 Message-Id: <20170405092317.27921-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170405092317.27921-1-ard.biesheuvel@linaro.org> References: <20170405092317.27921-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org To allow platform specific code to hook into the capsule loading routines, indirect calls to efi_capsule_setup_info() via a weak alias of __efi_capsule_setup_info(), allowing platforms to redefine the former but still use the latter. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/capsule-loader.c | 52 +++++++++----------- include/linux/efi.h | 12 +++++ 2 files changed, 35 insertions(+), 29 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/firmware/efi/capsule-loader.c b/drivers/firmware/efi/capsule-loader.c index 5b012a467d7d..d68a1ecebbf3 100644 --- a/drivers/firmware/efi/capsule-loader.c +++ b/drivers/firmware/efi/capsule-loader.c @@ -20,16 +20,6 @@ #define NO_FURTHER_WRITE_ACTION -1 -struct capsule_info { - efi_capsule_header_t header; - int reset_type; - long index; - size_t count; - size_t total_size; - struct page **pages; - size_t page_bytes_remain; -}; - /** * efi_free_all_buff_pages - free all previous allocated buffer pages * @cap_info: pointer to current instance of capsule_info structure @@ -46,28 +36,13 @@ static void efi_free_all_buff_pages(struct capsule_info *cap_info) cap_info->index = NO_FURTHER_WRITE_ACTION; } -/** - * efi_capsule_setup_info - obtain the efi capsule header in the binary and - * setup capsule_info structure - * @cap_info: pointer to current instance of capsule_info structure - * @kbuff: a mapped first page buffer pointer - * @hdr_bytes: the total received number of bytes for efi header - **/ -static int efi_capsule_setup_info(struct capsule_info *cap_info, - void *kbuff, size_t hdr_bytes) +int __efi_capsule_setup_info(struct capsule_info *cap_info) { size_t pages_needed; int ret; void *temp_page; - /* Only process data block that is larger than efi header size */ - if (hdr_bytes < sizeof(efi_capsule_header_t)) - return 0; - - /* Reset back to the correct offset of header */ - kbuff -= cap_info->count; - memcpy(&cap_info->header, kbuff, sizeof(cap_info->header)); - pages_needed = ALIGN(cap_info->header.imagesize, PAGE_SIZE) / PAGE_SIZE; + pages_needed = ALIGN(cap_info->total_size, PAGE_SIZE) / PAGE_SIZE; if (pages_needed == 0) { pr_err("invalid capsule size"); @@ -84,7 +59,6 @@ static int efi_capsule_setup_info(struct capsule_info *cap_info, return ret; } - cap_info->total_size = cap_info->header.imagesize; temp_page = krealloc(cap_info->pages, pages_needed * sizeof(void *), GFP_KERNEL | __GFP_ZERO); @@ -97,6 +71,26 @@ static int efi_capsule_setup_info(struct capsule_info *cap_info, } /** + * efi_capsule_setup_info - obtain the efi capsule header in the binary and + * setup capsule_info structure + * @cap_info: pointer to current instance of capsule_info structure + * @kbuff: a mapped first page buffer pointer + * @hdr_bytes: the total received number of bytes for efi header + **/ +int __weak efi_capsule_setup_info(struct capsule_info *cap_info, void *kbuff, + size_t hdr_bytes) +{ + /* Only process data block that is larger than efi header size */ + if (hdr_bytes < sizeof(efi_capsule_header_t)) + return 0; + + memcpy(&cap_info->header, kbuff, sizeof(cap_info->header)); + cap_info->total_size = cap_info->header.imagesize; + + return __efi_capsule_setup_info(cap_info); +} + +/** * efi_capsule_submit_update - invoke the efi_capsule_update API once binary * upload done * @cap_info: pointer to current instance of capsule_info structure @@ -186,7 +180,7 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff, /* Setup capsule binary info structure */ if (cap_info->header.headersize == 0) { - ret = efi_capsule_setup_info(cap_info, kbuff, + ret = efi_capsule_setup_info(cap_info, kbuff - cap_info->count, cap_info->count + write_byte); if (ret) goto fail_unmap; diff --git a/include/linux/efi.h b/include/linux/efi.h index ec36f42a2add..a7379a2b5680 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -137,6 +137,18 @@ struct efi_boot_memmap { #define EFI_CAPSULE_POPULATE_SYSTEM_TABLE 0x00020000 #define EFI_CAPSULE_INITIATE_RESET 0x00040000 +struct capsule_info { + efi_capsule_header_t header; + int reset_type; + long index; + size_t count; + size_t total_size; + struct page **pages; + size_t page_bytes_remain; +}; + +int __efi_capsule_setup_info(struct capsule_info *cap_info); + /* * Allocation types for calls to boottime->allocate_pages. */ From patchwork Wed Apr 5 09:23:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 96800 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp173430qgd; Wed, 5 Apr 2017 02:23:55 -0700 (PDT) X-Received: by 10.99.8.67 with SMTP id 64mr24116068pgi.220.1491384234928; Wed, 05 Apr 2017 02:23:54 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1si20066378pfg.225.2017.04.05.02.23.54; Wed, 05 Apr 2017 02:23:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933040AbdDEJXw (ORCPT + 2 others); Wed, 5 Apr 2017 05:23:52 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:36411 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932632AbdDEJXv (ORCPT ); Wed, 5 Apr 2017 05:23:51 -0400 Received: by mail-wm0-f45.google.com with SMTP id o81so44877583wmb.1 for ; Wed, 05 Apr 2017 02:23:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PcBWA/TheR4stIpKETmYwQEFOH6xiIa2ojcOt7akqP0=; b=feSm6r85OMFST5L00+6CA/s6HSnGUSTBS6LLayw2BeSoa4unsO+RfeEpuYG68yMOgK vrdammg8+LmSNbVU6UutoP2XSts7nG5AZFkU7vrr6y57JgGqWWO8jUhNtxC5/9Ql/V7N 2cGvZXvwaJ+0sMddmbH+vCG7pkTkLrPcYMnjI= 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=PcBWA/TheR4stIpKETmYwQEFOH6xiIa2ojcOt7akqP0=; b=nN3CoFrCY41tSGZ6P+7828okt/fmzMNaVx/e81Kts0fJ77W3lVIxaWm0g0KYhAh62x qqK9aLdHQC5hceaA/eF2QBznkuBm63+zGcKUJJoWAAGkd9QGWvBV0SfZ0ulwBFF3XyF5 SilPKynR6wkwn7GS7FJUyaheHcCAe2hv03juL4qoq3V9UUnMHCEukjMZGVCfXy1HfFFw HJdzbOvdX27Zq+MpbUtSg5DRc7i8qyj2werx9YYQkTI6SMubwu4T0S+FTh5dvrCOpaOn WkOg9EMPzT+iYqRp5xpB4jH3DmyymBeG3LnxDp14sf6YQO6XBB1mXDBmToV82KEdc1wj FMqg== X-Gm-Message-State: AFeK/H0L2kh10BpSNHhlFXaaCYfVSNeR44U0ozYLXNP3bBVkwsQdK1mL Y1neuEQqLnNI7BgM X-Received: by 10.28.154.14 with SMTP id c14mr18180010wme.75.1491384224893; Wed, 05 Apr 2017 02:23:44 -0700 (PDT) Received: from localhost.localdomain ([160.163.145.113]) by smtp.gmail.com with ESMTPSA id b66sm23935271wrd.29.2017.04.05.02.23.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 02:23:44 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: matt@codeblueprint.co.uk, andy.shevchenko@gmail.com, pure.logic@nexus-software.ie, hock.leong.kweh@intel.com, bp@alien8.de, sascha.weisenberger@siemens.com, jan.kiszka@siemens.com, Ard Biesheuvel Subject: [PATCH 7/8] efi/capsule-loader: use page addresses rather than struct page pointers Date: Wed, 5 Apr 2017 10:23:16 +0100 Message-Id: <20170405092317.27921-8-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170405092317.27921-1-ard.biesheuvel@linaro.org> References: <20170405092317.27921-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org To give some leeway to code that handles non-standard capsule headers, let's keep an array of page addresses rather than struct page pointers. This gives special implementations of efi_capsule_setup_info() the opportunity to mangle the payload a bit before it is presented to the firmware, without putting any knowledge of the nature of such quirks into the generic code. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/capsule-loader.c | 12 ++++++++---- drivers/firmware/efi/capsule.c | 7 ++++--- include/linux/efi.h | 4 ++-- 3 files changed, 14 insertions(+), 9 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/firmware/efi/capsule-loader.c b/drivers/firmware/efi/capsule-loader.c index d68a1ecebbf3..22b2bb73176c 100644 --- a/drivers/firmware/efi/capsule-loader.c +++ b/drivers/firmware/efi/capsule-loader.c @@ -20,6 +20,10 @@ #define NO_FURTHER_WRITE_ACTION -1 +#ifndef phys_to_page +#define phys_to_page(x) virt_to_page((unsigned long)__va(x)) +#endif + /** * efi_free_all_buff_pages - free all previous allocated buffer pages * @cap_info: pointer to current instance of capsule_info structure @@ -31,7 +35,7 @@ static void efi_free_all_buff_pages(struct capsule_info *cap_info) { while (cap_info->index > 0) - __free_page(cap_info->pages[--cap_info->index]); + __free_page(phys_to_page(cap_info->pages[--cap_info->index])); cap_info->index = NO_FURTHER_WRITE_ACTION; } @@ -157,12 +161,12 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff, goto failed; } - cap_info->pages[cap_info->index++] = page; + cap_info->pages[cap_info->index++] = page_to_phys(page); cap_info->page_bytes_remain = PAGE_SIZE; + } else { + page = phys_to_page(cap_info->pages[cap_info->index - 1]); } - page = cap_info->pages[cap_info->index - 1]; - kbuff = kmap(page); if (!kbuff) { ret = -ENOMEM; diff --git a/drivers/firmware/efi/capsule.c b/drivers/firmware/efi/capsule.c index 6eedff45e6d7..57f85256feb2 100644 --- a/drivers/firmware/efi/capsule.c +++ b/drivers/firmware/efi/capsule.c @@ -214,7 +214,7 @@ efi_capsule_update_locked(efi_capsule_header_t *capsule, * * Return 0 on success, a converted EFI status code on failure. */ -int efi_capsule_update(efi_capsule_header_t *capsule, struct page **pages) +int efi_capsule_update(efi_capsule_header_t *capsule, phys_addr_t *pages) { u32 imagesize = capsule->imagesize; efi_guid_t guid = capsule->guid; @@ -253,10 +253,11 @@ int efi_capsule_update(efi_capsule_header_t *capsule, struct page **pages) } for (j = 0; j < SGLIST_PER_PAGE && count > 0; j++) { - u64 sz = min_t(u64, imagesize, PAGE_SIZE); + u64 sz = min_t(u64, imagesize, + PAGE_SIZE - (u64)*pages % PAGE_SIZE); sglist[j].length = sz; - sglist[j].data = page_to_phys(*pages++); + sglist[j].data = *pages++; imagesize -= sz; count--; diff --git a/include/linux/efi.h b/include/linux/efi.h index a7379a2b5680..8269bcb8ccf7 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -143,7 +143,7 @@ struct capsule_info { long index; size_t count; size_t total_size; - struct page **pages; + phys_addr_t *pages; size_t page_bytes_remain; }; @@ -1415,7 +1415,7 @@ extern int efi_capsule_supported(efi_guid_t guid, u32 flags, size_t size, int *reset); extern int efi_capsule_update(efi_capsule_header_t *capsule, - struct page **pages); + phys_addr_t *pages); #ifdef CONFIG_EFI_RUNTIME_MAP int efi_runtime_map_init(struct kobject *); From patchwork Wed Apr 5 09:23:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 96799 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp173428qgd; Wed, 5 Apr 2017 02:23:54 -0700 (PDT) X-Received: by 10.98.34.20 with SMTP id i20mr7623431pfi.102.1491384234748; Wed, 05 Apr 2017 02:23:54 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1si20066378pfg.225.2017.04.05.02.23.54; Wed, 05 Apr 2017 02:23:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933081AbdDEJXv (ORCPT + 2 others); Wed, 5 Apr 2017 05:23:51 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:38415 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933040AbdDEJXt (ORCPT ); Wed, 5 Apr 2017 05:23:49 -0400 Received: by mail-wm0-f48.google.com with SMTP id t189so8335605wmt.1 for ; Wed, 05 Apr 2017 02:23:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7yt6bt9/BLTB8jweuGJYuVeKq77EzRfl3nAPNwKW7KA=; b=RIKLyQ7pcFgRKkAJoicjmF2qas0/iSaTjYlJUzn28Ns6bWB2lTzuypTzwri5b3C25j +aMBJfXDYZ21KU1EiNfWAk6gngi46Ub6xjd7MdNLCQCkhQhfI2/RG3zeeVgSQmfMRva3 HTjieKs5sBn4ew1AgcgIzWf3BJptQ7j5Xf0OY= 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=7yt6bt9/BLTB8jweuGJYuVeKq77EzRfl3nAPNwKW7KA=; b=FUx89UYNAjDfc6Wgwa6XujkGx7MpbsaTWZ6A5rhrWMCG4J9OAQGa22sic/kRsO09r8 OPoPvMYuZki3za4PIjoqHYe1P7mk6XJNmBJ6nQVPFN2zAidAJ/V29mxYnJ5y7erdUSey bG1FFQMv75kuczxUVzQnhd+MMCrPmDssuwVGfKKMDBSOaNZi1FWCkbNCro4Ak/J2GUTV HIMjdNUqlk2/XXc/1hIdkuFusgrJiq9ZMCBbbQ2zZKXoIinlbzEWxv7OhaWmL70Xy01L shrkkBQYmzXq6LIPhuLVdWFgcgJjD7hN4f3J4AblNNsHkmW9lU5fx2vdoz9bvbq1sm1l OGmw== X-Gm-Message-State: AFeK/H1r5Cz8oYCFyHD9zTh7OuC/E56hosdFXtV9mseRdpB0a737SX2EAPUHyYvVob76noZq X-Received: by 10.28.103.84 with SMTP id b81mr18164751wmc.124.1491384227442; Wed, 05 Apr 2017 02:23:47 -0700 (PDT) Received: from localhost.localdomain ([160.163.145.113]) by smtp.gmail.com with ESMTPSA id b66sm23935271wrd.29.2017.04.05.02.23.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 02:23:46 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: matt@codeblueprint.co.uk, andy.shevchenko@gmail.com, pure.logic@nexus-software.ie, hock.leong.kweh@intel.com, bp@alien8.de, sascha.weisenberger@siemens.com, jan.kiszka@siemens.com, Ard Biesheuvel Subject: [PATCH 8/8] efi/capsule: Add support for Quark security header Date: Wed, 5 Apr 2017 10:23:17 +0100 Message-Id: <20170405092317.27921-9-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170405092317.27921-1-ard.biesheuvel@linaro.org> References: <20170405092317.27921-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Jan Kiszka The firmware for Quark X102x prepends a security header to the capsule which is needed to support the mandatory secure boot on this processor. The header can be detected by checking for the "_CSH" signature and - to avoid any GUID conflict - validating its size field to contain the expected value. Then we need to look for the EFI header right after the security header and pass the real header to __efi_capsule_setup_info. To be minimally invasive and maximally safe, the quirk version of efi_capsule_identify_image is only effective on Quark processors. Signed-off-by: Jan Kiszka Cc: Matt Fleming [ardb: refactor using an override of efi_capsule_setup_info()] Signed-off-by: Ard Biesheuvel --- arch/x86/platform/efi/quirks.c | 112 ++++++++++++++++++++ drivers/firmware/efi/Kconfig | 9 ++ 2 files changed, 121 insertions(+) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c index 30031d5293c4..ee922e1b7008 100644 --- a/arch/x86/platform/efi/quirks.c +++ b/arch/x86/platform/efi/quirks.c @@ -13,12 +13,66 @@ #include #include #include +#include #define EFI_MIN_RESERVE 5120 #define EFI_DUMMY_GUID \ EFI_GUID(0x4424ac57, 0xbe4b, 0x47dd, 0x9e, 0x97, 0xed, 0x50, 0xf0, 0x9f, 0x92, 0xa9) +#define QUARK_CSH_SIGNATURE 0x5f435348 /* _CSH */ +#define QUARK_SECURITY_HEADER_SIZE 0x400 + +/* + * Header prepended to the standard EFI capsule on Quark systems the are based + * on Intel firmware BSP. + * @csh_signature: Unique identifier to sanity check signed module + * presence ("_CSH"). + * @version: Current version of CSH used. Should be one for Quark A0. + * @modulesize: Size of the entire module including the module header + * and payload. + * @security_version_number_index: Index of SVN to use for validation of signed + * module. + * @security_version_number: Used to prevent against roll back of modules. + * @rsvd_module_id: Currently unused for Clanton (Quark). + * @rsvd_module_vendor: Vendor Identifier. For Intel products value is + * 0x00008086. + * @rsvd_date: BCD representation of build date as yyyymmdd, where + * yyyy=4 digit year, mm=1-12, dd=1-31. + * @headersize: Total length of the header including including any + * padding optionally added by the signing tool. + * @hash_algo: What Hash is used in the module signing. + * @cryp_algo: What Crypto is used in the module signing. + * @keysize: Total length of the key data including including any + * padding optionally added by the signing tool. + * @signaturesize: Total length of the signature including including any + * padding optionally added by the signing tool. + * @rsvd_next_header: 32-bit pointer to the next Secure Boot Module in the + * chain, if there is a next header. + * @rsvd: Reserved, padding structure to required size. + * + * See also QuartSecurityHeader_t in + * Quark_EDKII_v1.2.1.1/QuarkPlatformPkg/Include/QuarkBootRom.h + * from https://downloadcenter.intel.com/download/23197/Intel-Quark-SoC-X1000-Board-Support-Package-BSP + */ +struct quark_security_header { + u32 csh_signature; + u32 version; + u32 modulesize; + u32 security_version_number_index; + u32 security_version_number; + u32 rsvd_module_id; + u32 rsvd_module_vendor; + u32 rsvd_date; + u32 headersize; + u32 hash_algo; + u32 cryp_algo; + u32 keysize; + u32 signaturesize; + u32 rsvd_next_header; + u32 rsvd[2]; +}; + static efi_char16_t efi_dummy_name[6] = { 'D', 'U', 'M', 'M', 'Y', 0 }; static bool efi_no_storage_paranoia; @@ -495,3 +549,61 @@ bool efi_poweroff_required(void) { return acpi_gbl_reduced_hardware || acpi_no_s5; } + +#ifdef CONFIG_EFI_CAPSULE_QUIRK_QUARK_CSH + +static const struct x86_cpu_id quark_ids[] = { + { X86_VENDOR_INTEL, 5, 9 }, /* Intel Quark X1000 */ + { } +}; + +int efi_capsule_setup_info(struct capsule_info *cap_info, void *kbuff, + size_t hdr_bytes) +{ + struct quark_security_header *csh = kbuff; + + cap_info->total_size = 0; + + if (!x86_match_cpu(quark_ids)) + goto fallback; + + /* Only process data block that is larger than the security header */ + if (hdr_bytes < sizeof(struct quark_security_header)) + return 0; + + if (csh->csh_signature != QUARK_CSH_SIGNATURE || + csh->headersize != QUARK_SECURITY_HEADER_SIZE) + goto fallback; + + /* Only process data block if EFI header is included */ + if (hdr_bytes < QUARK_SECURITY_HEADER_SIZE + + sizeof(efi_capsule_header_t)) + return 0; + + pr_debug("Quark security header detected\n"); + + if (csh->rsvd_next_header != 0) { + pr_err("multiple Quark security headers not supported\n"); + return -EINVAL; + } + + kbuff += csh->headersize; + cap_info->total_size = csh->headersize; + + /* + * Update the first page pointer to skip over the CSH header. + */ + cap_info->pages[0] += csh->headersize; + +fallback: + if (hdr_bytes < sizeof(efi_capsule_header_t)) + return 0; + + memcpy(&cap_info->header, kbuff, sizeof(cap_info->header)); + + cap_info->total_size += cap_info->header.imagesize; + + return __efi_capsule_setup_info(cap_info); +} + +#endif diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig index 2e78b0b96d74..394db40ed374 100644 --- a/drivers/firmware/efi/Kconfig +++ b/drivers/firmware/efi/Kconfig @@ -112,6 +112,15 @@ config EFI_CAPSULE_LOADER Most users should say N. +config EFI_CAPSULE_QUIRK_QUARK_CSH + boolean "Add support for Quark capsules with non-standard headers" + depends on X86 && !64BIT + select EFI_CAPSULE_LOADER + default y + help + Add support for processing Quark X1000 EFI capsules, whose header + layout deviates from the layout mandated by the UEFI specification. + config EFI_TEST tristate "EFI Runtime Service Tests Support" depends on EFI