Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1592367imm; Wed, 8 Aug 2018 21:33:02 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyZnLdGgRK7f8q+NGrBtk8JYlB1d8ndbdofriJntCkkiQA/zywlwbHFqxBq767KQENgmZsI X-Received: by 2002:a63:6441:: with SMTP id y62-v6mr544100pgb.240.1533789182365; Wed, 08 Aug 2018 21:33:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533789182; cv=none; d=google.com; s=arc-20160816; b=mPYhQnQy0rLYm5cKxUdoPx5B9rBkDMfaryxlC+6HUA/thmigyXqlg1e3AR/WG0rFDQ jt1NW7ETfhjowy0qhZiOFD0wu/bvY0A1LtmTT8Yx3FJS+vO7UbtIkw42mwmmwNbuMGrP G1y6y6WYdk5MQ19iZNZ45Ie4TBWvxuSaRxDQemcbdCQPfBfXuXGUJyDMy6Psrc3HZNCw 18CMCer5ArrfwLof9sBFBs8gVhgv94m60Wu4vH5vKLMreqO9x1y9n+aOuQkvY2HbEfsp Hk/EkxQzJEMTPcgpwXFpvooDC/YR7YCFuVcvyVtQsRykaQx4YpXIVc5vrhlXMyhn0nWA iiQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=7CfAsvk6NBqTRVdkgsWFzXYB5nvI5J7hEz0wZ3tfQks=; b=nPY2nK8aAAurtiYaabaxGVXediV7SovqjtzCTQ/RtzAjg0MSv16MiIcEs4H70oPrSO ucU5RDI1NkB4uQEb1s4rJqG6XuzBG/hoRNPMD+uwKnVYRCcUlmZKBBlx2Gj5DGzORc2g AdZdzcrWjDmXYLMLIyDnQ83Ln5KtM1YW6IDIPwSFYSTAx3hTrHM6nnNWnY8fD7B0ByKb NgjG05kUN41k+7SUY+XvIgGVVqfhTFIAmforZ5wBFpiZuKTBAEHlMQ5BRCmIGlzAgFb2 rNNqNafPhRCsZ2jtV6eFPmTtCpNuGdsZuOXEyIIxF4oVg58iQKLdz4Xtv2kwPUoEwsRF xk8w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d9-v6si5052784pgo.470.2018.08.08.21.32.48; Wed, 08 Aug 2018 21:33:02 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728175AbeHIGym (ORCPT + 99 others); Thu, 9 Aug 2018 02:54:42 -0400 Received: from mga01.intel.com ([192.55.52.88]:44990 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727211AbeHIGym (ORCPT ); Thu, 9 Aug 2018 02:54:42 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Aug 2018 21:31:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,213,1531810800"; d="scan'208";a="61024018" Received: from sai-dev-mach.sc.intel.com ([143.183.140.52]) by fmsmga007.fm.intel.com with ESMTP; 08 Aug 2018 21:31:51 -0700 From: Sai Praneeth Prakhya To: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ricardo.ner@intel.com, matt@codeblueprint.co.uk, Sai Praneeth , Lee Chun-Yi , Al Stone , Borislav Petkov , Ingo Molnar , Andy Lutomirski , Bhupesh Sharma , Peter Zijlstra , Ard Biesheuvel Subject: [PATCH V1 1/6] efi: Make efi_rts_work accessible to efi page fault handler Date: Wed, 8 Aug 2018 21:31:12 -0700 Message-Id: <1533789077-16156-2-git-send-email-sai.praneeth.prakhya@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1533789077-16156-1-git-send-email-sai.praneeth.prakhya@intel.com> References: <1533789077-16156-1-git-send-email-sai.praneeth.prakhya@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sai Praneeth If the firmware illegally accesses any efi regions other than EFI_BOOT_SERVICES_, the efi page fault handler would freeze efi_rts_wq and schedules a new process. To do this, the efi page fault handler needs efi_rts_work. Hence, make it accessible. There will be no race conditions in accessing this structure, because, all the calls to efi runtime services are already serialized. Suggested-by: Matt Fleming Based-on-code-from: Ricardo Neri Signed-off-by: Sai Praneeth Prakhya Cc: Lee Chun-Yi Cc: Al Stone Cc: Borislav Petkov Cc: Ingo Molnar Cc: Andy Lutomirski Cc: Bhupesh Sharma Cc: Peter Zijlstra Cc: Ard Biesheuvel --- drivers/firmware/efi/runtime-wrappers.c | 53 ++++++--------------------------- include/linux/efi.h | 36 ++++++++++++++++++++++ 2 files changed, 45 insertions(+), 44 deletions(-) diff --git a/drivers/firmware/efi/runtime-wrappers.c b/drivers/firmware/efi/runtime-wrappers.c index aa66cbf23512..b18b2d864c2c 100644 --- a/drivers/firmware/efi/runtime-wrappers.c +++ b/drivers/firmware/efi/runtime-wrappers.c @@ -45,39 +45,7 @@ #define __efi_call_virt(f, args...) \ __efi_call_virt_pointer(efi.systab->runtime, f, args) -/* efi_runtime_service() function identifiers */ -enum efi_rts_ids { - GET_TIME, - SET_TIME, - GET_WAKEUP_TIME, - SET_WAKEUP_TIME, - GET_VARIABLE, - GET_NEXT_VARIABLE, - SET_VARIABLE, - QUERY_VARIABLE_INFO, - GET_NEXT_HIGH_MONO_COUNT, - UPDATE_CAPSULE, - QUERY_CAPSULE_CAPS, -}; - -/* - * efi_runtime_work: Details of EFI Runtime Service work - * @arg<1-5>: EFI Runtime Service function arguments - * @status: Status of executing EFI Runtime Service - * @efi_rts_id: EFI Runtime Service function identifier - * @efi_rts_comp: Struct used for handling completions - */ -struct efi_runtime_work { - void *arg1; - void *arg2; - void *arg3; - void *arg4; - void *arg5; - efi_status_t status; - struct work_struct work; - enum efi_rts_ids efi_rts_id; - struct completion efi_rts_comp; -}; +struct efi_runtime_work efi_rts_work; /* * efi_queue_work: Queue efi_runtime_service() and wait until it's done @@ -91,7 +59,6 @@ struct efi_runtime_work { */ #define efi_queue_work(_rts, _arg1, _arg2, _arg3, _arg4, _arg5) \ ({ \ - struct efi_runtime_work efi_rts_work; \ efi_rts_work.status = EFI_ABORTED; \ \ init_completion(&efi_rts_work.efi_rts_comp); \ @@ -184,18 +151,16 @@ static DEFINE_SEMAPHORE(efi_runtime_lock); */ static void efi_call_rts(struct work_struct *work) { - struct efi_runtime_work *efi_rts_work; void *arg1, *arg2, *arg3, *arg4, *arg5; efi_status_t status = EFI_NOT_FOUND; - efi_rts_work = container_of(work, struct efi_runtime_work, work); - arg1 = efi_rts_work->arg1; - arg2 = efi_rts_work->arg2; - arg3 = efi_rts_work->arg3; - arg4 = efi_rts_work->arg4; - arg5 = efi_rts_work->arg5; + arg1 = efi_rts_work.arg1; + arg2 = efi_rts_work.arg2; + arg3 = efi_rts_work.arg3; + arg4 = efi_rts_work.arg4; + arg5 = efi_rts_work.arg5; - switch (efi_rts_work->efi_rts_id) { + switch (efi_rts_work.efi_rts_id) { case GET_TIME: status = efi_call_virt(get_time, (efi_time_t *)arg1, (efi_time_cap_t *)arg2); @@ -253,8 +218,8 @@ static void efi_call_rts(struct work_struct *work) */ pr_err("Requested executing invalid EFI Runtime Service.\n"); } - efi_rts_work->status = status; - complete(&efi_rts_work->efi_rts_comp); + efi_rts_work.status = status; + complete(&efi_rts_work.efi_rts_comp); } static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc) diff --git a/include/linux/efi.h b/include/linux/efi.h index 401e4b254e30..855992b15269 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1659,7 +1659,43 @@ struct linux_efi_tpm_eventlog { extern int efi_tpm_eventlog_init(void); +/* efi_runtime_service() function identifiers */ +enum efi_rts_ids { + GET_TIME, + SET_TIME, + GET_WAKEUP_TIME, + SET_WAKEUP_TIME, + GET_VARIABLE, + GET_NEXT_VARIABLE, + SET_VARIABLE, + QUERY_VARIABLE_INFO, + GET_NEXT_HIGH_MONO_COUNT, + UPDATE_CAPSULE, + QUERY_CAPSULE_CAPS, +}; + +/* + * efi_runtime_work: Details of EFI Runtime Service work + * @arg<1-5>: EFI Runtime Service function arguments + * @status: Status of executing EFI Runtime Service + * @efi_rts_id: EFI Runtime Service function identifier + * @efi_rts_comp: Struct used for handling completions + */ +struct efi_runtime_work { + void *arg1; + void *arg2; + void *arg3; + void *arg4; + void *arg5; + efi_status_t status; + struct work_struct work; + enum efi_rts_ids efi_rts_id; + struct completion efi_rts_comp; +}; + /* Workqueue to queue EFI Runtime Services */ extern struct workqueue_struct *efi_rts_wq; +extern struct efi_runtime_work efi_rts_work; + #endif /* _LINUX_EFI_H */ -- 2.7.4