From patchwork Mon Sep 27 15:56:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitri John Ledkov X-Patchwork-Id: 1533429 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=TRloCk/P; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HJ6jN46fNz9tkM for ; Tue, 28 Sep 2021 01:57:44 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1mUt0W-0006go-4V; Mon, 27 Sep 2021 15:57:32 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1mUt0R-0006gD-Vb for kernel-team@lists.ubuntu.com; Mon, 27 Sep 2021 15:57:27 +0000 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id CAA984019D for ; Mon, 27 Sep 2021 15:57:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1632758247; bh=87ZtbWA/i3Tb/5qUY90mB8Iw2BPx6+MY2FflxE+XRt0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TRloCk/PVtIHnwG0cK5b8XlcELB2Fmt1CCU26Az8A+KBpbby0Df5K4bW6C1t59gol 3XvUgtbJSt8REZZ3nsQjLc4MpwDwIlXMf6HLPAVyKPz9iRau9f9CrMsJiCoa/jO7pM wkgedS9stcTjK1ImXNL3v5ZF4PHOeNmSNVF/pPvyD/g+QE5cwhV5XXmcUqzDosTPat 8Dwea9vI1g9De6k8kcfV0f0rUe+ZeTxbOyb4nok/bUMOXVrNih5/ywtvbikcpYvujf OlIqf4gAi8+we+o1LreUY+VbTPIaWZGirvt9uK6j7xY10Ke4nQWUfQLbCqDz8vDTxq Z51L23iSSEjVw== Received: by mail-wm1-f70.google.com with SMTP id v5-20020a1cac05000000b0030b85d2d479so425020wme.9 for ; Mon, 27 Sep 2021 08:57:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=87ZtbWA/i3Tb/5qUY90mB8Iw2BPx6+MY2FflxE+XRt0=; b=HS0Ox/oBQJ2DgPBuXxclms8TEGacj8u+2suS3ZSsJJvXjTgEAvuUOBYoLh7Rytz73n LD2m3M9+oFoYW9xu/mCRW8MwOfuik9vpK+3EPEF2gQqcMxu9Mk+Dhb6NO8zgUAFvljaA QVB2p/Y7hRX+A7EHvFD4nYLwI8iwS2PCa1qgh0dgF7pSbZsnkN6hfYZtS92jzCJ9RxAT 0SCYshNAWyDN4uLPqem4iA8vicMl30uK0KXik4anMyF3NxSuiQ/KTqcUqsv1OP0NPuHW /WM7aJRYd406Cq2WA539KQnAv5ETAPeDYi7p3STbOdGZjqUKtMLv0NHLTYVtXi4GiNAW PrmQ== X-Gm-Message-State: AOAM530wEQ1LvNMwrDvVCYLp3ZgKOvGs8i73FWzZaYSSslPPXLNvuMAh chwarWKejh4oZHScJKD6hbpqnvVooT0nuYQk752iQFz9Px2ftD0K+7KolOn7sagpHJlkQfCV75o wHIOoJN5I74rSTRsEEop1alwngij7smt6JfdcRN8Bug== X-Received: by 2002:a5d:5748:: with SMTP id q8mr673025wrw.384.1632758247106; Mon, 27 Sep 2021 08:57:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyujGo4jJJj1E5n7dQcbOIrJrW2lMJ8oUvDW7OVhtApwNu1cLUCxOWV/k38WJlE4FKsMpknDA== X-Received: by 2002:a5d:5748:: with SMTP id q8mr673012wrw.384.1632758246915; Mon, 27 Sep 2021 08:57:26 -0700 (PDT) Received: from localhost ([2a01:4b00:85fd:d700:86ad:7d9c:de94:eed0]) by smtp.gmail.com with ESMTPSA id 61sm17139189wrl.94.2021.09.27.08.57.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 08:57:26 -0700 (PDT) From: Dimitri John Ledkov To: kernel-team@lists.ubuntu.com Subject: [SRU][F/hwe-5.8][PATCH 03/18] efi: mokvar-table: fix some issues in new code Date: Mon, 27 Sep 2021 16:56:57 +0100 Message-Id: <20210927155712.164337-4-dimitri.ledkov@canonical.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210927155712.164337-1-dimitri.ledkov@canonical.com> References: <20210927155712.164337-1-dimitri.ledkov@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lenny Szubowicz , Arvind Sankar , Borislav Petkov , Ard Biesheuvel Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Ard Biesheuvel BugLink: https://bugs.launchpad.net/bugs/1928679 Fix a couple of issues in the new mokvar-table handling code, as pointed out by Arvind and Boris: - don't bother checking the end of the physical region against the start address of the mokvar table, - ensure that we enter the loop with err = -EINVAL, - replace size_t with unsigned long to appease pedantic type equality checks. Reviewed-by: Arvind Sankar Reviewed-by: Lenny Szubowicz Tested-by: Borislav Petkov Signed-off-by: Ard Biesheuvel (cherry picked from commit b89114cd018cffa5deb7def1844ce1891efd4f96) Signed-off-by: Dimitri John Ledkov --- drivers/firmware/efi/mokvar-table.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/firmware/efi/mokvar-table.c b/drivers/firmware/efi/mokvar-table.c index b1cd49893d..72a9e1736f 100644 --- a/drivers/firmware/efi/mokvar-table.c +++ b/drivers/firmware/efi/mokvar-table.c @@ -98,15 +98,14 @@ static struct kobject *mokvar_kobj; void __init efi_mokvar_table_init(void) { efi_memory_desc_t md; - u64 end_pa; void *va = NULL; - size_t cur_offset = 0; - size_t offset_limit; - size_t map_size = 0; - size_t map_size_needed = 0; - size_t size; + unsigned long cur_offset = 0; + unsigned long offset_limit; + unsigned long map_size = 0; + unsigned long map_size_needed = 0; + unsigned long size; struct efi_mokvar_table_entry *mokvar_entry; - int err = -EINVAL; + int err; if (!efi_enabled(EFI_MEMMAP)) return; @@ -122,18 +121,16 @@ void __init efi_mokvar_table_init(void) pr_warn("EFI MOKvar config table is not within the EFI memory map\n"); return; } - end_pa = efi_mem_desc_end(&md); - if (efi.mokvar_table >= end_pa) { - pr_err("EFI memory descriptor containing MOKvar config table is invalid\n"); - return; - } - offset_limit = end_pa - efi.mokvar_table; + + offset_limit = efi_mem_desc_end(&md) - efi.mokvar_table; + /* * Validate the MOK config table. Since there is no table header * from which we could get the total size of the MOK config table, * we compute the total size as we validate each variably sized * entry, remapping as necessary. */ + err = -EINVAL; while (cur_offset + sizeof(*mokvar_entry) <= offset_limit) { mokvar_entry = va + cur_offset; map_size_needed = cur_offset + sizeof(*mokvar_entry); @@ -150,7 +147,7 @@ void __init efi_mokvar_table_init(void) offset_limit); va = early_memremap(efi.mokvar_table, map_size); if (!va) { - pr_err("Failed to map EFI MOKvar config table pa=0x%lx, size=%zu.\n", + pr_err("Failed to map EFI MOKvar config table pa=0x%lx, size=%lu.\n", efi.mokvar_table, map_size); return; }