From patchwork Wed Jun 30 15:49:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 468708 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp473984jao; Wed, 30 Jun 2021 08:50:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0hBX28HRKcSUikgfoAYwrengqrUQbfzjG+Qzs6HMs3ZhgLuJatLgTxHTDbFEZZH7zzLm4 X-Received: by 2002:a17:906:3489:: with SMTP id g9mr35133705ejb.282.1625068203796; Wed, 30 Jun 2021 08:50:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625068203; cv=none; d=google.com; s=arc-20160816; b=GIDn5yX5ZwFIrsluEKTKIDOs5EqJlID0XmMv1RiyrfL4sFvLmwyjIAazVUAUTHM4xZ QVB+r/DzTdX8HVL7q2ZGEN8aE1EvEcgkvKwdLQwVqQ60Nubx0ars9hlSkLqPMbnbmNOk 0viQbGtK7QAkbCvfjz8UUS2UfrSSmuKkPoWcF1XHzKNJrpCjypXc/8m0ll8aSJHfgS0M ojlX4A7AwhHktbs/dXzBloOcCAE8wySZwtrzdvJRgJc6AMxn5ZQuJiWjOrc1s5FA1hRm 88YOjB1fm7cqIXPlza3uUGd1YmoylfUnb7+ZS26ii0gBbck9EP7OaLTcg3WnRGMIOVXn Le5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:user-agent:message-id:date:subject:cc:to:from :dkim-signature; bh=IAlKW5QCY6qHGkO8bmRDvv11m7jBdcZjZVft0TIQrOw=; b=mVLttH94e0W8DGgvJ/r0nJOSQMOlG1UGk9tBHw57+a8CKv/cMwbOd76hzUdlSnhmIh 7NR/Fx84jFWxvUcRJLgusLtuxhbFbAYESSeEKziMmEsP1MXPb3ICL0Cx2QaYJn19J4/F DvIR39UCM9YPYMuBNOJ7uQJjp8fVbuQHSqEiLYJWWf7LVbPsSI9zOwB/ZY3FSImjhDkk i2ynp+AdzboTRkYlYEr9gsxoMZbmVhqTj6VO2cPq3EE+9j6U2C7O42EG7OnNkyb49gKT VJMEJQjsZO24gZNLYux2WhfID7A0j+/UfnIwki8dYpYGdjSK1nDQjB3+4NGXmyJOIZQQ i9XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sHdTEDUi; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id cf25si11578448ejb.288.2021.06.30.08.50.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 08:50:03 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sHdTEDUi; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 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-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_Ste?= =?utf-8?q?hl=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 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(+) Reviewed-by: Heinrich Schuchardt 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,