From patchwork Mon Jun 6 12:20:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Niehusmann X-Patchwork-Id: 9158085 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 983BC60573 for ; Mon, 6 Jun 2016 13:01:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A25725EF7 for ; Mon, 6 Jun 2016 13:01:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EC6E27D45; Mon, 6 Jun 2016 13:01:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2DE925EF7 for ; Mon, 6 Jun 2016 13:01:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 95FFF6E4BB; Mon, 6 Jun 2016 13:01:10 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org X-Greylist: delayed 2444 seconds by postgrey-1.35 at gabe; Mon, 06 Jun 2016 13:01:08 UTC Received: from mail1.gondor.com (mail.gondor.com [78.47.100.206]) by gabe.freedesktop.org (Postfix) with ESMTPS id 80A7F6E448 for ; Mon, 6 Jun 2016 13:01:08 +0000 (UTC) Received: from vpn.moria.gondor.com ([10.12.0.8] helo=localhost) by mail1.gondor.com with esmtp (Exim 4.84_2) (envelope-from ) id 1b9tVr-0000O1-El; Mon, 06 Jun 2016 14:20:11 +0200 Date: Mon, 6 Jun 2016 14:20:11 +0200 From: Jan Niehusmann To: intel-gfx@lists.freedesktop.org, iommu@lists.linux-foundation.org Message-ID: <20160606122010.GA3048@x61s.reliablesolutions.de> References: <20160606103209.GA30777@mcvlad-wk.rb.intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160606103209.GA30777@mcvlad-wk.rb.intel.com> User-Agent: Mutt/1.5.23 (2014-03-12) Cc: Omer Peleg , David.Woodhouse@intel.com, Adam Morrison Subject: [Intel-gfx] [PATCH v2] iommu/vt-d: fix overflow of iommu->domains array X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP The valid range of 'did' in get_iommu_domain(*iommu, did) is 0..cap_ndoms(iommu->cap), so don't exceed that range in free_all_cpu_cached_iovas(). The user-visible impact of the out-of-bounds access is the machine hanging on suspend-to-ram. It is, in fact, a kernel panic, but due to already suspended devices, that's often not visible to the user. Fixes: 22e2f9fa63b0 ("iommu/vt-d: Use per-cpu IOVA caching") Signed-off-by: Jan Niehusmann Tested-By: Marius Vlad --- Added some details and Tested-By to the commit message. Patch is unchanged. Posted to intel-gfx@lists.freedesktop.org and iommu@lists.linux-foundation.org where the issue was discussed. diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index a644d0c..82989d4 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -4600,7 +4600,7 @@ static void free_all_cpu_cached_iovas(unsigned int cpu) if (!iommu) continue; - for (did = 0; did < 0xffff; did++) { + for (did = 0; did < cap_ndoms(iommu->cap); did++) { domain = get_iommu_domain(iommu, did); if (!domain)