Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4584379pxj; Wed, 12 May 2021 08:41:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0eRuxzEJ7Z8EcypZXI8OpOiCii7mwWNRavCL6BZ1iEppDm3/2rIvkFsnexO/lc1p6gQFT X-Received: by 2002:a17:907:75e9:: with SMTP id jz9mr5995853ejc.314.1620834081450; Wed, 12 May 2021 08:41:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620834081; cv=none; d=google.com; s=arc-20160816; b=djqEymKHgkDNa4CR4ccqxlGKG4Cl4B4jqxxtdiRDar7GhQjQvh0rs3ZeIYEdYGf1MP qzxED4ZYUdBq9TzpXQKqb9+NiGJqwEwApc8u57ylGU0pEJwWnOr79cjTGc0gbuGshTvx 9MZfIwZN8WP+NJvY0gWSXxWWfivi30E27Pc4GFYsCHBlmThy5LWqw6FhMneBh03d0Osi 3vjbNT9FE+isMGqDwJ3RT8Sbmgu229DLWbgZY+hbJryfcYH3LXxrZFVMgxMz3NG/yzqY 3TUg054azyG6QSymImzXvxAXrQTDhby8kK1FhEE8Wp+RA3Z2foBlwMCyEXiFPDq4ibBf ag/g== 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=ZUDjLz3/7Yu7Sr6jnlvdzNsI0YM18ecP6qOxvHd0wc0=; b=DZH+nSOLEXyFjD73QTFE3beE8Wa47G0gJBQJK4GNJlD+QJN6JF17RtNM7ar9t576XC a6RSXWcGFlC/y6HtQ4EOSGzEVmbHWVVBiD+pmExUGut9EPoXMVeTsNLJdMpomm/F4q7f XuaF3GKWEWFvKw7vrFSMD+xdUGfE5ghFKfJNSH2DDshdfIK3sGVtphNiBOFyTcTqyr5D g5uiPUnsr9ijhfvvwRU4SEO7Z2afP6Dgd8qEc/wCCi9ru0C9yOAcZEqCTvsT1LLcFGhV YLZTLhce8nD4jozvNfYzoV7cjFd8BxMi9Eha/lXKAHtHeigdgl7yYtVEHnbQjknq8P6F ktsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HqaYnxke; 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 b6si286330ejc.303.2021.05.12.08.40.57; Wed, 12 May 2021 08:41:21 -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=HqaYnxke; 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 S235621AbhELPkK (ORCPT + 99 others); Wed, 12 May 2021 11:40:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:50144 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233125AbhELPRl (ORCPT ); Wed, 12 May 2021 11:17:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F23B66195F; Wed, 12 May 2021 15:07:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832035; bh=OutA4LIeEjcDid8OGBeOVhqgU0w91cHH6NxHdsKbaME=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HqaYnxkegI5PLiO07FZJlYBJuKQRs+Ctkip66o/XG4DSJhxY+nGUivg6EZc+ziVRz UIVsll2uy8g7vVVeRd7beaJ2BTx8QlEU6K93C9wDKZlHpBxfJuVU73Zw9zMH30o+j6 v5XweyPxUxjgclmDZyq9dMnVBEBPUTL2fDurOs+k= 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 5.10 116/530] memory: gpmc: fix out of bounds read and dereference on gpmc_cs[] Date: Wed, 12 May 2021 16:43:46 +0200 Message-Id: <20210512144823.622329482@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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 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; + struct gpmc_cs_data *gpmc; + struct resource *res; spin_lock(&gpmc_mem_lock); if (cs >= gpmc_cs_num || cs < 0 || !gpmc_cs_reserved(cs)) { @@ -1018,6 +1018,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