From patchwork Tue Jul 30 11:11:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 815302 Delivered-To: patch@linaro.org Received: by 2002:a5d:4acf:0:b0:367:895a:4699 with SMTP id y15csp242840wrs; Tue, 30 Jul 2024 04:12:20 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWE2jkOmwNU0HtrCS8LIJprBTj5RR+YHfQePdenqVcRhK12vjDDMUPKPfBACUlHNg5j81K+w2Auhubc7yVXjlDY X-Google-Smtp-Source: AGHT+IH+ZMHJqXer+SGHDDdHqjOX2mZRrCSbU/NCaVDyaGM0hUlp1B1/P7XiqTbyK1FaGyIELAE3 X-Received: by 2002:a17:907:3da8:b0:a7a:a892:8e05 with SMTP id a640c23a62f3a-a7d3ff9e775mr916239166b.33.1722337939841; Tue, 30 Jul 2024 04:12:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722337939; cv=none; d=google.com; s=arc-20160816; b=OWyO9yoexYS/qRASj7OMyp/6skdAtaoLJzYY/cSkJWGMYiZNSui45XIvRlhnSxCi91 iVtKe2+dC8Qh51c9jDCWoQpe8qXWZe0AgN41JYoDzeFn2mr2gHk5uT2baeylSN3y78Cu DmoaN9w4FHdVex2EhY37nIBnjN9galmGPEzHCl5OdFQq8MhlYtUOAAh7bhcTAc4LRZzP mvx2/oKiqBK54fVfS8Oh23/4Y3G/ZhAdL2sox1cvr8AyDoT8wrUfCzWyBbobusSjc9bN umW74ewZ3NXKlurkfgxnPf0vo6ZGzFLccUdcjxYU3IbNcwZ/eq0x+Mumaiqk5MH7jv+F /hIw== 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=+eXAiokIiec04FrwfY3zW21rpc5HUPUNthsFPOsIlMs=; fh=c60fu1IChZaOc2lQYQAOoRysAfBqXosZh6e58mdWpwk=; b=hAdzlqmfPVGDZrAMfams7X0Z/vuT8bQ7nXQUz+/Ul+hvvTsS6/FnERl0CYX9bE9wyH vL4RlQQwpyAmuRQAMvL0Gsr8AMEJH6lQlQ/qH22x0iEMIOgw0EHz05RVv+miIjX05mzr Mbb6a3d9jsfxCfXc/5gy01NgyJd/7LzA8a5fwUhWxMEcTOwRleyeMDbu9gaQ/q2RlK6L DGRUA/jcrz3wYPJu6zs6sAWL+gmINhnl89MHJa3B5PwEFTidgtg4sq3Gf9iDwYQQ4Lce DjCsLsv8G5dUpGGUTpzUmr02qe8KH2UQ+KEz8rF95Wxe39CBT1PKux9NkHdggrCNh4pb terg==; dara=google.com 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 a640c23a62f3a-a7acac69516si788927766b.667.2024.07.30.04.12.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jul 2024 04:12:19 -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 CBC768882F; Tue, 30 Jul 2024 13:12:02 +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 025118881D; Tue, 30 Jul 2024 13:12:02 +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, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL 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 10A978780A for ; Tue, 30 Jul 2024 13:11:59 +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 01B6B1007; Tue, 30 Jul 2024 04:12:25 -0700 (PDT) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AC88F3F5A1; Tue, 30 Jul 2024 04:11:57 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Sughosh Ganu Subject: [PATCH 3/5] efi_memory: avoid possible null pointer dereference Date: Tue, 30 Jul 2024 16:41:30 +0530 Message-Id: <20240730111132.1097315-3-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240730111132.1097315-1-sughosh.ganu@linaro.org> References: <20240730111132.1097315-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.8 at phobos.denx.de X-Virus-Status: Clean Populate the previous memory descriptor node pointer only after it's parent struct has been initialised. The compiler fixes this logic to do the right thing, but it is better to have correct code in place. Signed-off-by: Sughosh Ganu Reviewed-by: Simon Glass Reviewed-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- lib/efi_loader/efi_memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index bfadd6bd41..8d4f6e339d 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -138,7 +138,7 @@ static void efi_mem_sort(void) merge_again = false; list_for_each(lhandle, &efi_mem) { struct efi_mem_list *lmem; - struct efi_mem_desc *prev = &prevmem->desc; + struct efi_mem_desc *prev; struct efi_mem_desc *cur; uint64_t pages; @@ -149,6 +149,7 @@ static void efi_mem_sort(void) } cur = &lmem->desc; + prev = &prevmem->desc; if ((desc_get_end(cur) == prev->physical_start) && (prev->type == cur->type) &&