Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FSL_HELO_FAKE, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08E6BC4338F for ; Thu, 12 Aug 2021 23:30:30 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 33A8760C3E for ; Thu, 12 Aug 2021 23:30:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 33A8760C3E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9A85882DAD; Fri, 13 Aug 2021 01:30:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.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=google.com header.i=@google.com header.b="IcPIMXhR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AFE2C82DB1; Thu, 12 Aug 2021 17:28:49 +0200 (CEST) Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450: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 5A7A382DB3 for ; Thu, 12 Aug 2021 17:28:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ptosi@google.com Received: by mail-wm1-x32f.google.com with SMTP id k5-20020a05600c1c85b02902e699a4d20cso4888024wms.2 for ; Thu, 12 Aug 2021 08:28:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding; bh=SO9r1AA68ydLmPZGojmO1CSvCIimdugIsHM08/rdhM8=; b=IcPIMXhR7k3EC2JqsroEe885ynURN/8X47oa36NR7Dj38B/qhCn2trJSDt0doBSP2D +TYenCXKY/kF9ZMNx7Ks1Ioqp18aEoSD61JXxb5Jg2EedEgs85a1+CNeqsM2UokJxO+V XJIwQzXarpJLjxSc0HwwVNTSUPmWsKHPDoDnn19qjos9cVqgU6/cCCEESNvbDQ7hCL23 QhIuAwXHKTZR4ljzGUSR+cuUUzAxiBMIZu8uNaHOVC9QHkik7K+nbf1Zk7FixE+z0TYZ Jcv3oHX2uMxHeeeGW0bfQz47mZILvWMrzjmYs2a5HR/CXborJr9Uwc0TxLcsIhbboAcZ E7jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding; bh=SO9r1AA68ydLmPZGojmO1CSvCIimdugIsHM08/rdhM8=; b=jy+gHGzYdPWr6q8z0nDWlj7E8C5Ree2qI4Xy2Cjx4VG2ialLO7/wax+dLEGVwwRkpK Vi/uSrPjy//vMau+c23VURkyJpe6kL08ewAimIo9+ruxkWt65M6idZ9894+vC4rDpZ9M cTr1Y2UF/7284b3wYP4o6PIfQD5d6qJ8BCw94AzdqaugwHlmswcvsB/5MRou+AhvBVlr XFxWSnoqC5cxMk828zlW9xEV2/gz4SyaFLgzbGmZ71/QuB+p/Xamnx7C2u11Ul5HE0IY GHqpEgRhBKaTv3RLMFkT5fVM4hibLPMqlAH0cj+vzqlw+bBzAcyuc9MSGcgDD2TXHKuS eGJA== X-Gm-Message-State: AOAM532A5Ksw2Y7rTa2AwCE6FGVWCSNnEOO0b9+FBdyBKVuhcQ5RoEMC VJ0YkYCpAgvU/qXGu/j3T4hQG1gB4ha/ik8W X-Google-Smtp-Source: ABdhPJwTtVgY99K70jxf7eScILZ+KUPZdZeZbYyEDCwONcvF+E+M7+/j8T2fT4F8NQ9Zs6o6MQmKFw== X-Received: by 2002:a05:600c:510d:: with SMTP id o13mr4710805wms.123.1628782118388; Thu, 12 Aug 2021 08:28:38 -0700 (PDT) Received: from google.com (203.75.199.104.bc.googleusercontent.com. [104.199.75.203]) by smtp.gmail.com with ESMTPSA id g35sm10893700wmp.9.2021.08.12.08.28.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Aug 2021 08:28:37 -0700 (PDT) Date: Thu, 12 Aug 2021 15:28:31 +0000 From: =?utf-8?Q?Pierre-Cl=C3=A9ment?= Tosi To: u-boot@lists.denx.de Cc: Marek Vasut , Wolfgang Denk , Joe Hershberger , =?utf-8?Q?Pierre-Cl=C3=A9ment?= Tosi Subject: [PATCH] env: Make _init() expect _INVALID when _IS_NOWHERE Message-ID: <20210812152831.vucrpalduzj25h26@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Fri, 13 Aug 2021 01:30:25 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean Avoid applying the "fix" introduced by commit 5557eec01cbf ("env: Fix invalid env handling in env_init()") to the environment "nowhere". This is necessary as that commit, by setting the return value of env_init() to -ENOENT if gd->env_valid is ENV_INVALID, forces that function to reset gd->env_valid to ENV_VALID. By doing so, it breaks the assumption (required by ENV_IS_NOWHERE) that gd->env_valid must be ENV_INVALID. This, in turn, results in env_relocate() calling env_load() (it should not), which itself, calls U_BOOT_ENV_LOCATION(nowhere).load() i.e. env_nowhere_load(). That function, being implemented under the assumption mentioned above, calls env_set_default(), which in turn, seeing that gd->env_valid is ENV_VALID (it should not), tries to dereference whatever lies in gd->env_addr (most likely garbage), leading to a faulty memory access. Note that other env_locations might be concerned by this bug but that this commit only intends to fix it for when ENV_IS_NOWHERE. Fixes: 5557eec01cbf ("env: Fix invalid env handling in env_init()") Signed-off-by: Pierre-Clément Tosi --- env/env.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/env/env.c b/env/env.c index e534008006..0a0f234747 100644 --- a/env/env.c +++ b/env/env.c @@ -336,7 +336,7 @@ int env_init(void) debug("%s: Environment %s init done (ret=%d)\n", __func__, drv->name, ret); - if (gd->env_valid == ENV_INVALID) + if (gd->env_valid == ENV_INVALID && drv->location != ENVL_NOWHERE) ret = -ENOENT; } -- 2.32.0.605.g8dce9f2422-goog -- Pierre