Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF66DC11F68 for ; Wed, 30 Jun 2021 15:50:04 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 23A3961480 for ; Wed, 30 Jun 2021 15:50:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 23A3961480 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 160B982EB5; Wed, 30 Jun 2021 17:50:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="sHdTEDUi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9BB3082F40; Wed, 30 Jun 2021 17:49:59 +0200 (CEST) Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id DA0F082DF5 for ; Wed, 30 Jun 2021 17:49:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masami.hiramatsu@linaro.org Received: by mail-pj1-x102d.google.com with SMTP id in17-20020a17090b4391b0290170ba0ec7fcso4271960pjb.4 for ; Wed, 30 Jun 2021 08:49:54 -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:user-agent:mime-version :content-transfer-encoding; bh=IAlKW5QCY6qHGkO8bmRDvv11m7jBdcZjZVft0TIQrOw=; b=sHdTEDUiiPWVjQ7WgQNdCcC/n89G31D3T+YueXedJ45VKBYsfkaX4KQ+uNDS2PVCr/ 0DPZq51sWEmZ/5J53angbQ+ayR2iJMCSQbmdWYaqdRq3ltawb2TCtjbN1rQjJjWtxJfh HaSX+PaiXUhSh101efwhobZQZYp/xtHmoPNSi1Ji7QhOmuJXs68nvi+18q8hhJIhkiXJ uch/9fj+S9mouB0L6YKts1fqcGuYC9ZHetthlLhitFd9zimAriQdEl2lYOddFjCrEF43 3P6vsp6E5sXTPQ5IL3q6B5fkqAkPjX5KtfyP4g+W4rnf+nCgVDIiuP/hudw9bQsU9rWs Hqfw== 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:user-agent :mime-version:content-transfer-encoding; bh=IAlKW5QCY6qHGkO8bmRDvv11m7jBdcZjZVft0TIQrOw=; b=q2X7nZKm1j6WJmozCi5WvQd/1i5YYSjwBl46mOnpnc92z9tqgT99TdTSTW0BmJZZw2 DJDiQABictSxnGqiFYSX6zMLiAcmZGTNLlrHz98gF04PKd5HQ+vtB/K3WgB9hJl1VaId UoRo3viW+WF6SuK5rCW6cAxslHaxg1vbjHipg7fS+zEy3fV43OX/bc+PsskSo4lmglgi KEm6cs03Ta0XYJvx2jugGU5gRWVSNqQc1N3q2XHOLcPAW7QqcBiniIosajjbXmZ0H1KJ kRpV9s4NUXOcufFTxcotAysIkuhSvt6uG3vf2Bs81kM3BChpu1hDoszFDd71dvpDwaR9 7+WQ== X-Gm-Message-State: AOAM53151DSpSHEFGWYPpPczB07bopa6P4eTix4rv6c2FeIDeA1yXJP5 94/J8Y64j/ZVQdy88MmgPf+hKeQaGrFkiqpS X-Google-Smtp-Source: ABdhPJzBghFEvFwj31gV85KFj81e+6y/RmOdcB/zAI4OZxXsEOf6IZp1CzDMIYTuO6uy5dZUw49jcQ== X-Received: by 2002:a17:90a:1641:: with SMTP id x1mr40467692pje.160.1625068193071; Wed, 30 Jun 2021 08:49:53 -0700 (PDT) Received: from localhost.localdomain (122x208x150x49.ap122.ftth.ucom.ne.jp. [122.208.150.49]) by smtp.gmail.com with ESMTPSA id p45sm23051518pfw.19.2021.06.30.08.49.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 08:49:52 -0700 (PDT) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Kazuhiko Sakamoto , Alexander Graf , Ilias Apalodimas , =?UTF-8?q?Vincent=20Stehl=C3=A9?= , Grant Likely , Heinrich Schuchardt Subject: [PATCH v2] efi_loader: Improve the parameter check for QueryVariableInfo() Date: Thu, 1 Jul 2021 00:49:48 +0900 Message-Id: <162506818806.105828.11539308200542520069.stgit@localhost> X-Mailer: git-send-email 2.25.1 User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Improve efi_query_variable_info() to check the parameter settings and return correct error code according to the UEFI Specification 2.9, and the Self Certification Test (SCT) II Case Specification, June 2017, chapter 4.1.4 QueryVariableInfo(). Signed-off-by: Masami Hiramatsu Reported-by: Kazuhiko Sakamoto --- Changes in v2: - Add a reference to SCT 2 spec. - Fix checkpatch.pl warnings. - Simplify the check according to Henrich's comments. --- lib/efi_loader/efi_var_common.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/efi_loader/efi_var_common.c b/lib/efi_loader/efi_var_common.c index 83479dd142..3d92afe2eb 100644 --- a/lib/efi_loader/efi_var_common.c +++ b/lib/efi_loader/efi_var_common.c @@ -163,6 +163,19 @@ efi_status_t EFIAPI efi_query_variable_info( EFI_ENTRY("%x %p %p %p", attributes, maximum_variable_storage_size, remaining_variable_storage_size, maximum_variable_size); + if (!maximum_variable_storage_size || + !remaining_variable_storage_size || + !maximum_variable_size || + !(attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS)) + return EFI_EXIT(EFI_INVALID_PARAMETER); + + if ((attributes & ~(u32)EFI_VARIABLE_MASK) || + (attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) || + (attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) || + (!IS_ENABLED(CONFIG_EFI_SECURE_BOOT) && + (attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS))) + return EFI_EXIT(EFI_UNSUPPORTED); + ret = efi_query_variable_info_int(attributes, maximum_variable_storage_size, remaining_variable_storage_size,