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=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 29F53C433E0 for ; Wed, 24 Feb 2021 08:49:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE35864DD3 for ; Wed, 24 Feb 2021 08:49:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233900AbhBXIsx (ORCPT ); Wed, 24 Feb 2021 03:48:53 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:45495 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234039AbhBXIrW (ORCPT ); Wed, 24 Feb 2021 03:47:22 -0500 Received: from cpc154979-craw9-2-0-cust193.16-3.cable.virginm.net ([80.193.200.194] helo=[192.168.0.210]) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lEpoa-0002NZ-1G; Wed, 24 Feb 2021 08:46:36 +0000 Subject: Re: [PATCH] memory: gpmc: fix out of bounds read and dereference on gpmc_cs[] To: Dan Carpenter Cc: Roger Quadros , Tony Lindgren , Krzysztof Kozlowski , linux-omap@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210223193821.17232-1-colin.king@canonical.com> <20210224075552.GS2087@kadam> From: Colin Ian King Message-ID: Date: Wed, 24 Feb 2021 08:46:35 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <20210224075552.GS2087@kadam> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24/02/2021 07:55, 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. Plus compilers are getting smarter with static analysis so some day in the future they will warn about this. > > regards, > dan carpenter >