From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 C3826C433DB for ; Thu, 25 Feb 2021 12:38:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 75B0764F14 for ; Thu, 25 Feb 2021 12:38:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232144AbhBYMiP (ORCPT ); Thu, 25 Feb 2021 07:38:15 -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-omap@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