Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id B0962C433F5 for ; Wed, 30 Mar 2022 17:06:00 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 094EC840EA; Wed, 30 Mar 2022 19:05:59 +0200 (CEST) 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="d2UN8dSN"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5E3E2840F6; Wed, 30 Mar 2022 19:05:57 +0200 (CEST) Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) (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 A96E183FF8 for ; Wed, 30 Mar 2022 19:05:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qk1-x733.google.com with SMTP id v15so17159316qkg.8 for ; Wed, 30 Mar 2022 10:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=cdpIRbv+EVNcAqZViz40aKze2MA8/+R35v52TTB/NxY=; b=d2UN8dSN1QxsK9SPhLAKFkCT/pqlCgjoHJmTBwszVz377D7cQyLwxI8Ablzo3Wkg7Y jEIS1Oefbv4Shze7s1uEDGO5OgYlxAZ7/Q/xyw7kvOGsrZzh8ZSylQZXNHf0YzsPvIbI e21lsSpO7nP9U4R3lIvSU+GVY+5av6Op9ZCeEgk9AKNsBDuRj08x7r+FBl1Sul5Suvmo EbedK0DiS6yA0AZ73qZRBX912B2hZupzL9ajcqY7NWEfDTotYRiQW8evySKpanCrj/PR zpTKXPxv+AAhcxDbEdp36pgoyBIbl4KFgsd/K6YxYjCYNq5xXIqiFUTeQWDROVvEnEi5 f+GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=cdpIRbv+EVNcAqZViz40aKze2MA8/+R35v52TTB/NxY=; b=czfKnS1xdcZasfNlPKf1RL90ecgCg9OuptbwHlwRBusggAKur9SwtGws4z+UwIfPYT hh1hp5fpPIca5PjXVYGc+grDCdvLtpvnbDc/pQs/GlHMChqtn2fN0bzxVDw7Dz7U3zsB SOvkn8WTa92mlHitPz52Ongdf5R5Mxp7w78jNBAhiNTSPsXLpl1KhmfXWPyuItlGGFSZ 5NC3k6WxkpDGPbTvYDI114ExApvaEZxbG/beXqCIPdcUregXMJbs+j8iDv7ZD1K9xPa9 pBBbLXOUCJSAsQNAPUwhIBKdLpRfCgp8jfFrQl0LiIqhpSFP7eUN8rzuJ2/5liUyRphE UPug== X-Gm-Message-State: AOAM533rXRQ6grz72npds9SYOqYoekbu6M/OBufeOSBMralZYJySQRCm 5zXYK8PfkNp3aD85n+SP3kAMhALG0jY= X-Google-Smtp-Source: ABdhPJzg6lQPDXUCCRIy2fXAHiKj2J2YAAYW/pBoJu4UozuJXcVm1WV/Hp3H2uHCNAV9wU7C101PyQ== X-Received: by 2002:a05:620a:2a14:b0:67e:ca33:a46d with SMTP id o20-20020a05620a2a1400b0067eca33a46dmr502410qkp.360.1648659953527; Wed, 30 Mar 2022 10:05:53 -0700 (PDT) Received: from [192.168.1.201] (pool-108-18-137-133.washdc.fios.verizon.net. [108.18.137.133]) by smtp.googlemail.com with ESMTPSA id r7-20020ac85c87000000b002e234014a1fsm17781158qta.81.2022.03.30.10.05.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Mar 2022 10:05:53 -0700 (PDT) Subject: Re: [PATCH] IOMUX: Fix access past end of console_devices To: Andy Shevchenko Cc: U-Boot Mailing List , Simon Glass , Andy Shevchenko References: <20220330164902.431732-1-seanga2@gmail.com> From: Sean Anderson Message-ID: Date: Wed, 30 Mar 2022 13:05:52 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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.5 at phobos.denx.de X-Virus-Status: Clean On 3/30/22 1:01 PM, Andy Shevchenko wrote: > On Wed, Mar 30, 2022 at 7:49 PM Sean Anderson wrote: >> >> We should only access console_devices[file][i] once we have checked that >> i < cd_count[file]. Otherwise, we will access uninitialized memory at the end of >> the loop. console_devices[file][i] should not be NULL, but putting the >> assignment in the loop condition allows us to ensure that i is checked >> beforehand. This isn't a bug, but it does make valgrind stop complaining. > >> Fixes: 400797cad3 ("IOMUX: Split out for_each_console_dev() helper macro") > > Has this been tested? See below. Yes. > ... > >> #define for_each_console_dev(i, file, dev) \ >> - for (i = 0, dev = console_devices[file][i]; \ > > When we enter the loop, the dev is assigned and perhaps valid > >> - i < cd_count[file]; \ >> - i++, dev = console_devices[file][i]) >> + for (i = 0; i < cd_count[file] && \ > > Not the case anymore. The loop condition is evaluated before we enter the loop, which includes the first assignment to dev. --Sean >> + (dev = console_devices[file][i]); i++) > > >