From patchwork Fri Oct 1 15:44:19 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: 1535384 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=Q80Z9C+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 4HLZDx5849z9t0T for ; Sat, 2 Oct 2021 01:45:05 +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 1mWKiX-0007zf-S8; Fri, 01 Oct 2021 15:44:57 +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 1mWKiU-0007xn-5d for kernel-team@lists.ubuntu.com; Fri, 01 Oct 2021 15:44:54 +0000 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (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 04665402C9 for ; Fri, 1 Oct 2021 15:44:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1633103094; bh=87ZtbWA/i3Tb/5qUY90mB8Iw2BPx6+MY2FflxE+XRt0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q80Z9C+pfR/2+PeekQDm41bPpcMWpdRXwa4sVmAjK7vkXc0Wb6G6WfDxQXLtXvu5M 23ylcjv78v7C9NJQXv143n+TWRP+TM3KLU1HFS5g+VOCpeqCu9MnWTg71tiW3gN1i1 AqtSxyTLiCg01uwjuWsHhUwrwFJI1SBxOq2Q0aHG8r2m6UIJ+VbUNKaXgXN6A+EFy6 A4n8IBI63f1evMi4mWSStoA1Fi2GQ3uAOsvy8dVpVUc74H6gs6BggMb5MTDoybU8X0 JOCTat+yD2lGMcLlStBCZWB1ELunmfzeS8Pu3H14+P1+2nEX5hBTRcXwjL5TAvJ6lc N3LuQlbMGpqgg== Received: by mail-wm1-f72.google.com with SMTP id 129-20020a1c1987000000b0030cd1616fbfso6135380wmz.3 for ; Fri, 01 Oct 2021 08:44:54 -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:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=87ZtbWA/i3Tb/5qUY90mB8Iw2BPx6+MY2FflxE+XRt0=; b=2ZRtJ6j3G1hB1JZJU5fBpQtapBeUMxbMmcPkfPXPqCCE2a6RPybV/DJ5cKLCujfx42 CCylbkUvGZBVmkobdjaBqHNywijEMc4QjFWFBWByiNmyZiAdOeod/pVFch655BjkDGmp TOc8EtEwOW/JC4IwWJc27SAlK86ykQxZY34bD3Ve6HHHcKyJp4f8rS81uWbIbxbLY5Gh BAo1anyLBJP4RtkJbc4aOZ556/Oq+lv/Q6t+eBXHlf6sc2CkWEp23KGtkP77q/dHO6Wy KgrdwNUURSDy6moqEdJ8pO4AP+vX72gB5oPDQ6IKq7U/2hMLK4QvU8an7mZakJ/+wsPm CmAw== X-Gm-Message-State: AOAM532KH4BKOJrkX0mCBdYXZC4CVVVljTcug+477zIuQdWBVai5YhUd ld6Pc9HteUhr7LAyzEgnWSZY/41+h7cbizSi5wxMTyG5ERHAqVaVLmracxszSU5lvcdw2aDJxbJ +Ky5p/oo9KLwUo/AY+Khjkoz/LCJtZhDgOCkAgiXXfA== X-Received: by 2002:a1c:a942:: with SMTP id s63mr5301465wme.45.1633103093482; Fri, 01 Oct 2021 08:44:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7yBXlpvf5frkXgnfjo0Cav8XJu1ZZ6F+9Xza+FZ5ee7B1VzrBrRW8v/P579GhbsCkbeAivA== X-Received: by 2002:a1c:a942:: with SMTP id s63mr5301439wme.45.1633103093207; Fri, 01 Oct 2021 08:44:53 -0700 (PDT) Received: from localhost ([2a01:4b00:85fd:d700:dd38:5596:506f:f213]) by smtp.gmail.com with ESMTPSA id g2sm6378797wrb.20.2021.10.01.08.44.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 08:44:52 -0700 (PDT) From: Dimitri John Ledkov To: kernel-team@lists.ubuntu.com Subject: [SRU][FOCAL][PATCH 03/16] efi: mokvar-table: fix some issues in new code Date: Fri, 1 Oct 2021 16:44:19 +0100 Message-Id: <20211001154432.20287-4-dimitri.ledkov@canonical.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211001154432.20287-1-dimitri.ledkov@canonical.com> References: <20211001154432.20287-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: , 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; }