From patchwork Sat May 25 11:25:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 165175 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp4724820ili; Sat, 25 May 2019 04:26:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzsq8FWFIoLviwn9UzRv9roT2fntn/rIPwiww/UfkvoWblHD7WVrJkfjhY8bRm9xAOMeY8x X-Received: by 2002:a17:90a:ba96:: with SMTP id t22mr15384241pjr.143.1558783568899; Sat, 25 May 2019 04:26:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558783568; cv=none; d=google.com; s=arc-20160816; b=Z0t8Cn2V3E7An5YcaSWXzc/lPAmeWg0aeOOmXoWyrg2SN8yuXugPwMz53BJDhgkt1O M3qbwFbTzMprAUaCH3ELapYbYtbyA+Mx91tK9eAnj0Vdvo22XRf3xxMjsG4KQAHUvnMK RuHQUIBUnyzrR6hSk1P34gqkt7QgbJ054MnSJKrNFNk2c2Aym8SF56wDlTRg3th+x9nD XRJq1lvateUg6d7kvQPqyYbXQqq/aAY+AHwQl5M5pULiTmBPPKWKO+BW9iCP+9iJe7U9 RMRFLkY9DSaavat+FZvm/joDycoPtQiHsZUrDed5rOsb586zbUYLfH5iUWI/+Aro/Ig/ qUHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eqkbz42r/JkXQTE9JdHM5dm2nu1g0Kj971dkCS8AvjE=; b=cBYR6JSEEhkSPI5z4D/EQ8wd1B7w+puGQ1UjOgvdvaQukdFtuEdNJFuyV4uy/h49/m 7SgyohvjrGS6YwqoUTR/NT6/bMR0hSsiMNmUtTzRYdrY2Xy79ixcylkKl1RGjpRB1w6t yTPGE2fY98rhT1PpAw+4MWwSCc19hn956goVFlD58gWKOf979vlaa+H1uajMA2Q0vULJ scXDAUpMxOKi+aGwOyCWtomNHySpwfSa9+dTSPZsdk4poydFsuecXf0PkcHt7BLCQOdb olce0qyu1thskhWFtD2B64q8FC2191ozlpbKv4D9yEy0SVudjMiGZqisKGD8pwV4cVRc 8A4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gqFR2hJe; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7si843280pll.254.2019.05.25.04.26.08; Sat, 25 May 2019 04:26:08 -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=@linaro.org header.s=google header.b=gqFR2hJe; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726818AbfEYL0H (ORCPT + 30 others); Sat, 25 May 2019 07:26:07 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:42847 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726646AbfEYL0G (ORCPT ); Sat, 25 May 2019 07:26:06 -0400 Received: by mail-wr1-f68.google.com with SMTP id l2so12364781wrb.9 for ; Sat, 25 May 2019 04:26:05 -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 :mime-version:content-transfer-encoding; bh=eqkbz42r/JkXQTE9JdHM5dm2nu1g0Kj971dkCS8AvjE=; b=gqFR2hJeFw3u2HpUwckkEXBS3nmH3rAd5ohGNgyItfKUneMiagkz0GCf+6di8LXz1k n/Mq3Vy9WDy8tApfAEICrVbZM1TOi/M692RmO0NyXNl5lFy2ZffOXXUQvKFKJzuQIdCK LmWAgBVdc8aRM8ACeRHdIRClURjrj3Y55+7Bw4EXv1xTU3fc5Fa5otRHRPEOn0Cr0VZm PV2hDTJuwE+n6eW9XcKNciAfa6kac2I9V5LR2/dgVAVqLK+3l11y0lKz/BSNoxTHIg84 z6Jz43oR45LWnNrbbn/pbaL6BSC6tp8Mpii3mTTgMXWvCMKOTA7YidujFD7vdA599zW2 yWKg== 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:mime-version:content-transfer-encoding; bh=eqkbz42r/JkXQTE9JdHM5dm2nu1g0Kj971dkCS8AvjE=; b=lFXorwsOuK8xlFf/55iK8wrQA++Sa1har4CtsgxglPVisNQXWl3vEIKsUxjprVdK8T pRBvViuJajyXAgV2pst6jFbpjw3fG9xDS4QAS/ljVEm7wAoM+y/6G/FIbvi0yhGjPZvD hIgFqZaSQs8V3IT6ZoDtKWgI6fw2bBexqisvsesrebj75TUZVPScXN9YtsQmx3isIabZ 44Gs4eRTnZkd8w7GdQFbcKuW41DYp5fRNXYV9kBFIRGKlFHmFOh0MnMHvACfQmzz++fL 3nLnhbnWLbdqqrmlQ2MxO+S3xmxS0dNL8lgdfL5iC6x75Hg3sk8kLOHpWBNkqkux+hfc ZLEw== X-Gm-Message-State: APjAAAXICKEEeZ9tnMYzSvMSDL1JA1ES7v6oS4sGO59iqpDdLu3DxgBd UR6u+8yM2/2YZDT1vPvJAVDD+xUIdjpZNQ== X-Received: by 2002:adf:bc94:: with SMTP id g20mr14398118wrh.206.1558783564787; Sat, 25 May 2019 04:26:04 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:3ccc:7074:9336:6a6e]) by smtp.gmail.com with ESMTPSA id y16sm4942010wru.28.2019.05.25.04.26.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 May 2019 04:26:04 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Gen Zhang , Rob Bradford Subject: [PATCH 1/2] efi/x86: Add missing error handling to old_memmap 1:1 mapping code Date: Sat, 25 May 2019 13:25:58 +0200 Message-Id: <20190525112559.7917-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190525112559.7917-1-ard.biesheuvel@linaro.org> References: <20190525112559.7917-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gen Zhang The old_memmap flow in efi_call_phys_prolog() performs numerous memory allocations, and either does not check for failure at all, or it does but fails to propagate it back to the caller, which may end up calling into the firmware with an incomplete 1:1 mapping. So let's fix this by returning NULL from efi_call_phys_prolog() on memory allocation failures only, and by handling this condition in the caller. Also, clean up any half baked sets of page tables that we may have created before returning with a NULL return value. Note that any failure at this level will trigger a panic() two levels up, so none of this makes a huge difference, but it is a nice cleanup nonetheless. Signed-off-by: Gen Zhang [ardb: update commit log, add efi_call_phys_epilog() call on error path] Signed-off-by: Ard Biesheuvel --- arch/x86/platform/efi/efi.c | 2 ++ arch/x86/platform/efi/efi_64.c | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) -- 2.20.1 diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index e1cb01a22fa8..a7189a3b4d70 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -85,6 +85,8 @@ static efi_status_t __init phys_efi_set_virtual_address_map( pgd_t *save_pgd; save_pgd = efi_call_phys_prolog(); + if (!save_pgd) + return EFI_ABORTED; /* Disable interrupts around EFI calls: */ local_irq_save(flags); diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index cf0347f61b21..08ce8177c3af 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -84,13 +84,15 @@ pgd_t * __init efi_call_phys_prolog(void) if (!efi_enabled(EFI_OLD_MEMMAP)) { efi_switch_mm(&efi_mm); - return NULL; + return efi_mm.pgd; } early_code_mapping_set_exec(1); n_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT), PGDIR_SIZE); save_pgd = kmalloc_array(n_pgds, sizeof(*save_pgd), GFP_KERNEL); + if (!save_pgd) + return NULL; /* * Build 1:1 identity mapping for efi=old_map usage. Note that @@ -138,10 +140,11 @@ pgd_t * __init efi_call_phys_prolog(void) pgd_offset_k(pgd * PGDIR_SIZE)->pgd &= ~_PAGE_NX; } -out: __flush_tlb_all(); - return save_pgd; +out: + efi_call_phys_epilog(save_pgd); + return NULL; } void __init efi_call_phys_epilog(pgd_t *save_pgd)