From patchwork Wed Jun 1 18:00:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 577792 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:8f0c:0:0:0:0 with SMTP id mq12csp833591mab; Wed, 1 Jun 2022 11:01:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/lAKO+WO2VZv9KLtH5qtpdMjrh/niqOeZEaHxicwpfS17NwFrJ2vZOoCoC7b5DFjNFjVu X-Received: by 2002:a92:d68f:0:b0:2d3:a05b:6435 with SMTP id p15-20020a92d68f000000b002d3a05b6435mr785713iln.317.1654106483297; Wed, 01 Jun 2022 11:01:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654106483; cv=none; d=google.com; s=arc-20160816; b=KcJOjRFnexNTuC/ChYO5EXFIrzKWyo4O2wh9RHTXxCqOiNPzhdgyzX2SI6LCCq6Uzx W766Y+Wt9p3Kd3KqwA43/jnmK2jExmbT9lj5VUKfWYRRslrWqmagPNnFqmayBawh7/zz ODA8UpsUbE+Yw1Tz5u46QFVi1yChoYgCtGzUrSwsHmjc22mOdtFidI1zb1X0sKGkZawp E6m1RcrJECMGRhCtNS9DyOx9SMqK9wHHx68Ly0UMk2lWCZy0mAGpRyzaqYLkKniWt4uG YI3nC79kszOCqA7ALNo12ILhgJuNKv1OpHS9yILEYukbnvQzRZv5gKdMNG9vRBeOm13e rkNw== 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:references:in-reply-to:message-id:date:subject:cc:to :from; bh=58XSahOb53w2F0PvGxhsbm1hiwPTljnWhgC8Nqb8qoo=; b=zwjgtUjESzvZgS4aEjgd1xdzOqdBLMeQ2zSswCmq3ogY4ams/kfFYVeuAkVG+rGv0X i+XcbLdyUD44J4jZUt/fQve53lyy5QEE4+s87k0MJEuppJmQT9AU5/iS2IXoq2n5kwQz MwZk+LMA1i3JfEXMAmocDIS+pqKJULynQUTN5ECxuHp7vcRqu0js5gXgRhbtKUtJOZWF YIpdi093b1vWX3rPUD3CZA83kaDGgPIc9bpilBA3s4M9t880fX0417Q0m1qLa58sD4oQ zcswWtttQKlHLnqevqTeY/gsvbYco2IzaCrgIgss+p+vSCv3ziW19PadCn1pQ4piMu8k BIFQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id b7-20020a6b7c47000000b006525d83ea3dsi2761195ioq.5.2022.06.01.11.01.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 11:01:23 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (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 DDB77842DE; Wed, 1 Jun 2022 20:01:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id EB178842EA; Wed, 1 Jun 2022 20:01:06 +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=-1.2 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 46ADC842BF for ; Wed, 1 Jun 2022 20:01:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 62D94D6E; Wed, 1 Jun 2022 11:01:02 -0700 (PDT) Received: from a076522.blr.arm.com (a076522.blr.arm.com [10.162.16.44]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9EF763F766; Wed, 1 Jun 2022 11:01:00 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Takahiro Akashi , Sughosh Ganu Subject: [PATCH v2 1/4] EFI: Populate descriptor_count value only when image_info_size is not zero Date: Wed, 1 Jun 2022 23:30:38 +0530 Message-Id: <20220601180041.340240-2-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601180041.340240-1-sughosh.ganu@linaro.org> References: <20220601180041.340240-1-sughosh.ganu@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.5 at phobos.denx.de X-Virus-Status: Clean The GetImageInfo function of the Firmware Mangement Protocol(FMP) gets called initially to query the size of the image descriptor array that would have to be allocated. During this call, the rest of the function arguments, specifically pointers might be passed as NULL. Do not populate the descriptor_count value before it is known that the call to GetImageInfo has been made with the allocated buffer for the image descriptors. Signed-off-by: Sughosh Ganu Reviewed-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas Tested-by: Peter Griffin --- Changes since V1: None lib/efi_loader/efi_firmware.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index fe4e084106..9cdefab41f 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -130,9 +130,6 @@ static efi_status_t efi_fill_image_desc_array( struct efi_fw_image *fw_array; int i; - fw_array = update_info.images; - *descriptor_count = num_image_type_guids; - total_size = sizeof(*image_info) * num_image_type_guids; if (*image_info_size < total_size) { @@ -142,6 +139,8 @@ static efi_status_t efi_fill_image_desc_array( } *image_info_size = total_size; + fw_array = update_info.images; + *descriptor_count = num_image_type_guids; *descriptor_version = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION; *descriptor_size = sizeof(*image_info); *package_version = 0xffffffff; /* not supported */