Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2007319imm; Sat, 18 Aug 2018 08:58:31 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzV/24NpFDXnIZIwsu9cgkqGyke6O0fi71JgEy4+5OvI1jH8clWN9pM79WD1KznzK7han/q X-Received: by 2002:a62:1016:: with SMTP id y22-v6mr41162034pfi.109.1534607911351; Sat, 18 Aug 2018 08:58:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534607911; cv=none; d=google.com; s=arc-20160816; b=pFNkVxvPJk3mt/nyui8pp6u1nyMXMRLgbOnq7OLOX6QbooGAga/efgz2PaShA9ejJB y64ygIVKPcHvyABWFTmo4RzpppVDwl1VBEi5nyii8kYXViY3d/e7mgPxrzC9o5XRyyZb NVX/+dI3C2UHq+cq4WXoKxf9FR2+ZPN7NVEjiLZ/LYwi4LLWCjkKlxAi4hyDLDuqx9Kf Ppxb/7ntZ9LqR2twgn+YAsSytwdEnJ44EMMQstuznxsmErYNc5Ttpnea/ctRkEqE5TKz AOLnYlog0rbK7aEk2eNBmmND/ZXcNcyS0jYeJkqH9Ns4gFVYXUAAMuYdyYPIXOqhhNjG 8OOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=zCpTSpyL1wbgmHjX1/OPXhCprvlf7BBAbtdIyx97wFY=; b=fI0aRI4lv2MTJlqNxrwOEWw/Qfaub9CoxLyxUouDr12cDXLhyKSupXPiwZFZWvFBo9 rx3lf1gewWL4Gp573XIh4c6YdM9SeXec2CTvM2LqecwAtxDvLmdyA0fyeWi/Sz7IqpoT SWboyxFooW8bViD2Bl1cviBMD8YRX0hO/2BRoBhcqsqSU/BUOSi5Ork7sL5rHDBY95bU Zjsf1ttKJOrEAltrch6MG+7e9yx02BKzqXNxT/ytg8uSYp/XJ8ZBs3inttU01ileUCtM NDOlP8OJutAfAlutLNYINXEP2SDIWTPC5RC8c4q/dKdDMn5A7+ghSCcFdKZsoVhLGZhu ek6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZZUcUOks; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k6-v6si4852873pla.473.2018.08.18.08.58.16; Sat, 18 Aug 2018 08:58:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZZUcUOks; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727340AbeHRTEz (ORCPT + 99 others); Sat, 18 Aug 2018 15:04:55 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:46918 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726273AbeHRTED (ORCPT ); Sat, 18 Aug 2018 15:04:03 -0400 Received: by mail-ed1-f67.google.com with SMTP id o8-v6so6099353edt.13; Sat, 18 Aug 2018 08:55:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zCpTSpyL1wbgmHjX1/OPXhCprvlf7BBAbtdIyx97wFY=; b=ZZUcUOksNz0OFdSnMKougbPymeULYNGSnsplwPTJsaN3umUNJvWq9IGTxy2sP1JL6N 4i+mMijVnOhCLJ/BJsRsZ4EGV+ylhCN+5b3d25AAb/Gh1969rPeT0ChP+0ZicREHGUzH 5I/p5ZNPokgupSQiU/+ossg13y7XIM6PSanor19iA2DyvbCVwq1Pam89pGDBILzGbTXQ m4VpYDytXEjMm9i8ixZfBEIsR3uT+5YFpSvscpYrdjTIyNlLmnvHPvFonl8mkbopmehg BjofX4ho7dWoA/ItjvuCVtWUR5sZ23YeQ4PQvb0oox8qcn+5D3O+TfrvPKSoV6FOFarG 8rmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zCpTSpyL1wbgmHjX1/OPXhCprvlf7BBAbtdIyx97wFY=; b=lQc0D34P/RIk2asQZTLLP64qh1CL+Ri/CKpd46J0r9pYg4BujuTT4X+SvI1bkRqn1Z Rg7tbaFrKhfABQCdjnJdajMBcsH9vj2eoDpWwKyovAEuxGxzgSy8gx+gGxobjXsX9jIz 258v3uvm5h6gbFI7pwlMVNrzrWdh6Dz8G7svIGUajnOXa628A+MmF6yk8ZHfF6pWAslh 0o57Kdn3t1jNuHqYhFu/hLqLmRk5cLxGR7h0qy238iOu4EiPOIW9+YyisiB+JaqF/uJ8 R4lM6YZNr/onXt/5BnItBjL7QGWlqr37KtmbzpsukM1MrORbnV+0QzKJqSPNG+LU04hD /TsA== X-Gm-Message-State: AOUpUlEmqYQwGSd4NcxdXuYN8t4HArNVQBjBjc9jiBNaXo7lrTf7tauN TdG90AX1wPS9v2TwA+UQm5Y= X-Received: by 2002:a50:ade6:: with SMTP id b35-v6mr47283365edd.168.1534607752946; Sat, 18 Aug 2018 08:55:52 -0700 (PDT) Received: from localhost.localdomain (109-252-90-13.nat.spd-mgts.ru. [109.252.90.13]) by smtp.gmail.com with ESMTPSA id v8-v6sm2784014edr.48.2018.08.18.08.55.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Aug 2018 08:55:52 -0700 (PDT) From: Dmitry Osipenko To: Joerg Roedel , Robin Murphy , Thierry Reding , Jonathan Hunter , Rob Herring Cc: iommu@lists.linux-foundation.org, devicetree@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 13/19] iommu/tegra: gart: Fix NULL pointer dereference Date: Sat, 18 Aug 2018 18:54:24 +0300 Message-Id: <20180818155430.5586-14-digetx@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180818155430.5586-1-digetx@gmail.com> References: <20180818155430.5586-1-digetx@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fix NULL pointer dereference on IOMMU domain destruction that happens because clients list is being iterated unsafely and its elements are getting deleted during the iteration. Signed-off-by: Dmitry Osipenko --- drivers/iommu/tegra-gart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c index e6fe139576c3..1d45b023adea 100644 --- a/drivers/iommu/tegra-gart.c +++ b/drivers/iommu/tegra-gart.c @@ -258,9 +258,9 @@ static void gart_iommu_domain_free(struct iommu_domain *domain) if (gart) { spin_lock(&gart->client_lock); if (!list_empty(&gart->client)) { - struct gart_client *c; + struct gart_client *c, *tmp; - list_for_each_entry(c, &gart->client, list) + list_for_each_entry_safe(c, tmp, &gart->client, list) __gart_iommu_detach_dev(domain, c->dev); } spin_unlock(&gart->client_lock); -- 2.18.0