From patchwork Thu Sep 8 06:18:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 603799 Delivered-To: patch@linaro.org Received: by 2002:a05:6504:2213:b0:1da:4c02:b5e7 with SMTP id z19csp4246682ltw; Wed, 7 Sep 2022 23:18:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR5KrfEsu8XWAvxwiI7zS9Ws0Bw8wauE8EhjIqhqtOLdeinoB6wvjSS7a3C6jKcBsp9vtQEy X-Received: by 2002:aa7:c61a:0:b0:44e:7d1d:7814 with SMTP id h26-20020aa7c61a000000b0044e7d1d7814mr5718178edq.44.1662617905944; Wed, 07 Sep 2022 23:18:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662617905; cv=none; d=google.com; s=arc-20160816; b=YAsbzE13mbQI9gehulhJxN4in1F7rcjQwM2ej/hc82w+nz/9yCJSU5Oh8S2Yg2jNwZ iiaeMrLf+L1TUWjD6n68etGwDu3Za9g7CVtZJn8WULHDt9qj47v6W5PJn4Dz89mt8vyA wUQEmiiZQjUnD5DnWRKZDo0J/eUFZHg92sedLqeY7FGtvyOAvKBqzcsIZvJSkRZgfeHE y2iLO8CEkSoJOxxN0mPYmvqMcEFXSADVR36YMLMAMfoXYFvuzxVDVD7iKZSSq9bWAUVY Ront4J2fTqLklij9B3QFI/gAHh0FB3sc4q4evxEw3vK1XZJrHgQcXpZTlZ5roklP7wFS sB3w== 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=mvm9Z5SbsIaxvtrHOn4VHDvDIricaCa9UuFhuwNvYkE=; b=Cf1YwLTDnkskq0RMxOiqxGNxAT6glBwo9IpYdzzvO42LSM9EOhcP6P0uB8pTb+yvbX b8YgKumLSJry6tgaEXA+srJtCLvE3raJ7zuq/Ukyfr20OwK4VYHTOOggUb1KloVZdo4u SmlEpZMCswjXwPuGEl6Ta+4zdGdywWXVHTyfgExMBqo6Zb8i78AYuygEx68fnR+jlFd8 HEVUzIsQad1XfuSymByh4p2ftaaVggBrPWfWLXagX7I1mvHVMm3g9B49jDJ4eFC4C/fA kvWcbhgafNCx+gr8O4LKjiJk9hzGdgBaKQenRuocd6FcvaBkqAMirFZiwKmiEojntvX+ 3hyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=khV1R6xc; 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=canonical.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id y20-20020aa7ce94000000b00447fc23b420si7647148edv.165.2022.09.07.23.18.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 23:18:25 -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; dkim=pass header.i=@canonical.com header.s=20210705 header.b=khV1R6xc; 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=canonical.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3538284133; Thu, 8 Sep 2022 08:18:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com 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=canonical.com header.i=@canonical.com header.b="khV1R6xc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A709184594; Thu, 8 Sep 2022 08:18: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,DKIMWL_WL_HIGH, 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 smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3DE3D8403D for ; Thu, 8 Sep 2022 08:18:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from LT2ubnt.fritz.box (ip-084-118-157-002.um23.pools.vodafone-ip.de [84.118.157.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id 01C16416E4; Thu, 8 Sep 2022 06:18:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1662617897; bh=mvm9Z5SbsIaxvtrHOn4VHDvDIricaCa9UuFhuwNvYkE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=khV1R6xcro9Xlo29dPN/Q1nwCRcUusSyEwKlioMz3zqkXbX3H/IK+kYaJkR+3W4Pi oJw5zZiKmgkSgW7hasc0o9kDxhNU1Tv/o9bkqWZfjOfjslSJMrWN+vjeMU4mfkVUrs xGU6OaLmrSTM8S6PrUd5JZMAXISKuyvl3lQYqmjDZ2PVda4kmYRn5Hzl+a43wNGSzz XCqlCAyea0rKXN+aTl5CSIknIWmH46gQ2X9/x2S4o1TKZ56yugaLub2an5zwgzQswH s0Z0VWBpzr9jhEzS76UroRI11EzIGqSQ/UjVXXTXUAxAdFYgIEWu7Ed7QzSQ2WzWl8 6q6U9R+2YT6SA== From: Heinrich Schuchardt To: Ilias Apalodimas Cc: u-boot@lists.denx.de, Etienne Carriere , Simon Glass , AKASHI Takahiro , Heinrich Schuchardt Subject: [PATCH v2 1/1] lib: efi_loader: don't delete invalid handles Date: Thu, 8 Sep 2022 08:18:13 +0200 Message-Id: <20220908061813.30400-1-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.37.2 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 From: Etienne Carriere From: Etienne Carriere Change efi_delete_handle() to not free EFI handles twice. This change tries to resolved an issue seen since U-Boot v2022.07 in which 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 but does not resolve the underlying problem. Signed-off-by: Etienne Carriere Add log message. Reviewed-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- v2: add log message remove superfluous NULL test tweak commit message --- lib/efi_loader/efi_boottime.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 4da64b5d29..6f7333638a 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -619,9 +619,14 @@ efi_status_t efi_remove_all_protocols(const efi_handle_t handle) */ void efi_delete_handle(efi_handle_t handle) { - if (!handle) + efi_status_t ret; + + ret = efi_remove_all_protocols(handle); + if (ret == EFI_INVALID_PARAMETER) { + log_err("Can't remove invalid handle %p\n", handle); return; - efi_remove_all_protocols(handle); + } + list_del(&handle->link); free(handle); }