From patchwork Tue Jun 20 06:19:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 694430 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp143745wrm; Mon, 19 Jun 2023 23:20:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6EQPqYugBWRFR5LczuDkjNhW5AjY1Y9IIWSNUMNWuZvkTzm8XV+acOh9c6h8aLm8/eAh1h X-Received: by 2002:a6b:794d:0:b0:77e:3d2f:d1f4 with SMTP id j13-20020a6b794d000000b0077e3d2fd1f4mr4231501iop.15.1687242020259; Mon, 19 Jun 2023 23:20:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687242020; cv=none; d=google.com; s=arc-20160816; b=gYR8KtHYHEf6tt3frx96ziBIF4ap7LXc7G9xudpr7CUx3Gd+Cc+4NfCSSPdez3r7+2 4zyl1UlbqzQNDl5nBLTQiREm1nUKkCGZSGOaUrZrPy1gBOlWf8aX4BV07Deg6R36hxLB tP+gTkXz62RmOpesI613S3z5scmaI/jvAHEMqLKF2mVcBDzoZP+xk35stawxtOMqtUPP vSmG26n1hjyrNUk12Oh99Fn6lOv1/MgE5kH/OLEU9154C80MuSvGnulbviDlHJZJRx2p A9AzxA3TTi7iElxrTgPrvlM5UgwZZoEMnu9ymLKCZ04ISloSRAunqvrEnPB2qsALU0Is dMZQ== 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=e3+i1sJtqzLfxmZTa48YlUeLD6oSYsh1gFKhsfobpIs=; b=mronokaqzTgO8JcJ28aDGA8NC3clLNpc81zx1rrKx3ftqlribhveVAUn+jPcthLQ5k UQwApLINNFSlhngc+V5Yh8s392K9S2g+uJmejx1i5uHOD1ouKWz9wIkZ91EXhjSQvtEl PrBoiP8o8Lw8/0RCwl/CQw5+RHERhg3VkNWUEQgOPrxtZKKkcrc55UW0Xnf3op4Q/CPL JtkDc/1A2TYu8O7pfmEx9B4x4TOPxzjn29d8IYPNP0EPc9/kkfHMnfwSPtZEfd+MECZz 7buWkXI6XYCW+Yw0bRfpbo2evhc4HRU4irOvc3gWKbs0v5q4xGmsTAnb+87bFsVe4cv7 6ivg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xaJyPTET; 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 cp27-20020a056638481b00b00418a86d79a8si647671jab.184.2023.06.19.23.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 23:20:20 -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=@linaro.org header.s=google header.b=xaJyPTET; 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 2E6FC86342; Tue, 20 Jun 2023 08:19:52 +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="xaJyPTET"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2119686259; Tue, 20 Jun 2023 08:19:42 +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-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) (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 2751B86259 for ; Tue, 20 Jun 2023 08:19:38 +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=ilias.apalodimas@linaro.org Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-982a88ca610so511266566b.2 for ; Mon, 19 Jun 2023 23:19:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687241978; x=1689833978; 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=e3+i1sJtqzLfxmZTa48YlUeLD6oSYsh1gFKhsfobpIs=; b=xaJyPTETlCkrZeKEL4Q70zPy6Z9V41smCzfrT0e3DplrjDuO12d7D8feC8v9oPWbwy ouaPYiUFx2Y1jLjC4gVffmjFVzVvVm419L4Ko26Zf95sI7JFKLlHXA4CDESGT6Ns/Vfh 694MPjEN4Bfz8tszjRFubezuI1w2CNCdn0TduVqWcWQs3DH0oyDSlRTGyaNI2bj1e64X atd4QBUARgGxOv+wAy25Xjy9ZuAwCVz7afRVIZZWVru0+k0+7DVdj/KGnY91kXLBnaLm 982CGj6V/a8Aiut/qc5XoId4os7ZmhFOhH6pt2tzRED2zmpTZeT9l7sEhV9PMZKizlMl hJNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687241978; x=1689833978; 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=e3+i1sJtqzLfxmZTa48YlUeLD6oSYsh1gFKhsfobpIs=; b=eLaLqgoCQth6loRYOzRm0zgMj5AxoGlP4JM5RXVOocge1l0EdBlHaU9kkiABI2DvTf eyAnpisMJXhe4Ho6wPs8Xx/BzOQA3YASVoUETkeYlV9vXVsH9tfwZQUD+mZ8F5HNmW7c fommcTExZCqZOx/w79RLHUQyTtwtTdfcDcBt/nvWlLYzZeLq2vbNthwjToIGldmLVvm7 4Rgx4fmSmKWEjx6NUrVkbszoxIAbCpDzTX8pFCJqnRbRItYjvrGxCP89IeC7Ep1R0NMN QvicADy4ncAk9g5rkJWrq5ACzmYaAVW+tNhZ9UMG0OD6di8Xo6tXq/kaMSfTqCiytK4X CnXA== X-Gm-Message-State: AC+VfDxU12g/VePLeWgOiT0wPwyPM8ldptw3owyi2jXq30BdRjHK5bJB LsT+q0R/uAq2O8DT6wkA7DSZJcFC/M8RYPXycrBDnQ== X-Received: by 2002:a17:906:7312:b0:96a:3119:ac0 with SMTP id di18-20020a170906731200b0096a31190ac0mr8367510ejc.69.1687241977824; Mon, 19 Jun 2023 23:19:37 -0700 (PDT) Received: from localhost.localdomain (ppp089210114029.access.hol.gr. [89.210.114.29]) by smtp.gmail.com with ESMTPSA id a22-20020a1709063a5600b00988e699d07fsm729988ejf.112.2023.06.19.23.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 23:19:37 -0700 (PDT) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt Subject: [PATCH 2/4 v2] efi_loader: check the status of disconnected drivers Date: Tue, 20 Jun 2023 09:19:29 +0300 Message-Id: <20230620061932.113292-3-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230620061932.113292-1-ilias.apalodimas@linaro.org> References: <20230620061932.113292-1-ilias.apalodimas@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_uninstall_protocol() calls efi_disconnect_all_drivers() but never checks the return value. Instead it tries to identify protocols that are still open after closing the ones that were opened with EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL, EFI_OPEN_PROTOCOL_GET_PROTOCOL and EFI_OPEN_PROTOCOL_TEST_PROTOCOL. Instead of doing that, check the return value early and exit if disconnecting the drivers failed. Also reconnect all the drivers of a handle if protocols are still found on the handle after disconnecting controllers and closing the remaining protocols. While at it fix a memory leak and properly free the opened protocol information when closing a protocol. Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- lib/efi_loader/efi_boottime.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) -- 2.40.1 diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index d44562d8f4e0..bfcd913dfad9 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1374,17 +1374,23 @@ static efi_status_t efi_uninstall_protocol if (r != EFI_SUCCESS) goto out; /* Disconnect controllers */ - efi_disconnect_all_drivers(efiobj, protocol, NULL); + r = efi_disconnect_all_drivers(efiobj, protocol, NULL); + if (r != EFI_SUCCESS) { + r = EFI_ACCESS_DENIED; + goto out; + } /* Close protocol */ list_for_each_entry_safe(item, pos, &handler->open_infos, link) { if (item->info.attributes == EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL || item->info.attributes == EFI_OPEN_PROTOCOL_GET_PROTOCOL || item->info.attributes == EFI_OPEN_PROTOCOL_TEST_PROTOCOL) - list_del(&item->link); + efi_delete_open_info(item); } + /* if agents didn't close the protocols properly */ if (!list_empty(&handler->open_infos)) { r = EFI_ACCESS_DENIED; + EFI_CALL(efi_connect_controller(handle, NULL, NULL, true)); goto out; } r = efi_remove_protocol(handle, protocol, protocol_interface);