Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp432723pxj; Thu, 20 May 2021 12:45:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoe7u0Q0V4EIzzpU4bYYoKcQrSnDh2A4yIZO2KsPuSENwuAI20C9oi1Rok3M/SImPY8Bbd X-Received: by 2002:a17:906:81cd:: with SMTP id e13mr6175106ejx.339.1621539940118; Thu, 20 May 2021 12:45:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621539940; cv=none; d=google.com; s=arc-20160816; b=rPnk3Ah2pSAQNdAMSYaOAtA/mVc1ScyDPQc3QCIYzzH5sze+QVvolxZnd2otame+CS HKPeTRjsANXkZMHujn0RjQFPCfin2t1ABhzGM+JulrisBIBhbpFj28kFpRe24q3bT91r Zt5D/oPqTcgW9Q04FpwGovYQbTVO1VgdurGRs7/DBJWb9eAgrof5OU5Awci8OvcH/2sG X0TEbANKVYok0VXf2LEUInI5GLO/ywOJZEebOF8dcuFGwCGdtWjTu3YLtvYrtVfyZZyd uhl8/YZDdoJLkBeBSKlL5m7AoIXJ7Y3JieMe0SkmdH7KmOoFC7qukkqG2aINHEKkghb8 tk3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cCs91yTurQ28LDLlbWT9tT01VpF0nqeHVrg5rSxFsHM=; b=avshSzxcs5/0QUGiG+RTsYESNOeVmaO2jDYd0sTYhRXcEKBbzKwC44pGWALmSyvN74 76TnDMRdGFDHjVLLxptxEDIxMYeKWUXINJ3TYjQi2oLaHVWyWx5BlYkNl/MpCPuYrDUc y77ZxYLcASYPNnDOnAqtCeW950iIS80W8VbO7fVoUMNNudY3wO6Ugc3d05TOLf5V3AmH fsGyrS+X84D2pTR6X2vv4Z9JiKFPKPyn7VHoBAa8NlI44IwGpjt/JNIs4GA07etbRJfl 4hF8iUl3oJOkm0TW8vhdzkwFLaCJeXqP8ZcNvn3YadAanF8S9iNLhlNoIsJOFOTyT9P3 bf1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o3wBKE9g; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z21si3267073edq.367.2021.05.20.12.45.16; Thu, 20 May 2021 12:45:40 -0700 (PDT) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o3wBKE9g; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236066AbhETKlU (ORCPT + 99 others); Thu, 20 May 2021 06:41:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:55706 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236078AbhETKZy (ORCPT ); Thu, 20 May 2021 06:25:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 856F561C1C; Thu, 20 May 2021 09:49:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504200; bh=P1Ify455ivagZ26TDWeqsKNPqMogp8ndawhHq0OgRFg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o3wBKE9gu9A4Wq7adcCYTQUQ2+DzWHRFEX7M96Mm3+/4zhYFPAeU/nuWZq3JEVq22 AfN00XXfAY2ltpTbJyE8dWcmZhuTMg+0U5GJ4svON8s6oQirWvchjtXdY75zvExEqM 6xXMvtuOdV9Y4zEVQvs1zMTfBwNkqKPgA12Tao4k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Tony Lindgren , Krzysztof Kozlowski , Sasha Levin Subject: [PATCH 4.14 138/323] memory: gpmc: fix out of bounds read and dereference on gpmc_cs[] Date: Thu, 20 May 2021 11:20:30 +0200 Message-Id: <20210520092124.839813789@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King [ Upstream commit e004c3e67b6459c99285b18366a71af467d869f5 ] 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: 9ed7a776eb50 ("ARM: OMAP2+: Fix support for multiple devices on a GPMC chip select") Signed-off-by: Colin Ian King Reviewed-by: Tony Lindgren Link: https://lore.kernel.org/r/20210223193821.17232-1-colin.king@canonical.com Signed-off-by: Krzysztof Kozlowski Signed-off-by: Sasha Levin --- 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 cc0da96d07ca..4eb1b8ebfd22 100644 --- a/drivers/memory/omap-gpmc.c +++ b/drivers/memory/omap-gpmc.c @@ -1028,8 +1028,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; + struct gpmc_cs_data *gpmc; + struct resource *res; spin_lock(&gpmc_mem_lock); if (cs >= gpmc_cs_num || cs < 0 || !gpmc_cs_reserved(cs)) { @@ -1038,6 +1038,9 @@ void gpmc_cs_free(int cs) spin_unlock(&gpmc_mem_lock); return; } + gpmc = &gpmc_cs[cs]; + res = &gpmc->mem; + gpmc_cs_disable_mem(cs); if (res->flags) release_resource(res); -- 2.30.2