From patchwork Wed Jan 17 09:44:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 763287 Delivered-To: patch@linaro.org Received: by 2002:a5d:6e5d:0:b0:337:62d3:c6d5 with SMTP id j29csp185596wrz; Wed, 17 Jan 2024 01:46:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHO+ClXIokTK0Mk6Xv8uC54m2OP0AQ1yDETyblvLtCJZsAXH4woQxIMkuw0mHeyHx7hgBJj X-Received: by 2002:a05:600c:418b:b0:40e:53f8:5242 with SMTP id p11-20020a05600c418b00b0040e53f85242mr4806988wmh.72.1705484817267; Wed, 17 Jan 2024 01:46:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705484817; cv=none; d=google.com; s=arc-20160816; b=D4mpsMjOCuht1WH3xSPB6xoiULJIkB2rKDHPvOW+2OkErmm2zRzES1qwyxMhKRZdGI NkQfi6ZkLfbbvIV0UXZO7Dmx1/qnlj7ysoAHdzhZkU9JJRbqck1D89Q0j74DQfvmggNZ Z4E64J5iPdjmfnVkVf6eDXYSyX63jt6x82ecj6laGLE1YiN9+wYx9GnxJ1bMiYMeCWAr yRLraPi3cjQdNFgy6zL14vS/8rDPYKG+R4PiRgLqy3smnx+TCHXIQyk9SjUw1H4lKACw MknQO7MZFuYbUzvV99efl1yss/GO/m5xfHlQSQ7puhC35SAw0LkqxNdUGzJDQEw+TXNC qjIg== 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=H/mGCQb8aGXFjbqqblC/NhK7evpYwFCorbUPtKhDUy8=; fh=90lSBw+wRfsPn+xaW0S3z+mfIwOpjwfjrVWi6OXSKN0=; b=qUpYIAOutfkSepRbLCk0/5OjZpeezd2Vw8FqT6uiYs7TmTmeXmVg0F7liadKDCM5Pp /Vt3JjJ80qFDBzag8WWyTUZH1Sc21mWG+j5WneXTqFrWKI2c1tUMjGj9CWjrVaPmF8YJ LVNq9a3B9maFiMBKmbp5FL2rVFoz8XKO/gFi4OkeUllQrNKsFLM7neo2l5I1Fv795dNj ngCb1LQ52LBwcUylU8TTdcleu7HrT67zO7e3xxWIeCNN/5vF7Xn4T1qB9RE8DcZoL/vv OTuvDBE30nt48o6im36INJed/W5lJvvcqTnXwMCxs0RwnByzdPUjdI/LuS9TAjrxHzSJ 0q5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GDAYTqFe; 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 fc12-20020a05600c524c00b0040e598c7c03si7641637wmb.108.2024.01.17.01.46.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:46:57 -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=GDAYTqFe; 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 206C187B42; Wed, 17 Jan 2024 10:46:50 +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="GDAYTqFe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9D45E87B41; Wed, 17 Jan 2024 10:46:47 +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-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) (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 C4BC587B12 for ; Wed, 17 Jan 2024 10:46:44 +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-pl1-x630.google.com with SMTP id d9443c01a7336-1d5dfda4319so13019835ad.0 for ; Wed, 17 Jan 2024 01:46:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705484802; x=1706089602; 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=H/mGCQb8aGXFjbqqblC/NhK7evpYwFCorbUPtKhDUy8=; b=GDAYTqFeR14oAwpvHDRTwPvMXqFuWj3SygUcCD8T2O+C1mykOBcOAHCQ1GI/Ew9N9w qNFrunp71jcY9aopSXsZoNJzqboSo1go5g04by71lvokWddAx/QoYULisrhCDjFyOYwD IVSPNntkC7/J/X/ZNiVOxqbZ55g0H9PhOb1zV/E39rNQ0nOvmrUPSB7Uqb6GB4ZP5z3c Nd+ozlay6gh9NJRcLH8M/neFSaM8/t8OWpg6RP4zY9247pXSC8b3HzHgikKvmeKQPnoP GiXjLsUiGSVmXk1e3uL4CO9RCSyTQKPhdlovztaFvpg0u8PyfOiDefcd14zQddoRNjt5 hW0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705484802; x=1706089602; 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=H/mGCQb8aGXFjbqqblC/NhK7evpYwFCorbUPtKhDUy8=; b=k9VxAhRBeqnkfGFJV6pgxW0wSqRh0HzUs+LV+d8K62FBS0vz0prUO5Mq2yhTN4u+lA s6Pj/UMTSz9foJwiAbMfFD3e4YBBikwE5KjxhnF8XxlBkMJasNrGZcebA36Gxh5zDHPZ Aqqkfb+tig48GSaRnP1yTu9ukSt+SmQs3D0XQS7G+59V/X6j+3jqI8KmUcXxFfi/fYSt jJYuTF2TuICS6YWzQs+HYtphjZDEX/F+AQ0HCl9W29XAVf+wuh+qqAsOORcz9HKe/yIo wf3nkQ/Ugj3H3fFWmz+HbPM6VyUGl4YofWBgEycJyD1P5HEtM9l1ssusg7oEpuiFE1Ma aNlw== X-Gm-Message-State: AOJu0YzLgC6LzbZ99ZdfCitci54ALyuQjUIJmJvvi3neFeHkB1PYFAo0 wXpkAiNMUImooGgEBtK/wV7uxe7ymHZE2xgndftjvneqb3Y= X-Received: by 2002:a17:903:2986:b0:1d6:f3be:aad0 with SMTP id lm6-20020a170903298600b001d6f3beaad0mr366119plb.32.1705484802372; Wed, 17 Jan 2024 01:46:42 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id e23-20020a170902ed9700b001d5eb912f8fsm2371267plj.15.2024.01.17.01.46.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:46:41 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , AKASHI Takahiro , Masahisa Kojima Subject: [PATCH v2 1/3] efi_loader: avoid pointer access after calling efi_delete_handle Date: Wed, 17 Jan 2024 18:44:30 +0900 Message-Id: <20240117094432.1049168-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240117094432.1049168-1-masahisa.kojima@linaro.org> References: <20240117094432.1049168-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 | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 013842f077..ce46c1092a 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -707,35 +707,46 @@ 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)) return 0; + if (!handle) + return 0; + id = device_get_uclass_id(dev); switch (id) { 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 Wed Jan 17 09:44:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 763288 Delivered-To: patch@linaro.org Received: by 2002:a5d:6e5d:0:b0:337:62d3:c6d5 with SMTP id j29csp185648wrz; Wed, 17 Jan 2024 01:47:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHROFPUlWLFAYkT+BdeEFnsK8LkRsgQH+8Rcpv7dM9XCb/XaJaFfvpn+jbPPV/nT66vbult X-Received: by 2002:a05:6000:1b0a:b0:337:bd2f:8575 with SMTP id f10-20020a0560001b0a00b00337bd2f8575mr1321909wrz.122.1705484826893; Wed, 17 Jan 2024 01:47:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705484826; cv=none; d=google.com; s=arc-20160816; b=iLhxAF+HzVafLFtJHx8CzgxrCUbAgUqVlPAoNlliqjF9S2TYn33LMazCVlu+jIbwBx IVn9KjIxFrogo/5QMUKYlGrie/tOP7ccyKMkkjcgxJn0rU0IUmsAZWS1J6NYUExEtlEZ T5W/ZJBE6yB1omc2fFnE9tY4JLOqfWNHaJzT7PPJUJVW7vpNps1ypjLDrZiMbwFSGLlQ 69To6Nowg0kUebMfDlksBNxE2GA823wnmoboVq7Go/ZT6m45jxgcKOqF1C/s82FsIAcz qBnC1U3cLUQWzyR2/lVz5YBi9t4GP5HdvpIH2NDXYY5D5lgFzuhAXGnnxULAV+TzfPWQ kuWg== 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=/ho+PLVyTZdaqLEvAtRVLK3xm2WuFnKSJpTJE1JOfHA=; fh=90lSBw+wRfsPn+xaW0S3z+mfIwOpjwfjrVWi6OXSKN0=; b=hXhNmLJuzSmzu7iAUDY6s5ItSKFVu2grRp9bvNljEmRawqvFcNgWdYjK3TJTQQQTe3 7DOG/ehSiaV2gT0I5ywbuLJdCJtf1vir3+Fz0EtadQ/pqD15TMYTJ3SLDxBvf25x/dY9 wC0+NowYMEarDG9rVPSq7bjZEHzWiohRZaiJFGVzC3rI/Kp8YD6KZTLeY1q26a6TITeL ATyHA2lseRbGhnUdezpsCYrhotGL7l+t+dxyUbNKqtqtjhFDYHfpQ0UetebaKTWTouI4 l7I0oCwltvFwSvc7LnvS9IywNLhMUlRp2Ji4XNsFhAqwY5UXShm9GW5duHqSwwcLVN4q rKBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RiHWw7QC; 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=pass (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 e3-20020adfef03000000b003372d84058esi644291wro.380.2024.01.17.01.47.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:47:06 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=RiHWw7QC; 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=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 C665287B3D; Wed, 17 Jan 2024 10:46:55 +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="RiHWw7QC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B444287B30; Wed, 17 Jan 2024 10:46:53 +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-xc31.google.com (mail-oo1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) (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 166ED87B3D for ; Wed, 17 Jan 2024 10:46:50 +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-xc31.google.com with SMTP id 006d021491bc7-59502aa878aso4948120eaf.1 for ; Wed, 17 Jan 2024 01:46:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705484807; x=1706089607; 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=/ho+PLVyTZdaqLEvAtRVLK3xm2WuFnKSJpTJE1JOfHA=; b=RiHWw7QC68GUvwyuQmie5/F2P2sTi9f0Q3kmeNpQHf6Wis+nUNeNpA33qRVC4NbNXG 8ZfHaNkxc7ts3A1sbLvCWJt6ymHhxHU9qd/3yqQxFkRQPWBHV8TwD8BmW/Jo6K6s2BPv qv9o7LXaCFa9CaSVQX9DUru4C75Q2b+OfY5dkkTHTNceyOwyxJwrRBBYPTCB+VmDs6OS PeayBfX7T8t/bEpZv3ItFE1JUr+bFpOjljJ24jZ76N5BPXaWnZJWfhodOz/fFBVNTf8d briV98GbFjuRHbDooXyNjRPM7XWsRmb1moOCTCppL9DnOAEyHvcysdn1Teu5iQDu+5e+ kD8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705484807; x=1706089607; 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=/ho+PLVyTZdaqLEvAtRVLK3xm2WuFnKSJpTJE1JOfHA=; b=QZjhnoCUOoc0jwsO6mo/CXytMLxfbevWUf2JT/2KAsexoKS+Dm4iIuNrFguHb4uZED aiQ3zLNB2qJx9AtxpeO8L9un1rs9hrJmpBBGmZ1yF51zZCod+ZsOoVa3XVAOf+16GP+f ZAnjk15j+Ix+44yaOsPJ5PhmG4XXTMdg3C71YDyrKCBSTTYesM1iI1vUReqpZXF+bLVz vaC+Q6ORqQUyKCVTAuzhoSNjrS/6ABbKrtFzkk80A5PXTzYx/ovamF7SiIY4JSfp6sTH owjYvAv51mqWuNwIIZ4PJpM+EbCZeU8C5aWYoB+u1GX5MBo2nhZUyvqHTS0u89RFDZfO nHlA== X-Gm-Message-State: AOJu0YyXgO4DhA4ZLvZaz4ISoi9KZmXsGGaHQE6gEnH7Iq8XlBejKAZB 4KLfPxly5X1pDa+pb2xacNnOEfFnDcAsvygvTZQMW5dQkEE= X-Received: by 2002:a05:6358:6f0e:b0:175:5bd4:f418 with SMTP id r14-20020a0563586f0e00b001755bd4f418mr7093707rwn.65.1705484807289; Wed, 17 Jan 2024 01:46:47 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id t19-20020a056a00139300b006d9abaf83ebsm993880pfg.164.2024.01.17.01.46.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:46:46 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , AKASHI Takahiro , Masahisa Kojima Subject: [PATCH v2 2/3] efi_loader: create common function to free struct efi_disk_obj Date: Wed, 17 Jan 2024 18:44:31 +0900 Message-Id: <20240117094432.1049168-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240117094432.1049168-1-masahisa.kojima@linaro.org> References: <20240117094432.1049168-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 ce46c1092a..4897a7a7a8 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 Wed Jan 17 09:44:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 763289 Delivered-To: patch@linaro.org Received: by 2002:a5d:6e5d:0:b0:337:62d3:c6d5 with SMTP id j29csp185711wrz; Wed, 17 Jan 2024 01:47:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFKesl5f0h6dWLLm5VnvcVowmhwdzDTA3mPnm6rfU0Es2KakklHoSI58dsglCvdCiquCgI X-Received: by 2002:adf:e0c4:0:b0:337:aeee:4bae with SMTP id m4-20020adfe0c4000000b00337aeee4baemr1957143wri.47.1705484837106; Wed, 17 Jan 2024 01:47:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705484837; cv=none; d=google.com; s=arc-20160816; b=wPlpXGAcrrxPFBTAuJrrdiUHGfnjx+etg7pAC+t+xQWmrTMfDdu7i5OSzneOf4JXKL oTa/9ho2pk5aEHncTyFGaFEbN6+ZNBXb45ntcVF3cEna81JXP10mlGeEH1c9LrGw1xq2 LH2QiaMgRLsYJkgsxGhoHRUT6IgKiSPiAw+2NBn/xk8mm0ZyCLNdkXLcYWiaryB/JAtr A3SLiqAv8883WFIV/YtuNxKaC6z97Zm1Brw6+X7VaU75jzjedJO+sEoIATM7FMDN0+7r g7T9c/a4OTfnxxNcCkDMkf7ucFJkvzMT+xrsjcXCMXDopfKBCMCBNmlGFEq/89PkbdGs +SRg== 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=TBpcYrQWRI2JAJfzQUSkVa9gBNfch/09fTVSYRF+OE8=; fh=90lSBw+wRfsPn+xaW0S3z+mfIwOpjwfjrVWi6OXSKN0=; b=N8wDNqanEgq42cVZqnfRpieclxLSqsj0S+5+FKd3rRJU5ObZOrE6uelEP9NemJ6mLr 9G09kVRdlLs3hMj5NG7Y4xuUMw6c5iCTivvZAUDKqFiMRBzuf01V2j5Wi99LdR5JjHzu XaDRk72Fwn1kJeoTlzhJYvSjJcyCHH5fYzZ3MfORCcUH7XcyX1sb08k0jTWe8MbM6ewp PWltP1iw7AdTQYhducU3M1Rd7maF0Wh5KNCUxF2QJsZmOXB624iAbwPtqBtyzpmFQnkH W9pSqdQMfslmLHG0oEgpGEHHAR2Q9tB87AuFTVSEUSeLB1qazH3/EaMYT/BzI51C9DtY zZ0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JDxO+1ru; 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=pass (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 m23-20020a056000181700b003377dfeffa1si613788wrh.912.2024.01.17.01.47.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:47:17 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=JDxO+1ru; 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=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 501CF87B1C; Wed, 17 Jan 2024 10:46:58 +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="JDxO+1ru"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0992D87B1C; Wed, 17 Jan 2024 10:46:57 +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 469D187B48 for ; Wed, 17 Jan 2024 10:46:53 +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-5986d902ae6so4389416eaf.3 for ; Wed, 17 Jan 2024 01:46:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705484811; x=1706089611; 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=TBpcYrQWRI2JAJfzQUSkVa9gBNfch/09fTVSYRF+OE8=; b=JDxO+1ruqqDi9CP2HuQlsQ9XRSPV1AxPgArFLQ3zhrgJ63KDCkzJIbUdq9O3j6/Lzv 6mnuWCJSV2KM0K16e+CloNAH1PaV//QS/zyu3WKcW9LQy35MTinRiBEzV5kf0zhQ6He/ m2KzixbOfzpH46UPL/gILYIj+1BWfbNcbN/BSVHcPWRPEFccieRd2QkoLB3kYEfGmCAz bFDvUHeDOgd7ar1w/zJ6+A4nO8EH0+4SRkhFJ0GOcfam/2NFcLVBdt/vqLDwcu/uDrnC AhKvLhrX+qNOdP163ZAGkArhdkds9vT+/6SwatvIPrywbQuvD5LzF7KbFKduV9YpoVnY wlQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705484811; x=1706089611; 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=TBpcYrQWRI2JAJfzQUSkVa9gBNfch/09fTVSYRF+OE8=; b=qWXAIRSWfcSCage3HniCI4ywO2vOgzif72SNp2+4nHp+hqFtWKR6NT9erob3qBUzvu GircXpNq/7/AcHIyx/tVtS6gyhdL66RMg1C6hNZCDC0G2mFwjcXNkJHjA3myJJU1s8i2 ANKxGmgpzNl8jtHZIUb4+MDT/yALStBOYR0MJBwi+Za5fNg0gX5M0TkqoLhRDZr0KlFH JhHKOZtj4z60iR7j1e72C4yDqlfVdsjZHAkHua1WbraFwacamoilGfj8i8Uv99D/cW3d wfHNeJHtAYZXGQE6NYq2+a/kwwJ3+EEBnA3E1MnThENa0xec8EcyhdpnU5UBEzZBL2Dd PS5A== X-Gm-Message-State: AOJu0Yz4UGWCeCoVDORt51ueJK7+RhO9cHgPG6fKYVFmvdo0PZ0DJKDD eX/zw0gzlsRjpQFF1eat2/B/pqs/XPUjnGSaHF9MKGic3r8= X-Received: by 2002:a05:6359:2d05:b0:174:edd3:b3e9 with SMTP id rl5-20020a0563592d0500b00174edd3b3e9mr6330247rwb.38.1705484811510; Wed, 17 Jan 2024 01:46:51 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id h13-20020aa79f4d000000b006d92f081d9fsm1004698pfr.31.2024.01.17.01.46.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:46:50 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , AKASHI Takahiro , Masahisa Kojima Subject: [PATCH v2 3/3] efi_loader: return immediately in UCLASS_EFI_LOADER removal Date: Wed, 17 Jan 2024 18:44:32 +0900 Message-Id: <20240117094432.1049168-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240117094432.1049168-1-masahisa.kojima@linaro.org> References: <20240117094432.1049168-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 4897a7a7a8..cdf8a4560e 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -734,8 +734,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; @@ -747,10 +753,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. */