From patchwork Sun Jan 12 03:42:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 856751 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:385:e875:8a9e with SMTP id k28csp888622wrc; Sat, 11 Jan 2025 19:42:30 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW+VQVoAprEklACSRAIiDTl0lOIYHC0J7dAzzQHZ5CkPyEehegaiKdKiZtXegsJWju6l0l9pg==@linaro.org X-Google-Smtp-Source: AGHT+IHxwMDMekPj5knd8SNpWRzIc/YMviJp1337cHJ9GDAJGZ1p9eb046Do4YXwKmgQc+xaEXAF X-Received: by 2002:a05:6402:5109:b0:5d0:cfad:f71 with SMTP id 4fb4d7f45d1cf-5d972e7110amr34585001a12.32.1736653350516; Sat, 11 Jan 2025 19:42:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1736653350; cv=none; d=google.com; s=arc-20240605; b=IwuJPg1/1qr6bYEva4jTPf47BCMxVHjplf3I2MAd9FtdMFYJxx28lPpSN3UKxwX14O sfsKK3gwEDfpDNUEyMIewtGW7lkvFEhPyqglt3xaIXKknvlGfZS8JZTRVXUj/TjQbNM6 PszyAvXUoHBwQSQlxKkx/o5nnb7/BR3RHhWrqDOuFvY54UKewaey9EQEUiuyFt+P6nQW fLwXkUmDZ7rQrAlv/kwuDVlTi0dlXIdXJ2H/Dw8TqWN7K5xzPIoIvPnJ3Gx8yFKwOJSn TQPIcTpe1F3nKy3sCHozPEjApMbdM3PN7UMhrsQtkU+k9prtL+gl38SCKHpfNWhK8Xrd Iojg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=8GqWMM7WOX8rE18EQNu5ubLw9ojN7anB4FsnTFrS9L8=; fh=vtNonh0NiHxYepiXbrigFY/LCQLAmEiW7N1qKnEE3F4=; b=UKzSB1Rfpqg5ZO6zAB8Y8xKU1k7WwntHoSagBhjF/6PMe2Thww3P8nVVbFbLvkktpA 3oGG1od5jv5iu8OEA2JGBxjWzUnoiY2NxFORQjqaAV29OEHXRhu5KFPChicEdKTi9yQm vIgO8DL1NHDAoMqXBDqCKObc8qLQBV+AjvXR0Uo6XebLWnpQBhKHYwop1F8JXHOLbnCs bWHt4X97ZhWeJg3l/VIgP/Afl8bZJClDoY/7e8W/VKSk5sZHtsod+aPsBWsXa0zI6pzj GkDg1LAPo16J1VsyDxXerMNWjEQ2YW49/uOF1CDkFDu1jTWgyHG4S9chpxmHmQg+36U+ U72w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nfEoPwoq; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5d99f0524c5si3618077a12.512.2025.01.11.19.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jan 2025 19:42:30 -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=nfEoPwoq; 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; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 77C66805E9; Sun, 12 Jan 2025 04:42:20 +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="nfEoPwoq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 22210801F5; Sun, 12 Jan 2025 04:42:19 +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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) (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 E6658801F5 for ; Sun, 12 Jan 2025 04:42:16 +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=semen.protsenko@linaro.org Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-71e2bb84fe3so1768596a34.1 for ; Sat, 11 Jan 2025 19:42:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736653335; x=1737258135; 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=8GqWMM7WOX8rE18EQNu5ubLw9ojN7anB4FsnTFrS9L8=; b=nfEoPwoqSVeIKRnL+Vlg2jb3cSreZPFQG5OSlMMyBUnJfjpuM3YXgoqf0DSsp7gNMZ 0p8ulNqXhnPeXGx7vG5uHLzt3+NuExAHaLgGC9jsHbGVTPPu5IuU/GVeWSS2MaQLXwMN iQldvREHix5mSGYsK1xTWBRct3geIyHWboqyVXO9jTQqgAWZM4Psc6r9lBaDeWwhHGqN B77ge0Qfts35a4oEMVcXI49vnoSFxeBfNbBASfv7VlLj5bXQX6nOiarZHhjFwt3BXOP1 CGKNEIszykJPbBOxuRej3mkMTURf4SAE//DaWkzgGMjpOhysCMdrAxK8A1HeEuZY/2/Q 25xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736653335; x=1737258135; 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=8GqWMM7WOX8rE18EQNu5ubLw9ojN7anB4FsnTFrS9L8=; b=hmw6EJticyardGeIxChE+FNXj9ni7I+AXxezA/iq+VdALLzkSOVmEAjswM7SV0U+gv 47oxx8esCMkehRMcyDLWet8gMKGvFoUzkbgdEW0lLXTrXbm8ZbEam5ceFcq0cReWthHK hQQrDbJ9juGq20ZdKeDoMs4iYJaIaCwGUNoNDyWdrX4wTYHI/qahgmFbz+O8/7thNIKz vSAaA2lc3/ILctzNbXRLkus+3XiWhkoC1e4QTGjTpveWJUx2/YZlvnRR235GBqv/FRyq oARmcxc3S/QxuWerhx3p92gj1mihy6TNN8G4CPZ/WEurlMBehjOxTTxYOWHNbW9TPHYp BQJw== X-Forwarded-Encrypted: i=1; AJvYcCUfrzdM9VXd3Kb7jXTbwKjyjYGnS0bc7NjxzyCbhcX0yKMrnWvm8dt2I/h2EzfkkDdQ4L91DME=@lists.denx.de X-Gm-Message-State: AOJu0YwpQjyOwiMT8HCnmK/tKBkMMCqsGcQeA4nh4IH9N8xQK0vCrJ7a +aJPGHPeznvWvbXsVceZM1TvK44x/uj4r+KIFKgk8655ZNjSAIKe3DTEayZKUPc= X-Gm-Gg: ASbGnct6eMkh6SUxR8SWMONeHUv9pgeFYCRoIGnA6js/WcZd90JZZ9ls0W22mSIUyjg /sa4MxCpd7LXnRsQF8b861H4GbGi52ABbgV2VWhOUOz0yDQZBX1eoH3oyUutUMMo5Cdu2l6AyBG CrB0bzLzKij0Au/kWXR+P57baQtppRxRI+vCq2IvzG3t/jI4UkslbcDKDgjh88C+oRfBwxGGw92 fn6gSoQGZO3fRwPM/KfwoFUs4TfBTbIKlaCP4P12yTXOIPgb14uKNBtHn/ZoC4tzmE= X-Received: by 2002:a05:6830:90b:b0:71d:ffa1:6b0a with SMTP id 46e09a7af769-721e2f00d87mr8782251a34.23.1736653335643; Sat, 11 Jan 2025 19:42:15 -0800 (PST) Received: from localhost ([2605:a601:a0f4:b000:264b:feff:fe59:d7f7]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7231861c020sm2313928a34.49.2025.01.11.19.42.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jan 2025 19:42:15 -0800 (PST) From: Sam Protsenko To: Simon Glass , Tom Rini Cc: Heinrich Schuchardt , Ilias Apalodimas , Martyn Welch , u-boot@lists.denx.de Subject: [PATCH 1/3] bootstd: Fix memleak on errors in bootmeth_setup_iter_order() Date: Sat, 11 Jan 2025 21:42:11 -0600 Message-Id: <20250112034213.13153-2-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250112034213.13153-1-semen.protsenko@linaro.org> References: <20250112034213.13153-1-semen.protsenko@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 Free memory allocated for 'order' (array of bootmeths) on error paths in bootmeth_setup_iter_order() function. Fixes: c627cfc14c08 ("bootstd: Allow scanning for global bootmeths separately") Fixes: 10d16faa436c ("bootstd: Detect empty bootmeth") Signed-off-by: Sam Protsenko --- boot/bootmeth-uclass.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/boot/bootmeth-uclass.c b/boot/bootmeth-uclass.c index 5b5fea39b3b3..ff36da78d5a1 100644 --- a/boot/bootmeth-uclass.c +++ b/boot/bootmeth-uclass.c @@ -133,8 +133,10 @@ int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global) * We don't support skipping global bootmeths. Instead, the user * should omit them from the ordering */ - if (!include_global) - return log_msg_ret("glob", -EPERM); + if (!include_global) { + ret = log_msg_ret("glob", -EPERM); + goto err_order; + } memcpy(order, std->bootmeth_order, count * sizeof(struct bootmeth *)); @@ -188,8 +190,10 @@ int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global) } count = upto; } - if (!count) - return log_msg_ret("count2", -ENOENT); + if (!count) { + ret = log_msg_ret("count2", -ENOENT); + goto err_order; + } if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) && include_global && iter->first_glob_method != -1 && iter->first_glob_method != count) { @@ -200,6 +204,10 @@ int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global) iter->num_methods = count; return 0; + +err_order: + free(order); + return ret; } int bootmeth_set_order(const char *order_str) From patchwork Sun Jan 12 03:42:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 856752 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:385:e875:8a9e with SMTP id k28csp888653wrc; Sat, 11 Jan 2025 19:42:39 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXS1EKeHSEnlJLJmKy9mvfq9jKuxJzCt+m6sBihQ/6TzcQ5hWCsGBHbIWD1/Ti+wzCqS/uxPg==@linaro.org X-Google-Smtp-Source: AGHT+IGG4WA5V1GT4RFQyLokermrXXlniV4FK2qu0yCbVt0uxdTzdJsdw3Z7z7U19evzCjFIpZ8q X-Received: by 2002:a05:6000:1847:b0:385:f060:b7fc with SMTP id ffacd0b85a97d-38a8730a60cmr15167440f8f.25.1736653359443; Sat, 11 Jan 2025 19:42:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1736653359; cv=none; d=google.com; s=arc-20240605; b=NZntHCBO/Ss+TTm3aUorcHu04i0le1dX6/qgtg/pZL1C1jinw9wpmZg61WkBEK2aol SwxOwxyPXIIxITKXrjPakrs/seFWzkzYIebk9mbokTdXuxVXJGR+tAB+iWpJLtOlkLAn +Hdm9LPwuJFyyxE8VFS8DESA4mIgW6Oh5uW6Q8tmJ5YniU9/q8t6qo2nRb0BPLMgkCQQ xUlmdU7ExePnbBcJMDWqfG59dg8SrrN/3ZSxkscL5AdwMFeKtFQX629JbezLDRaNKzj0 e3JjJ/6BlPUusBACMiRB9fXGhpCLR/yJfZhtFqNFYUT8dJhmyZob+bEcLAVHLLztIKmu Ql7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=b5u5G11aunGI+aml/J793NesimzKzJxjlVD8EIiicUM=; fh=k6Bi/zktlcLW2mH/Nn4HYUPxicJGvzlLPh2gLrXis7w=; b=Ob1PV/Fk8MdD3/N45E8bqlWS/SoqRRG4WtjvE5tNHgziDRNJxS7qmEZRhJCImpCnOQ afissRQzG5eD21KTa2XbcIZR1PvT/DcDWeXwyHHed3Y+nq0pSwcZMrk1fe9Ioh2tOKyS HnZvDZWY3G/7FM4SX23ccvuCgwtzEyqmR2qncPLRU0akv02L+t13e6A0NWcmBH+ATng/ FKpZf1fEnvI5oci8Qj4a7hU/aSaeexTvwkga4leBo9+/hret3QW6RiWgoUXmHuAPvDPz zzuP6epYK2WqVR1aZUnCmn8g2iCMW5x8Sf4nar/Q0/qwYa4OVn9E2JBqSuM+t3fIFOO0 ujFg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PpiTpjgu; 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; dara=neutral header.i=@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 ffacd0b85a97d-38a8e4d3b33si4947816f8f.599.2025.01.11.19.42.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jan 2025 19:42:39 -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=PpiTpjgu; 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; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CEE1B801F5; Sun, 12 Jan 2025 04:42:21 +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="PpiTpjgu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2E6EF80628; Sun, 12 Jan 2025 04:42:20 +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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) (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 EB0F1805E9 for ; Sun, 12 Jan 2025 04:42:17 +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=semen.protsenko@linaro.org Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-2a88c7fabdeso1546745fac.1 for ; Sat, 11 Jan 2025 19:42:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736653337; x=1737258137; 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=b5u5G11aunGI+aml/J793NesimzKzJxjlVD8EIiicUM=; b=PpiTpjguuWJ+o2gdhfOYFVuNFx9YwIsZ1yc7kqL3dpzh+L2Chxs354G8TV1fwQZxhZ blTQFT7rQ34XymrJYkEiBwPdaj0ka79Wr2xKwUwwqQR+/jnfPR+nv13iP/1cdGQJ2/in dNxwuE5k+grioKIZE2mvpvw0pCLDmnfpR4ZGfz3f4SjRfzkIdPCG9M0j0R6sYr466Rd9 37SwRhPtGR01jxuh2U4OQ7LtpUjKszNZwRnge18jDKuOZ1xOomyHQmp6jsZLu8y0uVPt raPvSpv9YIVb3lR2Vn/hGVAATK7MLNHOWPSCkweEKbeU/8faaqvebJjAe4tI0ePZTTts rGnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736653337; x=1737258137; 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=b5u5G11aunGI+aml/J793NesimzKzJxjlVD8EIiicUM=; b=lKF9Dbbbjses5bRmg60iMFTgo7UIwM1UywtmNtoNrZG/iFdIxTQSMS4bBVeNhzOa21 IJA04rDREebR6exi5fUrfUJS0xrgTGG+MUOQPNc0beFvQy435aLqZhbYr3GZ5U+fJjxC SzA+rmDJ9z9S3hKdV5sROXNV/VxdFoM/kSP0kXD+CePyZxel7hWxLYmdTajKR2DwqJ8P xYLsv5aCUkSrRhsdjOKgy5pFqRKYs4ACMHIwenfTx0m6iUhkvX/izCUh29Vmj+SpbsCB oXtlJ8gEPg2ahWpGIau6C3hqkRX5ukBXqpGLjr0GUTV1kkrr5M6jHXDucpvBJUjJekBE kH1w== X-Forwarded-Encrypted: i=1; AJvYcCVNASz4KWbmYAbKlJblSxgWNc/z21sNYSgt0MgGVuX6VTk3V2+Zl7lmmSilwTpRSoQfqc2m85I=@lists.denx.de X-Gm-Message-State: AOJu0YzyFCP8+TH+I09IQaKY4eLcbh0uW/iotp/qtCyP5ZBo8sKlYFZJ zWzCn7fNExMMCN/Z81WBXYYWLp6GahAAYWJjqGBcPx68ZzfDAiQL3sVZIoi4Yzk= X-Gm-Gg: ASbGnctNz4Elkkxdohao2omPKTJE7afMu9paXEEfUfovhBrCxxXLhRTxdG2yISUEvPW 8MywpBoHtV5oOSAIwv65sbzDaWycc3/b5+gDRjfIpiJmViMlm22/C8U4AIVUGbRtQ8kt/ubGAxp XlJ8C4zrlc3+n+Ptmwqfpc7umSEGNgTlZZEW5LouBmtKoC2r6T5H34ZF7GMdmGzigw5NnfPAlp2 wQsl/osER9jaIzZl2ALw47dkxV02nC9r/jc95tv+a3JmRBu7GHDye/vf3+U8+yNY0o= X-Received: by 2002:a05:6870:1712:b0:29e:6bcd:3ba7 with SMTP id 586e51a60fabf-2aa069191f6mr8474027fac.28.1736653336672; Sat, 11 Jan 2025 19:42:16 -0800 (PST) Received: from localhost ([2605:a601:a0f4:b000:264b:feff:fe59:d7f7]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-2ad809af70bsm2558462fac.36.2025.01.11.19.42.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jan 2025 19:42:16 -0800 (PST) From: Sam Protsenko To: Simon Glass , Tom Rini Cc: Heinrich Schuchardt , Ilias Apalodimas , Martyn Welch , u-boot@lists.denx.de Subject: [PATCH 2/3] bootstd: Probe bootmeth devices for bootmeths env var Date: Sat, 11 Jan 2025 21:42:12 -0600 Message-Id: <20250112034213.13153-3-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250112034213.13153-1-semen.protsenko@linaro.org> References: <20250112034213.13153-1-semen.protsenko@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 Specifying efi_mgr in 'bootmeths' environment variable leads to NULL pointer dereference when 'bootflow scan' is executed, with call trace like this: priv->fake_dev // NULL pointer dereference .read_bootflow = efi_mgr_read_bootflow() bootmeth_get_bootflow() bootflow_check() bootflow_scan_first() do_bootflow_scan() 'bootflow scan -l' That happens because in case when 'bootmeths' env var is defined the bootmeth_efi_mgr driver is not probed, and the memory for its private data isn't allocated by .priv_auto. In case when 'bootmeths' env var is not defined, the std->bootmeth_count is 0, and the execution flow in bootmeth_setup_iter_order() takes "no ordering" path, which in turn runs uclass_get_device_by_seq() -> ... -> device_probe(), so issue isn't present there. But when 'bootmeths' is defined and contains efi_mgr, the std->bootmeth_count > 0, so bootmeth_setup_iter_order() follows the "we have an ordering" path, where devices are not probed. In other words: 'bootmeths' defined 'bootmeths' not defined -------------------------------------------------------- priv == NULL priv != NULL ^ ^ | device_alloc_priv() no probe device_of_to_plat() ^ device_probe() | uclass_get_device_tail() dev = order[i] uclass_get_device_by_seq() ^ ^ | have an ordering | no ordering +----------------+---------------+ | bootmeth_setup_iter_order() bootflow_scan_first() do_bootflow_scan() Add an explicit device_probe() call in "we have an ordering" case to fix the issue. Fixes: c627cfc14c08 ("bootstd: Allow scanning for global bootmeths separately") Signed-off-by: Sam Protsenko --- boot/bootmeth-uclass.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/boot/bootmeth-uclass.c b/boot/bootmeth-uclass.c index ff36da78d5a1..049389403191 100644 --- a/boot/bootmeth-uclass.c +++ b/boot/bootmeth-uclass.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -146,6 +147,12 @@ int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global) struct bootmeth_uc_plat *ucp; bool is_global; + ret = device_probe(dev); + if (ret) { + ret = log_msg_ret("probe", ret); + goto err_order; + } + ucp = dev_get_uclass_plat(dev); is_global = ucp->flags & BOOTMETHF_GLOBAL; From patchwork Sun Jan 12 03:42:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 856753 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:385:e875:8a9e with SMTP id k28csp888686wrc; Sat, 11 Jan 2025 19:42:48 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVW/a4UWhbxt2w4/Gq7F35y4CISx6870SnLM76WM0moNhPDSgudGDRBLEESyuaYApR/FIyDGQ==@linaro.org X-Google-Smtp-Source: AGHT+IFLiDkXiPCtfmS9aqZPtZdU69fp5asLfRn/H03TigvUMs2v1QDCg1SF9f7R+aKRthFW7t5g X-Received: by 2002:a5d:5985:0:b0:386:3f3e:ab11 with SMTP id ffacd0b85a97d-38a87312e0dmr15012246f8f.34.1736653368422; Sat, 11 Jan 2025 19:42:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1736653368; cv=none; d=google.com; s=arc-20240605; b=UOuVFp4/ftwpOwNa6WYy8Pd2nuV21BAmhNWX7SDqUTn5YThXFXMZxzm533UdbO0iaE 4A2y+38ft870P4NnwFMEUhSU+vnWnzATexV9qofgD/AMFim47wwMQmLkz4o96s+Q7g7c JzbqE3rY2bsmyzloAagUptTUjt3GDybrHuwRitlpqp5hKKoGFgbhVsUqdBarUoobUHlj pJlrBhg2hQejsSyhC/XrQ72kAgsVFdyze5ykGwrEUnGHb5eXbHwOuMrPw7US8pe6AZZ6 NWpmdVwjsFXMuvSvw6nlrFyUckc4Y+CtJXnWt+zWjinZPKfnhawtEQEcBLbJzMH6zc6K X6Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=4CVzJn1pvV3iidfWSp3Dfec/PldMJk5u6eX97PcXybY=; fh=gnQ8reBK2HNLN8nME+nLzSXc1rs71U4Dg9GKCn+l8lM=; b=X+3/50cykylPyTiYD4rEn89yWqeNRFiHaMQVhgXhp5657WR2wFQ7lWOtZV+X+Y7lvY 6THA7rUmOwh+TBtv4t60pUccMT4o8C4aMYN9NErgRVhHrFdo1lDAQMVgu1eIQhtMyu8Z KUce7w1CzyVVhaNAE3K4JOiyasiL0Iw8KA92gRTZRBfdreXpIEZmieZ7JEoBzJkYOgl+ VlOx3Z5mhHIXgHSAlU62YZp866JMaVjdhSwLhuFrKKLZCkNNvixEjUdzqWK+X6TZW8+i RMphVzK9hCNLBNhFS6eP1V35KNlOGgj3hwiDSjWRFqLD20HyuPRqnqzBF2udlCD/te6r EK+w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DT3+LLiB; 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; dara=neutral header.i=@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 ffacd0b85a97d-38a8e4df030si4818595f8f.814.2025.01.11.19.42.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jan 2025 19:42:48 -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=DT3+LLiB; 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; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2E17580602; Sun, 12 Jan 2025 04:42:23 +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="DT3+LLiB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2D1AA8066C; Sun, 12 Jan 2025 04:42:21 +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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) (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 EF8DA801BE for ; Sun, 12 Jan 2025 04:42:18 +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=semen.protsenko@linaro.org Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-71e1158fe3eso1795685a34.1 for ; Sat, 11 Jan 2025 19:42:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736653338; x=1737258138; 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=4CVzJn1pvV3iidfWSp3Dfec/PldMJk5u6eX97PcXybY=; b=DT3+LLiBCFnxQWqlGdDeCGYOK1hw4wmzWz3TLzAZgRUKVpeRhj2kKf7glAopWmzwnc B7i/QFXFDA0eLT2UZTxXk6JzuU5GxuJkEAysPSBf4Ti7Y9S8T0o6n08WszOaX2vjH9Qw MYl/LWAJO4cRa7inc1lAgu/bCyLPndNiXWCg8OufnXjULSvtHyZLiKvYMALq3gotm0/D PkJQrbGoqQ0nrFuNb7FMlDc4/PssdEkw+BUthQuVvXVRcsMLCnFXSXF0yDe3/0Z/na++ y3ExGKNMSw+wCg1GsJrQ1NQbljF5+J5f7X7PnKU729W2Lm2fLRa0vRFx2h8IP/JoeUf6 ePlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736653338; x=1737258138; 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=4CVzJn1pvV3iidfWSp3Dfec/PldMJk5u6eX97PcXybY=; b=ATmaebc6FFy6+Ihc3GMqy2v0tfse4Xa21SDiY6p6+fWtVLBW8CLo4i90Dw78cUw975 xJtS1/56Xt1kyijMDEcUgeFL3+3KdBqpRKiAAmMQh9p/23naICx2X54Rw2XzLIF8lS48 LQ6cwDsR8IQt0tuAMI92UDjoyRnG6lftr6Fe+gHJQAfTInwwXO8QQqXnC2IT/dQm2EBj r07kWmxjGNgTwDpctCTzDcBlhIMfasnqaTtdmILfUy4TW2Zrg/Q1+v24OvEjLjU3Bb0V 3WqxNbNWvAZrsdsNeOoxB8v1GWW+dtf99nlsR5bgK/0Bw88hWxi8aGR+5WAUpgfEgfEe wfZQ== X-Forwarded-Encrypted: i=1; AJvYcCXI0D+NXuCsxvOOiNRb0e9m+sRIcwzZpRPKPhLjpAoxprEtUmi3LWqmdzgd5PCVUawe1Bfw9Fw=@lists.denx.de X-Gm-Message-State: AOJu0YyOe8+cTqGmfXNJHspDjUTyFmtOC2T7PejpJ1I3RGCezFccvyTO H9rB5i8pN1/X6Bc6OHsUIm8h0U4VSyLgdO5gBIW1XrXx5l004JLsSeGAYDfvGlc= X-Gm-Gg: ASbGncsLYsnB5hNTVRmB+HuFO2mwEU0xmebdPcpMJMosuSaE6onchYrfl8/B4GNI71g jvzgiG0tEVenkjSIKRL2LTwyR75EsAz2FlQkMWGYxpSZ+Qbymy9Xt2jNewVYR9b3b/2uDpXwjxK Ua4I0c/G5DzJidWkxMgj+PBTqOsq/p7AYGp7NidTF5lnnW/akP5VcwUb9pofmqkIlomOrSwNyu5 YrgrjZqT+0jgG88B00rwaW2pbInd/LumjXut0cS10WmWaxPDy9gOu5pqa61BlI0ufk= X-Received: by 2002:a05:6830:2aa1:b0:71e:b43:e061 with SMTP id 46e09a7af769-721e2cce5fcmr11951180a34.0.1736653337724; Sat, 11 Jan 2025 19:42:17 -0800 (PST) Received: from localhost ([2605:a601:a0f4:b000:264b:feff:fe59:d7f7]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7231862a2easm2307870a34.67.2025.01.11.19.42.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jan 2025 19:42:17 -0800 (PST) From: Sam Protsenko To: Simon Glass , Tom Rini Cc: Heinrich Schuchardt , Ilias Apalodimas , Martyn Welch , u-boot@lists.denx.de Subject: [PATCH 3/3] bootstd: Fix incorrect struct name in bootmeth_setup_iter_order() Date: Sat, 11 Jan 2025 21:42:13 -0600 Message-Id: <20250112034213.13153-4-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250112034213.13153-1-semen.protsenko@linaro.org> References: <20250112034213.13153-1-semen.protsenko@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 There is no such thing as struct bootmeth, it's probably a typo. This issue doesn't affect the execution as it's a pointer, and pointer sizes are the same for all data types. But it can be confusing, so make it struct udevice, as it should be. Fixes: a950d31abe98 ("bootstd: Add the bootmeth uclass and helpers") Signed-off-by: Sam Protsenko --- boot/bootmeth-uclass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot/bootmeth-uclass.c b/boot/bootmeth-uclass.c index 049389403191..2496e8c1d8a8 100644 --- a/boot/bootmeth-uclass.c +++ b/boot/bootmeth-uclass.c @@ -139,7 +139,7 @@ int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global) goto err_order; } memcpy(order, std->bootmeth_order, - count * sizeof(struct bootmeth *)); + count * sizeof(struct udevice *)); if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) { for (i = 0; i < count; i++) {