Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp62833pxj; Thu, 20 May 2021 04:38:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRWYsNUMrR47CpWNuzw7Wa1/hq7b1yShFlcuVUwfi4/FuI4FGzTwoZOZsQX0Xa7TK7kZco X-Received: by 2002:aa7:d550:: with SMTP id u16mr2841726edr.72.1621510700756; Thu, 20 May 2021 04:38:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621510700; cv=none; d=google.com; s=arc-20160816; b=KO7prwWXkJWSTRLTLavPbUGLwhFXMKCKJ+B2ui2tWlt6kYmrEdD6foJ7W5RCCn3R9e qsChRjpMvQ4fl1sR0Jih6TnuFJn9s1mH5y+A3OI48w0VAURt0eewsKgjQO5oRszvADd4 2IuBBWcTUei37TJJgPh2lOnyg/PB5ewTw9rDRVoyG05nZjrW/GkW/ZLG+a9Z2BY2Nhg0 RbeupTHHg0BTx/9cW7ENSkhNiwSDj7SYrsgZ96Vy6CMqc3b6wNav1Z7MHo//o6fECOb7 951gpDMlZycTddIrhUymecDJCSpGgheyXvtMik6/ikxSrDLrt+uksHjF8RN5kh1IozzN cL+Q== 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=eU1lkvANR0Yq7uLviRGtgYshZoG9K+E8GK4qM2yjGKk=; b=j5yGt8qmVxrgAZKpLbBrPo1lNO8kf3gmscQbmC5ZoNXoliIZw1OQYCdYYdOAJO0ZKi 9daL40o8hAxJAPLriIUPVl6yaGRAlAm6LBGyT2flTKKIJbizsqWjMWZ6Cupl0+5gi9F2 yWpgv1WEowMHhttHsqSMG2JUrTvD4R+77zo6TLnjWWeZVmYZu+ClFKF3Qz2DXv2dBuo0 ypBHEef+EWv822PF7f01/NjE2G7m+KBHEyCkS8RjASS4oVCPfZ0FpE7JEi4NoG4+K4Sz 6miIZUoBlMcnyWR0b+/wGpWsbCU8EAC1c0T/gHJJNKXFJEP6UVL7YJxDWWTBE80Ry3xy mcCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hdHLmRml; 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 g2si1938988edu.441.2021.05.20.04.37.57; Thu, 20 May 2021 04:38:20 -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=hdHLmRml; 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 S242111AbhETLhh (ORCPT + 99 others); Thu, 20 May 2021 07:37:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:38286 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240441AbhETLRS (ORCPT ); Thu, 20 May 2021 07:17:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CEA4361951; Thu, 20 May 2021 10:09:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505384; bh=QvUtHm66ypMYgBh9BUX8eRgz4IUf+If+Cao1Z3v2waw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hdHLmRmlpg8n717QICkJa02MLg6a5WSTf6N07QLiLRED6hTodgE1DfjJkQnEE1DXD Q/B63vVwUQM+9568jDucZ9D4rSJa56Q4K+YbTn8Wwe16H7YOiRVhRQAHAJYsBZW9Ep pqAiIBU0i5zKWtvVWbS2WGEPk/vJWtk1rMWTBB8Y= 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.4 076/190] memory: gpmc: fix out of bounds read and dereference on gpmc_cs[] Date: Thu, 20 May 2021 11:22:20 +0200 Message-Id: <20210520092104.710822420@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092102.149300807@linuxfoundation.org> References: <20210520092102.149300807@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 af187c91fc33..f6d06d894538 100644 --- a/drivers/memory/omap-gpmc.c +++ b/drivers/memory/omap-gpmc.c @@ -1005,8 +1005,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)) { @@ -1015,6 +1015,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