From patchwork Wed Sep 7 08:20:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 603349 Delivered-To: patch@linaro.org Received: by 2002:a05:6504:2213:b0:1da:4c02:b5e7 with SMTP id z19csp3624790ltw; Wed, 7 Sep 2022 01:20:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR6SCggIfynkyJCbUATyKhifScMVBdc0Xl/z7M/YTyZ4rcvkFDKiHs9yzVL3r9tp1jt4aTId X-Received: by 2002:a05:6402:50ca:b0:447:3355:76e3 with SMTP id h10-20020a05640250ca00b00447335576e3mr2120725edb.72.1662538826051; Wed, 07 Sep 2022 01:20:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662538826; cv=none; d=google.com; s=arc-20160816; b=BPFzqBzd2mVyEnvpdFSVxvVcKZTNihhyuIjS6xBNcUcxZrf3/ujtJZwApXCNwPGYnp j/JjoxYmGeBbmHFZ6gZE6psnqbbYbPepcx3kh/o+nBJP5/HFKB4gW34nj7jqk2/D6y1i k3oZWWoHPiwTtEQ+vCy+h/8qKVJQ5vr+N4FSVbWthd5E4X/UZTt5GAma/GtdFdtxpitH fMDhTjpWiV+4M19NxO5FNOJVItQGahPtnPNlyB2t++//4cEo0yNmcb2tYD/RMPTcBBOe 0eTIUyS3A4hJLAq4Ms/St27BKsfJB9vNB4tgvJbnKfXFURhid/YVhGa4ZcaxmSYhcN2v pADA== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=0uKSAP8jrALlyYk5E1BxvTjUY3D9gv+eIBS+m/7Bm+4=; b=La1v7i6GJUkYlJ9MXJsh6fcDQZedGhEIQ87/Qn4NTJLezZ1upnZOuU8rjpHD5Cl8Ip q8kuaKuu2iKy+exjboXbZAlizAnzMbHUZHwXN8eSHWLV8r6j+hqgKyGMNjo/ZY2dMR0R RGjYpB7CteLjCYjr3cGxXjBeaPmrBn7UGBojTOHIngljHsp9JI1rtzqloW2gBrpU72Ze u5wl/dxcZSGYND3QSqGXVZp5PWkzAo59KGrz6QXDlV5akEr9VvGrboToJjpvdmGcfJp+ UUbW2fZd77vgmliOgyBdsEqeXq8zYM1EmhUrCHGeNJHCwCXLTMINooMXqRu680bQlJUQ SF+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AhhkkRlE; 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 r8-20020a50aac8000000b00448a3d713ffsi10911850edc.292.2022.09.07.01.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 01:20:26 -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=AhhkkRlE; 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 A2D9A84A34; Wed, 7 Sep 2022 10:20:22 +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="AhhkkRlE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6BD2A84A46; Wed, 7 Sep 2022 10:20:21 +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.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-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (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 4517284228 for ; Wed, 7 Sep 2022 10:20:19 +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=etienne.carriere@linaro.org Received: by mail-wm1-x32d.google.com with SMTP id az24-20020a05600c601800b003a842e4983cso9031237wmb.0 for ; Wed, 07 Sep 2022 01:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=0uKSAP8jrALlyYk5E1BxvTjUY3D9gv+eIBS+m/7Bm+4=; b=AhhkkRlEeWgWFgQ1V4LX4kC+/VmhV7kUsgXAGw2Q57zwyVXsKk5qi/v249cLx+S7hm QPjSxLFGvXSMUnAzlq70vEjyXzBnt+l0AwTYKURynKkJYXhTETQZEjIchhW3c+XLNM09 L+8k62qz92fvlRe5Ra7XSE9R4b83y1rFkluXvjGnx4V3cmBk6Vb0vYt8wNN+T0sk6byS rK9eAsJdauoyYifnvDyYZ5dixiAbvtI+VTlaqr8Zse9bJwccmgqFENlqiFakFgHFAzKW wbDr8KFxm5oVWtsxpmRQmF/KGhkQ71qr3fcUSA6xuKgzSN7Zi/0KUi+DLgHhHG/aG1DR mShA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=0uKSAP8jrALlyYk5E1BxvTjUY3D9gv+eIBS+m/7Bm+4=; b=F/54jYNYScqQySamkHbnQSAKFlD6tEzwaIdP1nfnpqEgo6o7/YDS44rLE7MODzs1oE OepYrku+L8eCJro6WExagkepAA3n/5gB1BqWML+qXnb9SkgCcY6KyAheaZb+JJDqp5AE YveN54eqw/c0OnrZ4HpAD0HixDPaclvLeIO7twG/gpu2lEjXHPc+bUrY58u4SZrNMrq+ nWyz644zuGYHrvQdjkKbK+GfKietASzPyJSMIY+XJ6OOFG+sVcz7o4GNHrAIUdnNxAGe i9s+O2W0GzzRM4gPi/Zr5shgP/fIG/r2jHHD+nwx/yvHwTWZC0g8RXHsOdKj5ojTE80a FwqQ== X-Gm-Message-State: ACgBeo2zkkgeWeAwcMmF/DU1cUpPvsCzH59gKxWNzvSGDiHRdz2mp2f4 YRyeZEr4h5DY1csaE8Tti3rHcrbNEYoCzA== X-Received: by 2002:a7b:c451:0:b0:3a6:829a:6102 with SMTP id l17-20020a7bc451000000b003a6829a6102mr16086966wmi.12.1662538818544; Wed, 07 Sep 2022 01:20:18 -0700 (PDT) Received: from lmecxl1178.lme.st.com ([2a04:cec0:1055:c67c:d26:f459:e285:dcad]) by smtp.gmail.com with ESMTPSA id r1-20020a5d4e41000000b00228bf773b1fsm8702687wrt.7.2022.09.07.01.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 01:20:17 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: AKASHI Takahiro , Heinrich Schuchardt , Ilias Apalodimas , Etienne Carriere Subject: [PATCH] [RFC] lib: efi_loader: don't delete invalid handles Date: Wed, 7 Sep 2022 10:20:13 +0200 Message-Id: <20220907082013.66879-1-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.25.1 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.6 at phobos.denx.de X-Virus-Status: Clean Changes efi_delete_handle() to not free EFI handles that are not related to EFI objects. This change tries to resolved an issue seen since U-Boot v2022.07 in which EFI ExitBootService attempts to release some EFI handles twice. The issue was seen booting a EFI shell that invokes 'connect -r' and then boots a Linux kernel. Execution of connect command makes EFI subsystem to bind a block device for each root block devices EFI handles. However these EFI device handles are already bound to a driver and we can have 2 registered devices relating to the same EFI handler. On ExitBootService, the loop removing the devices makes these EFI handles to be released twice which corrupts memory. This patch prevents the memory release operation caused by the issue but I don't think this patch is the right way to addresse the problem. Any help will be much appreciated. Signed-off-by: Etienne Carriere --- lib/efi_loader/efi_boottime.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 4da64b5d29..e38990ace2 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -619,9 +619,15 @@ efi_status_t efi_remove_all_protocols(const efi_handle_t handle) */ void efi_delete_handle(efi_handle_t handle) { + efi_status_t ret; + if (!handle) return; - efi_remove_all_protocols(handle); + + ret = efi_remove_all_protocols(handle); + if (ret == EFI_INVALID_PARAMETER) + return; + list_del(&handle->link); free(handle); }