Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp310134pxj; Thu, 20 May 2021 09:49:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylfGZPNJ0J2uvbkcILExiR+/enu1g8WA3H6pqMGx8mu/6H348qLl4i8s2/pfP7i4XiaKyV X-Received: by 2002:aa7:d455:: with SMTP id q21mr5949027edr.2.1621529378421; Thu, 20 May 2021 09:49:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621529378; cv=none; d=google.com; s=arc-20160816; b=JB5kgCG7+9lXRpgpsK56+atj624UupAUNlNCm38TBQy/4JfHh+TxwXtArGLPWcYjTd I40R/gDGhfoPSALUGmASMSccew1Wu6Zcx69cxhv2izgpSRxthYn9OYT83GGpCPPGHWf+ tL43vtC2wdktAuYkujA73ixtiRL63qWL04+w8Qe3YsdVYyu++sa38hDG7YLQDUSpSxnV Oo2lBxLKRQddLI4ff1ScSjS3BE9qavgyteesUlxLNXaqr4kiLf2XolS0yKVjn14KeU2r Hcxih7r66yeCKSTxRWIwxu9b+D12Uc2+k6AVLACeDyV40w0O8JtRF+7hSx2WnhXra+gl ad8A== 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=jCMf2Wj2Mvp1OiJlJyG4R12Pfw0AAAwtyRT1AWi907Y=; b=doOU46BEsak8NK0DaVGG+ZW/vkA3I0GcbkLBDAOlMpnsOC7Wl9JQHT0qnaf+ZqcTaL 9skuAjG7pE6gG6Vj5bUcERtrh3STbVgTgfV6hKDmpbjGCJYP4pS/BhvRA+THEtUuBU23 mq0MzPZCbGIV9XQpXblNq+X2zz4wBdjrt2KP7HhIntJblo5E4Hk1a3lUhuLDtoZBFjAt 0UI7H8vgHWL+ZJ5LCMKDpm5JlObRklrDoUYT65FoxrKw8WqTKjXjQGOLILjeBOtlDRli qOh3od9qe0Z6E3yFZ9WhG9kyH4j2UEd9BhMuZWr6Gg0vSpuJBdXd2Xfe0z2LHm8wzSEi 0YqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AV5LRxfP; 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 l19si2892360ejq.96.2021.05.20.09.49.14; Thu, 20 May 2021 09:49:38 -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=AV5LRxfP; 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 S233293AbhETJwR (ORCPT + 99 others); Thu, 20 May 2021 05:52:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:53174 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234458AbhETJtl (ORCPT ); Thu, 20 May 2021 05:49:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 537096147E; Thu, 20 May 2021 09:35:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503307; bh=ABOOV/XMXWFoKGlf+G2ZmP19IYOAD+/0JQL7xASoKdk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AV5LRxfPEusBiN4oaKSxXj6EFdwmW7uKyJZ/ufs2Jtq6RQZZmFgSfMKs7l6hiOqWY JlKPupE0AxRLPbcTDPh/RlqgkHIkBRE2ygCThlPoLKHFgFdXkRQ4qNzG4IOg6NwReP 0p5tTkyYFisCfb+jUXmo0LqfMS68MazSve0rB4Io= 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.19 162/425] memory: gpmc: fix out of bounds read and dereference on gpmc_cs[] Date: Thu, 20 May 2021 11:18:51 +0200 Message-Id: <20210520092136.778251483@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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 2ca507f3a58c..d8f2cacea750 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