Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp375595pxb; Thu, 25 Feb 2021 05:06:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJyhS7iIa5Aim2Xje5/q5xuPd2KB59SU4njhZm1QzgwjKGWEcF/P0R+6QGn8outJx2K3aD7T X-Received: by 2002:a17:906:2558:: with SMTP id j24mr2560243ejb.447.1614258365618; Thu, 25 Feb 2021 05:06:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614258365; cv=none; d=google.com; s=arc-20160816; b=JQNEJilQ1JrF5fLOXgoF7YNz9nB4Y0qmCdVrsWjf2mARaGQ6oD9/0HI11zwsefeyN8 GPS5j4s17DbTwc7WpS0OtjvkXzd+a7heOHBxnA0CID82oj9/Udf6vK1dTMVanOI1dPTE mTZHqBHNKvMUZu3CKd1ZLzyrFSc71xKK/xxiEAJq0NQFKApflEI8nUQoEHCyLdvwCxI6 y1CDt3z+PzWe8B91bn8vkAXO4dqxIczk1cbQdFQ1H7/IXqkPtc/sixuoY/3NoHwF6IRx ++hcKMyVjurzzYr80BJQKbEmMt8d0q1sWnP0NUEiwylWfxcOH26Qf2vTsG3M1tSNc7s+ 0G5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=+jL50CfJpidVQooNlno3D6077Rzg3ifXx0xrntE0k3Q=; b=hPkWRE4wjIhYutEjnhEp1EqHaMRwjmg0CSZclExqg/nOB5EcKXWIEAwcrztuDyFgqf PRhgAadE41eoTKL/ajlAEXGT83o+9rLFBU/+EYaDa6kQZyKE/rPxPmFPOpAFuhH3/jKG ufXMfCJ9jpnC2DHjh564s9u9ThUvgTJyY0emZybgi7rtRMkSOJEQ0dlLJge1+U7kt30O hSiyg4DLPSv7XpVRksWAzyBSmU+WnIz0+gHJzH7FYs/dB2/QworQsKG4Kl8wgURIsYvF LaMS14PR6QJL0N6TyjcHuOhttkaogPlBBWaHYqcPX5Wf3cq/MP5qN9Z6ZbuZLoDk1HGZ QsAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k21si3117006edo.563.2021.02.25.05.05.41; Thu, 25 Feb 2021 05:06:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232491AbhBYMiQ (ORCPT + 99 others); Thu, 25 Feb 2021 07:38:16 -0500 Received: from muru.com ([72.249.23.125]:37194 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231833AbhBYMiO (ORCPT ); Thu, 25 Feb 2021 07:38:14 -0500 Received: from atomide.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTPS id 37C2E807A; Thu, 25 Feb 2021 12:38:05 +0000 (UTC) Date: Thu, 25 Feb 2021 14:37:30 +0200 From: Tony Lindgren To: Krzysztof Kozlowski Cc: Dan Carpenter , Colin King , Roger Quadros , linux-omap@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] memory: gpmc: fix out of bounds read and dereference on gpmc_cs[] Message-ID: References: <20210223193821.17232-1-colin.king@canonical.com> <20210224075552.GS2087@kadam> <20210224081104.rw6amjl6p5so5cq7@kozik-lap> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210224081104.rw6amjl6p5so5cq7@kozik-lap> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Krzysztof Kozlowski [210224 08:11]: > On Wed, Feb 24, 2021 at 10:55:52AM +0300, Dan Carpenter wrote: > > On Tue, Feb 23, 2021 at 07:38:21PM +0000, Colin King wrote: > > > From: Colin Ian King > > > > > > Currently the array gpmc_cs is indexed by cs before it cs is range checked > > > and the pointer read from this out-of-index read is dereferenced. Fix this > > > by performing the range check on cs before the read and the following > > > pointer dereference. > > > > > > Addresses-Coverity: ("Negative array index read") > > > Fixes: 186401937927 ("memory: gpmc: Move omap gpmc code to live under drivers") > > > Signed-off-by: Colin Ian King > > > --- > > > drivers/memory/omap-gpmc.c | 7 +++++-- > > > 1 file changed, 5 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/memory/omap-gpmc.c b/drivers/memory/omap-gpmc.c > > > index cfa730cfd145..f80c2ea39ca4 100644 > > > --- a/drivers/memory/omap-gpmc.c > > > +++ b/drivers/memory/omap-gpmc.c > > > @@ -1009,8 +1009,8 @@ EXPORT_SYMBOL(gpmc_cs_request); > > > > > > void gpmc_cs_free(int cs) > > > { > > > - struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; > > > - struct resource *res = &gpmc->mem; > > > > There is no actual dereferencing going on here, it just taking the > > addresses. But the patch is also harmless and improves readability. > > Hm, in the second line indeed the compiler will just calculate the > offset of "mem" field against the "gpmc_cs+cs" and return it's probable > address. > > To me still the code is a little bit non-obvious or obfuscated - first > you play with the array[index] and then you check the validity of index. To me it seems the fixes tag is not ideal.. Seems this issue was there earlier too before moving the code. In any case: Reviewed-by: Tony Lindgren