From patchwork Fri Dec 6 17:18:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adriano Cordova X-Patchwork-Id: 2019387 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JODsz0lJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y4dK644Mgz1yRK for ; Sat, 7 Dec 2024 04:19:06 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6A49989737; Fri, 6 Dec 2024 18:18:59 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="JODsz0lJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5C3B989739; Fri, 6 Dec 2024 18:18:58 +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,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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 1BF5D8964E for ; Fri, 6 Dec 2024 18:18:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=adrianox@gmail.com Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-215770613dbso15465305ad.2 for ; Fri, 06 Dec 2024 09:18:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733505534; x=1734110334; 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=Q3WLB+VlvJaVRRB41n4OyNGHxrF+25PmuihgMN9TPJ4=; b=JODsz0lJ4K1A3J+/IwQ8Iv1zWkRBuid6Pr41wKlRc3Q6TuuBqrTNeI5FaGotXpSshd +2PNM5ZhUW7CdxGMWsDFSHherVTkZNrpasI4zY+kvEB2y+gjpw6mRxTc1aFLXz3Ym16x kzJg+mLpyf3ZCz3DwQI+5zkmRjW+kM9fgCOb0TT4j4zGQnvTKerL9YSHVtdQ5mcqYBaj W7Xx4GXcPjMI8KRJ7479HGCP8krA8nM/Wpw+9KOWthJImkjlkNg2nDu5dwNzcmd1HVi/ 6FG7OqHkv7+OSycJRves4kFpDQqln82Vw752+PVh7XW2wrsExUmOMBIQqi1BtN+FE65y mq4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733505534; x=1734110334; 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=Q3WLB+VlvJaVRRB41n4OyNGHxrF+25PmuihgMN9TPJ4=; b=fkIGwRdJpDuSYSXhOdq5/oMoW2WO3ONNVuMsniG0ZAC15zNH+fRcxGVozGRVE8GiZw HFIuVHc5K+8qP5uH33XZcRpXhkgZ6FNPfS5wjfE0L5D1S9oLPQCH6rLLiedscVOTvyTd TpTzzzn2F87AkhUQ0XwLOae+laW6l+bRrvNFSRDeRVOaRQFi8ZHmdpjl2XBSHC3FagQf P3ABMkLF37QwnrsrrIb7fRBd7kHpMtiAj0cuxSdtP0TzvP9v1iHvjXj6RKfVbY7k36Ms rV7Kg9JF+6z/kf8dXUwdoNwrEt7E+fGjqwD12arf2BJHrbE28vrQhAr7BjRKteLB7Kcc pKJQ== X-Gm-Message-State: AOJu0Yz67GK1EuSQMIegypjWIWXVkHx+Qd70RpswRpzvx0GJ+wmybFGW uT+eshq4r07SD+VPezugC9U28KmyqzBj1YO6TgoUDYzwrj4b2wJdHIhueed5rHs= X-Gm-Gg: ASbGnctz+geQ5GPekkmNRbhz7SBEELxvUfVrRU00e9EA8qNtR9c8hcp9GqqCdrC45jb wIRTYM7ti7uKYl9WNCOjaAX3QZLlV5WtCX4+QAZs6YAwVpuW1EK1TvcFhf1iSfnFEz2cUhD4o5U /6P1FMDtMOz06Ij/+9Cq8p+RsSxyk9Ph9jLEeUXeNtyXCGfcHYBZuCVyxRam/f4V7/quSuCbb0+ z2es2YfhcsjHu60WtMrYJkiUH/WXa0J7jzPGzEf+EsO5KhNQrX/tgO4eA== X-Google-Smtp-Source: AGHT+IF/siAyyfmZYXu6jacj4iS6W36hdYvkb4HUWeDSpCJWt6VyC+5DVFYBTNFRTTI7oMC/SIaNfg== X-Received: by 2002:a17:902:d4cb:b0:215:b8b6:d2e2 with SMTP id d9443c01a7336-21614da9da0mr58725785ad.40.1733505533093; Fri, 06 Dec 2024 09:18:53 -0800 (PST) Received: from adriano.. ([191.119.55.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-215f8f263b9sm30970025ad.226.2024.12.06.09.18.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 09:18:52 -0800 (PST) From: Adriano Cordova X-Google-Original-From: Adriano Cordova To: u-boot@lists.denx.de Cc: joe.hershberger@ni.com, rfried.dev@gmail.com, jerome.forissier@linaro.org, xypron.glpk@gmx.de, ilias.apalodimas@linaro.org, trini@konsulko.com, Adriano Cordova Subject: [PATCH v2 1/2] efi_loader: Expose efi_reinstall_protocol_interface in efi_loader.h Date: Fri, 6 Dec 2024 14:18:34 -0300 Message-ID: <20241206171835.2403418-2-adriano.cordova@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241206171835.2403418-1-adriano.cordova@canonical.com> References: <20241206171835.2403418-1-adriano.cordova@canonical.com> 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 This is done so that the device path protocol interface of the network device can be changed internally by u-boot when a new bootfile gets downloaded. Signed-off-by: Adriano Cordova Reviewed-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- Changes in v2: added commit message include/efi_loader.h | 5 +++++ lib/efi_loader/efi_boottime.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index 9afbec35eb..0d858c1e12 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -711,6 +711,11 @@ efi_status_t efi_search_protocol(const efi_handle_t handle, efi_status_t efi_add_protocol(const efi_handle_t handle, const efi_guid_t *protocol, void *protocol_interface); +/* Reinstall a protocol on a handle */ +efi_status_t EFIAPI efi_reinstall_protocol_interface( + efi_handle_t handle, + const efi_guid_t *protocol, + void *old_interface, void *new_interface); /* Open protocol */ efi_status_t efi_protocol_open(struct efi_handler *handler, void **protocol_interface, void *agent_handle, diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 080e7f78ae..58716fa795 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -3733,7 +3733,7 @@ out: * * Return: status code */ -static efi_status_t EFIAPI efi_reinstall_protocol_interface( +efi_status_t EFIAPI efi_reinstall_protocol_interface( efi_handle_t handle, const efi_guid_t *protocol, void *old_interface, void *new_interface) { From patchwork Fri Dec 6 17:18:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adriano Cordova X-Patchwork-Id: 2019388 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=VJaN8f4d; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y4dKH4RJfz1yRK for ; Sat, 7 Dec 2024 04:19:15 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C19F98971E; Fri, 6 Dec 2024 18:19:01 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="VJaN8f4d"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 58F1A89373; Fri, 6 Dec 2024 18:19:00 +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,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0: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 2F9D589736 for ; Fri, 6 Dec 2024 18:18:57 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=adrianox@gmail.com Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-21577f65bdeso19733105ad.0 for ; Fri, 06 Dec 2024 09:18:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733505536; x=1734110336; 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=xIOPoE/Vrg7UJNzD1lAnsdaAGdI60hCrSeNBj/hliHo=; b=VJaN8f4ddNDDs9H+aPyEQ+jzpsrRqGZV2klevUGS//LzNcFNyEVcmLIU6WUQKZWnM9 C1bPPMRPERmrLCNTwr17una9fU5z40K4I85mWU1eFO115Fol3frLzq2FCJJpBB2SwZiM SAV7D31Bp7w909MlCFkwl7yxB6dhPGL/th71sp2KFZIAzto1hUI6DzUl1w7rQee1Y37L PzISeFKEIWhZ0qgUjonIcifOq/50CSGkyjnbIjlncO7A24vfKXKQFFXEwgID3G89x/N7 XSuwCrPv46xUGJ6PQErPIMwou5a3qfyjVg0W5CQBjHf2nvCfo2sKLZzZZwkTzPxY7Rmi BHnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733505536; x=1734110336; 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=xIOPoE/Vrg7UJNzD1lAnsdaAGdI60hCrSeNBj/hliHo=; b=C40b239hV6IeFdNG9Xt9NSAjVTkRenlWMPDZLZFduhNxPazp/qNoGSTTUAFbo/6PKa R7zxYg/hsG5HhOEOCcCCFPObybVLW7OUDg6PSUJVion4tnRt+YWV0JjtIEey96ethIqo 5Jc3A+ztqO7dwVba4lALW20zt2aQU/ir4icRcRXvmhRcI68mv2aiVsaaH5BzkOQhdoCC VDnZuK6jNsIFzVaQradlkLCX8DnWeOqxRDq10YRb97hcVbJF3dGKpeZfGn5OF6WBmTkW 80NZApKMsEiIWPs1HLB1AL8SZig9PC8BkFXbknrqpQdGaUFyTNmx3NxfTVS9qe4S9rw7 AXxg== X-Gm-Message-State: AOJu0Yza0ywNzaQ8Gm3qhY9k+vKHWjRlPDoJpy3lTA9sDgh0c4q5VzUE PkUKe5agfLFvJ1ovsaJ4STFDOavckQT9OgyfXNnDXbmndlp4PCdV3QD4lfaheGA= X-Gm-Gg: ASbGncsnQ59dVEMoDX+KB+I9aRXTLCkfAJtoo9DWUaF3kVdqSsTSZ1VHmEqgr8uW5C2 eujNP0HeDYRRivw8eY0AbF54oeEmDtEqi9TakXu4ZNA/cnlsKcIGaBtE0WSSsqFQPYtJQmtXA8j 13OnPwHYhUHXZt0wVZzd6mbrAMispY81XMxs/qiRq/kbLua5+vZbSSfIAAZMxoBGygXbJ3KHeSI W7KFroIDLb9NYdY3kzes3/XBdy0u3tr5Z7QlgUgUvA+dPZB2T+e6lIRLg== X-Google-Smtp-Source: AGHT+IHaldVPEFeWpnAO+3f1Ho9lWwKfHdDT8mHBK7+fuB4hYNa3bdmIEC4mv3CEf/woJ+FAU/NtZg== X-Received: by 2002:a17:903:2309:b0:215:beb2:1039 with SMTP id d9443c01a7336-215f3c56b8cmr131325145ad.4.1733505535695; Fri, 06 Dec 2024 09:18:55 -0800 (PST) Received: from adriano.. ([191.119.55.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-215f8f263b9sm30970025ad.226.2024.12.06.09.18.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 09:18:55 -0800 (PST) From: Adriano Cordova X-Google-Original-From: Adriano Cordova To: u-boot@lists.denx.de Cc: joe.hershberger@ni.com, rfried.dev@gmail.com, jerome.forissier@linaro.org, xypron.glpk@gmx.de, ilias.apalodimas@linaro.org, trini@konsulko.com, Adriano Cordova Subject: [PATCH v2 2/2] efi_loader: efi_net: let efi_net_set_dp properly update the device path Date: Fri, 6 Dec 2024 14:18:35 -0300 Message-ID: <20241206171835.2403418-3-adriano.cordova@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241206171835.2403418-1-adriano.cordova@canonical.com> References: <20241206171835.2403418-1-adriano.cordova@canonical.com> 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 This commit fixes an use after free introduced in Commit e55a4acb54 (" efi_loader: net: set EFI bootdevice device path to HTTP when loaded from wget"). The logic in efi_net_set_dp is reworked so that when the function is invoked it not only changes the value of the static variable net_dp (this is how the function was implemented in e55a4acb54) but also updates the protocol interface of the device path protocol in case efi has started. Fixes: e55a4acb54e8 ("efi_loader: net: set EFI bootdevice device path to HTTP when loaded from wget") Signed-off-by: Adriano Cordova Reported-by: Tom Rini Tested-by: Tom Rini --- Changes in v2: use reinstall_protocol_interface() and new_net_dp in the body of efi_net_set_dp() lib/efi_loader/efi_net.c | 61 ++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/lib/efi_loader/efi_net.c b/lib/efi_loader/efi_net.c index 67593ef50c..ac8e54639b 100644 --- a/lib/efi_loader/efi_net.c +++ b/lib/efi_loader/efi_net.c @@ -925,12 +925,15 @@ efi_status_t efi_net_register(void) &netobj->net); if (r != EFI_SUCCESS) goto failure_to_add_protocol; - if (!net_dp) - efi_net_set_dp("Net", NULL); - r = efi_add_protocol(&netobj->header, &efi_guid_device_path, - net_dp); + + if (net_dp) + r = efi_add_protocol(&netobj->header, &efi_guid_device_path, + net_dp); + else + r = efi_net_set_dp("Net", NULL); if (r != EFI_SUCCESS) goto failure_to_add_protocol; + r = efi_add_protocol(&netobj->header, &efi_pxe_base_code_protocol_guid, &netobj->pxe); if (r != EFI_SUCCESS) @@ -1055,18 +1058,58 @@ out_of_resources: */ efi_status_t efi_net_set_dp(const char *dev, const char *server) { - efi_free_pool(net_dp); + efi_status_t ret; + struct efi_handler *phandler; + struct efi_device_path *old_net_dp, *new_net_dp; - net_dp = NULL; + old_net_dp = net_dp; + new_net_dp = NULL; if (!strcmp(dev, "Net")) - net_dp = efi_dp_from_eth(); + new_net_dp = efi_dp_from_eth(); else if (!strcmp(dev, "Http")) - net_dp = efi_dp_from_http(server); + new_net_dp = efi_dp_from_http(server); - if (!net_dp) + if (!new_net_dp) { return EFI_OUT_OF_RESOURCES; + } + + // If netobj is not started yet, end here. + if (!netobj) { + goto exit; + } + + phandler = NULL; + efi_search_protocol(&netobj->header, &efi_guid_device_path, &phandler); + + // If the device path protocol is not yet installed, install it + if (!phandler) + goto add; + + // If it is already installed, try to update it + ret = efi_reinstall_protocol_interface(&netobj->header, &efi_guid_device_path, + old_net_dp, new_net_dp); + if (ret != EFI_SUCCESS) + goto error; + + net_dp = new_net_dp; + efi_free_pool(old_net_dp); return EFI_SUCCESS; +add: + ret = efi_add_protocol(&netobj->header, &efi_guid_device_path, + new_net_dp); + if (ret != EFI_SUCCESS) + goto error; +exit: + net_dp = new_net_dp; + efi_free_pool(old_net_dp); + + return ret; +error: + // Failed, restore + efi_free_pool(new_net_dp); + + return ret; } /**