From patchwork Fri Jan 19 00:45:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 763903 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a08:0:b0:337:62d3:c6d5 with SMTP id m8csp204446wrq; Thu, 18 Jan 2024 16:48:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IEoQbfI4+evQIUmofDG7RwvLziV03PM/JOEL980o9TfSz/4gSbH1Qko2geIM2TXFgMIT7xK X-Received: by 2002:adf:a3d1:0:b0:336:8848:e7e5 with SMTP id m17-20020adfa3d1000000b003368848e7e5mr1175523wrb.15.1705625281991; Thu, 18 Jan 2024 16:48:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705625281; cv=none; d=google.com; s=arc-20160816; b=l4Rrms++wD1d10KgCX9mPxAV0veh7YSAEsaR+n2mzxxs77KL5XwfRKPIKEBfJRjyDc NPyWesLXIFn5TNMp7MEfJwbEEL+bG3s6gEy5YLb+dk7DfPGIFY+2tnX5bMtBVXIkHWiQ MHD2Oj8hNUG4DNP3mpvJVuJ2iA6vKjPGWlivo7bXqf4xS6T9Tz9sCVv3OJQ7mvo3Re8a dwq96cH99MU22QW53GwNBumQ0WYQXhpSxuQSn84UU1IGl2uqAeN1JzDmkPandVF354R9 qISPoLi5DwycJiJy46890LTnp6uYOJ1rxFm3m/QKOYPOoTEZ0YweVfNPJF85TkhmgII6 /pSQ== 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:dkim-signature; bh=lMkAtHbS9igJk/XqlqD1v8X9YbbdLN5u5/dkt7CG/X0=; fh=90lSBw+wRfsPn+xaW0S3z+mfIwOpjwfjrVWi6OXSKN0=; b=NeXWHVLZ9roNgtu0/aMNbMeCLAS94RP+OVhsvfMOhXNkA5b+vpfUVdYCQy5gpU37Kg N4IWvWjLhxLGXYjks5PWchh4wu03euxAF070g/JBARPFnx/T5gSV0xTFhnohT+GqWyLP 8rOQK0xw1Qa79ZM728dVpTn5WGoq7H3Sn+3uLScno3EfahWixzWmG6O3tibqgH/SA3N0 sg0XVghIH81dStDfeX33NAQ6KyZgBc+wk8Dt241meUWXaMmTyFWNV9qctBKoBY1GphdA TR7+dnFnEFl+33hDub1PKq2VXhV8MAGO1JjYTYrnEcqjVsvLAU3xTc45Mr5DG4nlTNoh k+FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DnSsEgNe; 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 s10-20020a5d6a8a000000b00337bf858ed9si2710344wru.65.2024.01.18.16.48.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 16:48:01 -0800 (PST) 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=DnSsEgNe; 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 A8CBD87C0F; Fri, 19 Jan 2024 01:47:59 +0100 (CET) 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="DnSsEgNe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 64FE0876C8; Fri, 19 Jan 2024 01:47:56 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) (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 8064D87C0F for ; Fri, 19 Jan 2024 01:47:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-598f3e9f2e3so140942eaf.3 for ; Thu, 18 Jan 2024 16:47:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705625270; x=1706230070; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lMkAtHbS9igJk/XqlqD1v8X9YbbdLN5u5/dkt7CG/X0=; b=DnSsEgNeanLRGsVa6hz4KTAVFhnseA1nehI5D5LnzFEYo6vwh95JpCvDl6FfN4wVt5 hz/Hit0Cm+lZZjABh71TmWPkdLRK07iAiYv+IZGzbEXK1iRCJQzzd7rS4dt0crZjXsXv TNyg7n5StRkKyXrLXp+X4keOykC+fKQc4JzEAmJQc57gnxcIMxKrSnDIjdQmhFDStJg5 m4frMag5FUPBuokBgLJST8ZRbTD0MoP40iJ7lSBM50lYhQdMucdPIO5slISE7hx7cdT0 va9bxK+dmOJ4p5vIj6ddo3Q4WUIBQojiNKu42ZpNdlBlP0oejmo7F747bhvvbYU5wVWM 4sKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705625270; x=1706230070; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lMkAtHbS9igJk/XqlqD1v8X9YbbdLN5u5/dkt7CG/X0=; b=H0qxSN5mRMPDaIiKOwNUEe9RyoIgZBAH9PDaMVBIe6DX6NfdACcUq1ojI/ZOH/3mrO QZgcCwmPmCeTuLR+fSh6qe+ewufkLKA5d+5NwMJgClQvSrd3X0wWoz6HH4A9MgcvUIPa wwrGkOxiIgHzSyIVgMPUQdUutJlMOS61OOiNDwPopCoHczh5jBPngpPV/tu5cVNH1OOr wclM/MwHHgzURkwYhJPILFnue6FbotBrIcli6RkUqGnuv36P5hxH/7w1AOvE3eGAmu8Q Vg5VX6xmpoTNEPEdXI+IQNytVGFA0az8cUl3GmDPquWdS9T+dt0RW4ltWGp/SIF8p6bN PIDw== X-Gm-Message-State: AOJu0Yyw7o7NC6Tmz/alFEGMDLMzsxrnnZOOK+fJM94U99kymmRAd3fC zgFa4KsejzJmSsWk7yH8maJfhTet/Q09xFfgGlJhK+hwuXoojcnSYNeviNuFRbldhqtt0YV1AQ5 5 X-Received: by 2002:a05:6358:cc1e:b0:175:e96d:3c4a with SMTP id gx30-20020a056358cc1e00b00175e96d3c4amr1516810rwb.11.1705625269709; Thu, 18 Jan 2024 16:47:49 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id kd3-20020a17090313c300b001d5383ae01csm1946470plb.121.2024.01.18.16.47.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 16:47:49 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , AKASHI Takahiro , Masahisa Kojima Subject: [PATCH v3 1/3] efi_loader: avoid pointer access after calling efi_delete_handle Date: Fri, 19 Jan 2024 09:45:44 +0900 Message-Id: <20240119004546.1084018-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240119004546.1084018-1-masahisa.kojima@linaro.org> References: <20240119004546.1084018-1-masahisa.kojima@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 efi_delete_handle() calls efi_purge_handle(), then it finally frees the EFI handle. Both diskobj and handle variables in efi_disk_remove() have the same pointer, we can not access diskobj->dp after calling efi_delete_handle(). This commit saves the struct efi_device_path pointer before calling efi_delete_handle(). This commit also fixes the missing free for volume member in struct efi_disk_obj. This commit also removes the container_of() calls, and adds the TODO comment of missing efi_close_protocol() call for the parent EFI_BLOCK_IO_PROTOCOL. Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- lib/efi_loader/efi_disk.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 013842f077..105f080125 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -707,7 +707,9 @@ int efi_disk_remove(void *ctx, struct event *event) struct udevice *dev = event->data.dm.dev; efi_handle_t handle; struct blk_desc *desc; + struct efi_device_path *dp = NULL; struct efi_disk_obj *diskobj = NULL; + struct efi_simple_file_system_protocol *volume = NULL; efi_status_t ret; if (dev_tag_get_ptr(dev, DM_TAG_EFI, (void **)&handle)) @@ -718,24 +720,30 @@ int efi_disk_remove(void *ctx, struct event *event) case UCLASS_BLK: desc = dev_get_uclass_plat(dev); if (desc && desc->uclass_id != UCLASS_EFI_LOADER) - diskobj = container_of(handle, struct efi_disk_obj, - header); + diskobj = (struct efi_disk_obj *)handle; break; case UCLASS_PARTITION: - diskobj = container_of(handle, struct efi_disk_obj, header); + diskobj = (struct efi_disk_obj *)handle; + + /* TODO: closing the parent EFI_BLOCK_IO_PROTOCOL is missing. */ + break; default: return 0; } + if (diskobj) { + dp = diskobj->dp; + volume = diskobj->volume; + } + ret = efi_delete_handle(handle); /* Do not delete DM device if there are still EFI drivers attached. */ if (ret != EFI_SUCCESS) return -1; - if (diskobj) - efi_free_pool(diskobj->dp); - + efi_free_pool(dp); + free(volume); dev_tag_del(dev, DM_TAG_EFI); return 0; From patchwork Fri Jan 19 00:45:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 763904 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a08:0:b0:337:62d3:c6d5 with SMTP id m8csp204488wrq; Thu, 18 Jan 2024 16:48:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGkC9w9m3T2jFcNqA+AtkVTxD/CEu/7hrJMTk21MoH99qBgFfnSlkgi55/FdRBWFI7CQnp4 X-Received: by 2002:a5d:4bd1:0:b0:337:b302:e752 with SMTP id l17-20020a5d4bd1000000b00337b302e752mr1032058wrt.50.1705625295890; Thu, 18 Jan 2024 16:48:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705625295; cv=none; d=google.com; s=arc-20160816; b=0sxyZuRBkeldvs7lQzEDfI76tium/gJ6Q3VYHdkqlVI1WlbsyjOljZLzQZiABNfckJ tt23/aTBv+1DI4O0RkmowpFwvsNV8DcSa/TTk3JDgVIY2hlFjNIMqQioj7b2E9Z1LQOg 94Bs9OqJeCiYwH7loqT2ucjtF+UQL736dkyIP5VANgzCJU+UJeGfuWwYe0jsR4SstWxJ jq1RwwzShfr/kBgPo116LitlzBL8udPeCEpraH0G3a5TcdSHExDLZRQvFQaPVI3MBKUL +zsoIlKevYDXV+TzIsA3uxV01PvDQbGd9/B81kaQSuhgu+SkSxhcNDh7SfocED0nrYD4 SpZQ== 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:dkim-signature; bh=crWngtzxMPcMdvcVco96f8AC88kApFBYBAC8rvuPYR4=; fh=90lSBw+wRfsPn+xaW0S3z+mfIwOpjwfjrVWi6OXSKN0=; b=HLrbuTSFTvHLNxb2PbFtkAug5cCP7VmJjJho9D3YAxmMvNvL4WCIml3eyttHGA6OE4 M/svGnr7A4jK4VpyKPcD3IBzGA57bu0vMMUXtmgEYUfZQodowvpxsTMXnr8RIrJiztHZ wlrjh56YqpJajEY2CCqcTgkY+LmFfS6dgThY2SRg7S9PXLDLqDVpB2xTHoRxQsTZkF7b L91HtqGilJdrWFKmnem+hZAemsfGEpp42WSZnUb/vB9mPlJND3pM92E9c8ECsR5wi30C jyEceOcpS4/HzzVOTunLIidM8YBzBbxtL2CJf+bm4TAcR34dXa6LNkJ3m6ZSUmay6prs KVvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pyaGSQI8; 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 g5-20020a056000118500b00337d7387ec9si708122wrx.555.2024.01.18.16.48.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 16:48:15 -0800 (PST) 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=pyaGSQI8; 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 8383587C5A; Fri, 19 Jan 2024 01:48:00 +0100 (CET) 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="pyaGSQI8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9359C87BF6; Fri, 19 Jan 2024 01:47:59 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oa1-x31.google.com (mail-oa1-x31.google.com [IPv6:2001:4860:4864:20::31]) (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 6BAB887BE1 for ; Fri, 19 Jan 2024 01:47:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-2109743a111so211423fac.0 for ; Thu, 18 Jan 2024 16:47:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705625274; x=1706230074; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=crWngtzxMPcMdvcVco96f8AC88kApFBYBAC8rvuPYR4=; b=pyaGSQI8HjyiQd98yezggVTpixqmiDgqyivwT9Lw5BV39dH0XaqV55O2JBjalN3dpM BeYmFSDHxpB7KmJVNcTJh4Vp2K0KA2o22ZFDIBfpCB6IzH7lSG3ALE4bcpcr05pSACwR 244XxkyYLLIMRIoJWGAawmO5gMu842EqD2sedUCWhG9AIyFes193lJ1oYAY7lDNfA//1 q/gzQBD9mOyEvlLr90mXBVBpNcfBaI7W81ahi/pcUoLSE3xIR6RgXIY4jMVjCpX/bsf+ 5p6+0aEmFy/JgjeBEAEAGcFRGmx4I92e7tBqGYz9CThIPXSkRt2bghrCplEpDaD65HEC vMeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705625274; x=1706230074; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=crWngtzxMPcMdvcVco96f8AC88kApFBYBAC8rvuPYR4=; b=pIc3XhbIGA+IH2mLH7h1rdJDnNqDj5kPObe9wlfqCg0VQb2Q5e6165lkdbsGCowp4s S2sYukXcbCq6Yt92cF1oGPvq2NGPvp09Bpl4Sgd3K5ZD6Hj9sgzAmqDLqCZ1VkK2xZs0 k2FjYcqeYpsa1etqR8x96MkF6ocv8a014kC1az+L2IPJ62qbjX90srJ2swSW1wQFqFN5 tso2kpPaofzXiCqkUemRuKXgxdKQZ2M4Nzv07o2jylfTJL2Fd5YQXsf1BHeCnff0w3EA 791zNZKDAW/w2tAahqEsZ4+V11EKRt4jIlMujzULeGZpfKw4Bpdb7+CsPy0a99PMyprT cLDw== X-Gm-Message-State: AOJu0Yx8RfBePBYjS3Mm6zAUWF5AjarJDwyQLhkOwk/o97ySP8NfpVS9 sMXwFAK4837SyS61MWOc3tzhEd0rOH5+rWLKd6iBjQNCe8ATbbm011GRvm+wPFGtgoDRHakvHxV 6 X-Received: by 2002:a05:6871:548:b0:203:afa6:ad29 with SMTP id t8-20020a056871054800b00203afa6ad29mr1960000oal.23.1705625274688; Thu, 18 Jan 2024 16:47:54 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id k68-20020a632447000000b00578b40a4903sm2200046pgk.22.2024.01.18.16.47.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 16:47:54 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , AKASHI Takahiro , Masahisa Kojima Subject: [PATCH v3 2/3] efi_loader: create common function to free struct efi_disk_obj Date: Fri, 19 Jan 2024 09:45:45 +0900 Message-Id: <20240119004546.1084018-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240119004546.1084018-1-masahisa.kojima@linaro.org> References: <20240119004546.1084018-1-masahisa.kojima@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 Current error handling of creating raw disk/partition has following issues. - duplicate free for EFI handle, EFI handle is already freed in efi_delete_handle() - missing free for struct efi_device_path and struct efi_simple_file_system_protocol in some error paths To address those issues, this commit creates the common function to free the struct efi_disk_obj resources and calls it in case of error. Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- lib/efi_loader/efi_disk.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 105f080125..e2edc69fcf 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -371,6 +371,20 @@ static int efi_fs_exists(struct blk_desc *desc, int part) return 1; } +static void efi_disk_free_diskobj(struct efi_disk_obj *diskobj) +{ + struct efi_device_path *dp = diskobj->dp; + struct efi_simple_file_system_protocol *volume = diskobj->volume; + + /* + * ignore error of efi_delete_handle() since this function + * is expected to be called in error path. + */ + efi_delete_handle(&diskobj->header); + efi_free_pool(dp); + free(volume); +} + /** * efi_disk_add_dev() - create a handle for a partition or disk * @@ -528,9 +542,7 @@ static efi_status_t efi_disk_add_dev( } return EFI_SUCCESS; error: - efi_delete_handle(&diskobj->header); - free(diskobj->volume); - free(diskobj); + efi_disk_free_diskobj(diskobj); return ret; } @@ -569,8 +581,7 @@ static int efi_disk_create_raw(struct udevice *dev, efi_handle_t agent_handle) return ret; } if (efi_link_dev(&disk->header, dev)) { - efi_free_pool(disk->dp); - efi_delete_handle(&disk->header); + efi_disk_free_diskobj(disk); return -EINVAL; } @@ -624,8 +635,9 @@ static int efi_disk_create_part(struct udevice *dev, efi_handle_t agent_handle) return -1; } if (efi_link_dev(&disk->header, dev)) { - efi_free_pool(disk->dp); - efi_delete_handle(&disk->header); + efi_disk_free_diskobj(disk); + + /* TODO: closing the parent EFI_BLOCK_IO_PROTOCOL is missing. */ return -1; } From patchwork Fri Jan 19 00:45:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 763905 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a08:0:b0:337:62d3:c6d5 with SMTP id m8csp204532wrq; Thu, 18 Jan 2024 16:48:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHp4CoOEVADud4JQ8UlkBaHJLujLSscAWSj2EUyH3iuuQ3VwIzY2O97g/8v7y05IfVikz/3 X-Received: by 2002:a05:600c:143:b0:40e:60c0:d94 with SMTP id w3-20020a05600c014300b0040e60c00d94mr1083152wmm.78.1705625305647; Thu, 18 Jan 2024 16:48:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705625305; cv=none; d=google.com; s=arc-20160816; b=jEFmJp83YVG2DxIUFArmkP8bs7cr/8i1rqfGPM2dOC022cYdRv3idF6aUHaZrZU5nB XBkaQE0YD0Y+IEYVkUQze5ZV6erp1XXVYPQm/YKJsp2tIisHipcWZE+stb6UvdEwvohm xXDOxeC5T87QmDZ71ICU1sr4LPzMfGz2mXA9LWr77TOIdrTskdsyqmS7QevjnMaWRscV Zw5dB6ARWDdHJaltFUXd7K74BTzsv1FcFK3vP1SBpq7bzHmcIquF3sIR+UasylvX9KkZ FTWFTR/657ZjBKTInmXffzWguEgdTX1mo4uevPtgwKBLlwfZykRx7ToWAHahs4PZxUWC bAYA== 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:dkim-signature; bh=987e+i7Eq0JZrNoCQx7+nDA1NxECWTAY1oGiBHOp0Gg=; fh=90lSBw+wRfsPn+xaW0S3z+mfIwOpjwfjrVWi6OXSKN0=; b=yfzVyrntwjzPfv6sgLkBlW9DNP4Zypj7PX3tY+byxV0SbyKp5FxiPei6I03YtZMM8O QYpvXIUEWV+38OptES8bzWvTWeZgJqS0OT+ZomQLJKPaSOfXSXRT4RVv0Yi4HU6/MErD hI/6GU8dnhrsnNZBT2bdvOyT7K8N2fWkSIftjdhuTgo+V8swGKqj7Vc/VL8TWAauqnID UrVRJfvF2ODIuCo98rfneCeH//fyPpmkA2VeSc7pkcPxG8cbl8E1ACga8hUOcB0R8tIu ESgkc1ILjzd/Ix2M2P8AgqB+IbhlUmRX8r++Kmaag0bvem5ftVzYf4ZRpUmO5oPl1hoJ +ixQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="c/Q5B5rs"; 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 r9-20020a05600c458900b0040e72a82703si5948636wmo.134.2024.01.18.16.48.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 16:48:25 -0800 (PST) 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="c/Q5B5rs"; 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 AA08187C8F; Fri, 19 Jan 2024 01:48:13 +0100 (CET) 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="c/Q5B5rs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7DAB487B93; Fri, 19 Jan 2024 01:48:10 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) (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 B32C887C8A for ; Fri, 19 Jan 2024 01:48:01 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6d9b050e88cso266461b3a.0 for ; Thu, 18 Jan 2024 16:48:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705625279; x=1706230079; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=987e+i7Eq0JZrNoCQx7+nDA1NxECWTAY1oGiBHOp0Gg=; b=c/Q5B5rsgZQfTi8BJSq/rKlGfMzKtL9UwB+GXNps4IvRpUSIWZ9RYIfWqLsKvZM6C6 Yvisq4d8S49Znz+ZbmBrIW/RpelLSK8lX4a0mXtAw/ik+OUwTvWwc5Ac/GDrXZ9LMn3R GBmUaZtePH22p0e8nq1fvH+ueMbb//ZwfHKqf66qRlg9OBJXgU+rjEtGT9oZhXRCS17V xOCShuOSddmwPsCjG/nAuO26VIm03AnBCnYC6JdNci7QoK23AwapS2r+zxETqB+P8jzI 4wqypCBaYszuOj6/1+J7OmM8jUOFUrH8RW82t9fVZnRDUpudZs0pJJbToMHAKJuzXNZZ RICg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705625279; x=1706230079; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=987e+i7Eq0JZrNoCQx7+nDA1NxECWTAY1oGiBHOp0Gg=; b=Ut1D1EnZk7O4EsmUNo/6fVKC6aFTOXY5EbPhEa85rT9oOvqeRdp5zsFv/uoByNCtCT Ixjd/7BkHftDsLyZrLFnHTuDxsKjc678Gb0dV+lgdOdtvFhbnBcOBbdWw1bgu24NfNJN QBJNIwfezsUhgvnyHz+6nOjYHQyR/dVAtk1+iPd66UQUNZ6TBg+PivtVFSOaeg2CydeI 1y+dcXkr5CBxZzAnpWaNWH0rXrKzmCa6W4WDTX07tmjfb+kHxZf5fGOLQzi0wJl2OdWe 3oNYNPGBpF2E/MtFYsig1Hf57ZpQH6WrqOUtjlC8T51nimQkjVtWK6+wgsTW5B7VlDgC egNw== X-Gm-Message-State: AOJu0Ywh58VFXN0WHQLTCcRIwfM4oflZ5GBwi41xLKDxFjR0nMWFLRML Pe3WHrilZ1Ce+c/YUbGXMuZCcXs1tedNWJ4y5fLSyHG2st2C2A0JCPx9CYfv9DvZFOA+U38GdpP d X-Received: by 2002:a05:6a00:4b0a:b0:6d9:a651:4b07 with SMTP id kq10-20020a056a004b0a00b006d9a6514b07mr1837305pfb.46.1705625279649; Thu, 18 Jan 2024 16:47:59 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id a3-20020aa78643000000b006db97e2c4e9sm3874522pfo.181.2024.01.18.16.47.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 16:47:59 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , AKASHI Takahiro , Masahisa Kojima Subject: [PATCH v3 3/3] efi_loader: return immediately in UCLASS_EFI_LOADER removal Date: Fri, 19 Jan 2024 09:45:46 +0900 Message-Id: <20240119004546.1084018-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240119004546.1084018-1-masahisa.kojima@linaro.org> References: <20240119004546.1084018-1-masahisa.kojima@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 In case of UCLASS_EFI_LOADER, EFI handles are managed by EFI application/driver, we must not delete EFI handles. Signed-off-by: Masahisa Kojima --- lib/efi_loader/efi_disk.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index e2edc69fcf..b1739d9920 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -731,8 +731,14 @@ int efi_disk_remove(void *ctx, struct event *event) switch (id) { case UCLASS_BLK: desc = dev_get_uclass_plat(dev); - if (desc && desc->uclass_id != UCLASS_EFI_LOADER) - diskobj = (struct efi_disk_obj *)handle; + if (desc && desc->uclass_id == UCLASS_EFI_LOADER) + /* + * EFI application/driver manages the EFI handle, + * no need to delete EFI handle. + */ + return 0; + + diskobj = (struct efi_disk_obj *)handle; break; case UCLASS_PARTITION: diskobj = (struct efi_disk_obj *)handle; @@ -744,10 +750,8 @@ int efi_disk_remove(void *ctx, struct event *event) return 0; } - if (diskobj) { - dp = diskobj->dp; - volume = diskobj->volume; - } + dp = diskobj->dp; + volume = diskobj->volume; ret = efi_delete_handle(handle); /* Do not delete DM device if there are still EFI drivers attached. */