From patchwork Wed Jun 19 21:23:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 805653 Delivered-To: patch@linaro.org Received: by 2002:a5d:508d:0:b0:362:4979:7f74 with SMTP id a13csp20477wrt; Wed, 19 Jun 2024 14:23:36 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVCHI5JPMjJRkod5MeCHaB9Q0bKVJz2TLqIbej/8XJ317pw0jNUDPFXKj2R67Xo2Lbsh46ek0Pp9J+f0FgbMQeU X-Google-Smtp-Source: AGHT+IHdBuw4n+8vuRVodeb7LqMQIjubL+mGVzJaU11xljPAq+O3FzkTkYPpwYTYMRXUwuHalglE X-Received: by 2002:a50:d593:0:b0:57c:fc75:408c with SMTP id 4fb4d7f45d1cf-57d07e63da5mr2712449a12.19.1718832216722; Wed, 19 Jun 2024 14:23:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718832216; cv=none; d=google.com; s=arc-20160816; b=fljV5AzPV3b/HujR82N1kCB9ll/8uGXpW5LYB81IVXmXE0g/nGuPTTDa2NyXynGs12 TsZIUw8Zcoua70NXx6H0+rwAyVgen63g2Fg5y+wSvqD7pJio+XemoCtc923VC3SVFKcU CaQJpkzifUnKhchIi/RXwcNK67+cBAgU1cBhKj/EuY40iQM07TvR3rvozUlbZUHt8hCr H85uvlwZefI29yh38w4YnhIIki4iYwUIV6S3T4dYhKCIwrlNPQjMrznKw69TDaYXqOKl SItHz/Awj+y37Gji88pEH2Nnyouau2csORCemC4KYBfrkhuowByehv9mCsoaT1MZeyn5 JeiQ== 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=uq7P1K781PJfTuQYFqdxa/EpTMsg/ZlpqIfKJ4dCE5k=; fh=CuGY6PEHJ9fjcpg3mgSw3Xksps+sZkmNrrcPCAS+7oc=; b=wC0frcD01utVt+oGZrma0HtdRDXzLsFbJ5QlNyQ+Q2jAoMfZR5tp8ziY2vcY870RhN lx+bdmnzWRlIlfqqe5VL5TGTmLMh8Og/glBuGm6l+XgwBfCY2c2SR9olPdEVCvrEo98A QMFQSaayS3sAYTIm7w+hbgiNNiomJbmf/hxSImaFlImhPpv/bhMfp1trCPDoqF/9QLNi DbREgh33ObMqManiCXBLTa5CcH0YW6IV6tyYYxUvdq3MBFL34iDQJ8sSS0ywJ8JYyypi IP+AS/6lGfPRVkWYN/01+sdFkaiSw7SFqPzvVISMsbBIshos/RaaDaCfrIO4MlvM++Hp EH5g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Quk9/EAv"; 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 4fb4d7f45d1cf-57d1603f040si616929a12.258.2024.06.19.14.23.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jun 2024 14:23:36 -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="Quk9/EAv"; 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 907F98840F; Wed, 19 Jun 2024 23:23:35 +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="Quk9/EAv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3857B88485; Wed, 19 Jun 2024 23:23:34 +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-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) (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 035B7882E8 for ; Wed, 19 Jun 2024 23:23:31 +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=semen.protsenko@linaro.org Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-25c9af0102cso142663fac.0 for ; Wed, 19 Jun 2024 14:23:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718832211; x=1719437011; darn=lists.denx.de; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=uq7P1K781PJfTuQYFqdxa/EpTMsg/ZlpqIfKJ4dCE5k=; b=Quk9/EAvlsHYQCJ2p8XKgegXv21eQDmAaxGMkuoiURVXz6C/YpLkvM89cKz7+nJN6B 1E9w574UsqUKEi2vaah22kONfHvPi3WD9KPOAoONNFWznmVfsl4jVv0/bbagAj4DS0MD 82ksFxOBdxkb9408nGME6roO2glIyBeNd93gDHfm7589Ed43cA/4dtv79bwTzewPEXok O5d3Z0rJwLqx1IEUVnoGLD9oulf5gZQW7CPXrikyBKppPc9gnsio36HvPbnU5EKd4HpH HeBcdQLiSL5hJCKS63acof0UT4xuk9GqeVr+BFuYbZJknUnUHj+gJXlMZiwWrysEm7K6 bksg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718832211; x=1719437011; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uq7P1K781PJfTuQYFqdxa/EpTMsg/ZlpqIfKJ4dCE5k=; b=BBv++Y7SZCJ35b4Prhs8DrfjGgO440MdCJwVvZ2Z1NQGexmabzMeEoKk/hq4jX1eDt IoBerLwoG8PDeYv2XhFniAmlvqEYIQ8597lPDYpYrbHYDNSTFgCERJ4UpBUIm247cSE2 wn8C+HrVOxYuKUKkbHcIDvbvQ6gMghckqPqF0f7g9i8ev3kscCeT7QTGaH02jGLzefYj WWKyzAbpBT2aUS2EC/a8j3e+zBICdNoZ+AOOlwHLTUU3IC/L1o27QD4ROL1TRoZW9tKG B7AutYbGf5Ar9j3/CagDe1JYGhHWIxpuNMuBY0TZQWZ2U9U23YboPQ+bFEVm412CjcWz MqUA== X-Forwarded-Encrypted: i=1; AJvYcCUdiBCeEo84mTxvBm4VJ6RbdJBf8pD37OvPEtQOozPpOU6o7H4nqxuD8pkYpk3bvFyWwPK/zxdhUQt2UWgbhZ2JotiiyA== X-Gm-Message-State: AOJu0YzPbZ0lFayg2xLJz3LsZ+fpbE5JvpRyw5TCu+bZqEAVX1azjvUi b58r4jVwMeIu1zu7UGyRY0muEvkLnZ9YLeQXtKEZ7c3MzPHsWkkBUlS6w/bxzdI= X-Received: by 2002:a05:6871:1cc:b0:258:38d5:652b with SMTP id 586e51a60fabf-25c94901693mr4343154fac.1.1718832210653; Wed, 19 Jun 2024 14:23:30 -0700 (PDT) Received: from localhost ([136.62.192.75]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-25699395c3fsm3922629fac.57.2024.06.19.14.23.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jun 2024 14:23:30 -0700 (PDT) From: Sam Protsenko To: Tom Rini Cc: Heinrich Schuchardt , Joshua Watt , Simon Glass , Lukasz Majewski , u-boot@lists.denx.de Subject: [PATCH] cmd: gpt: Fix freeing gpt_pte in gpt_verify() Date: Wed, 19 Jun 2024 16:23:30 -0500 Message-Id: <20240619212330.24842-1-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.39.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.8 at phobos.denx.de X-Virus-Status: Clean In case when either gpt_verify_headers() or gpt_verify_partitions() fails, the memory allocated for gpt_pte will be freed in those functions internally, but gpt_pte will still contain non-NULL dangling pointer. The attempt to free it in those cases in gpt_verify() leads to "use after free" error, which leads to a "Synchronous abort" exception. This issue was found by running the next command on the device with incorrect partition table: => gpt verify mmc 0 $partitions which results to: No partition list provided - only basic check "Synchronous Abort" handler, esr 0x96000021, far 0xba247bff .... Fix the issue by only freeing gpt_pte if none of those functions failed. Fixes: bbb9ffac6066 ("gpt: command: Extend gpt command to support GPT table verification") Signed-off-by: Sam Protsenko --- cmd/gpt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/gpt.c b/cmd/gpt.c index 7aaf1889a5ac..98e1185014ed 100644 --- a/cmd/gpt.c +++ b/cmd/gpt.c @@ -683,7 +683,8 @@ static int gpt_verify(struct blk_desc *blk_dev_desc, const char *str_part) free(str_disk_guid); free(partitions); out: - free(gpt_pte); + if (!ret) + free(gpt_pte); return ret; }