From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 986CC3D890B for ; Fri, 29 May 2026 11:34:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780054457; cv=none; b=TfNWx846egvqX5zXmkoFff1nJNev4MP0Jn3cEjT08r+F6KGEudMXK59hiezlKqNeqnKZIN+NA8/HHjob6M5ud8X8RC2yMju3LoEVXXpt65s8dArA4ABDCOmfxo7acfZst4LtZQ2RR8QFm0vx/n6z9d7tKf634OIZd3DWbLH7twI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780054457; c=relaxed/simple; bh=FWe+zkG6d1dSp2BnJpzvZr07OMSiwnHIAa4IQItE6Ig=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=A4SrbBf11RyTSbJZ7tL8p4kCww0rXZpHR2Ohrojud8sRg4RfaziufLmB6Veup3TzvY8fKcsKQXZ3acjltH56Pt2HmEEx5XzYA2GCHpFvlfXDzMYkH2XAfQ0BWag6/uKW73lOOuLHQRlWWdR97K6t2LLsxXzKYcTeKkPWcAoZWg0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--praan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MUOeGk/E; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--praan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MUOeGk/E" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2bf30576aa3so743785ad.3 for ; Fri, 29 May 2026 04:34:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780054455; x=1780659255; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=QWXlHKTSa6jbTlPQqXflZFEjWNMHtxbOFAcz50SUsYQ=; b=MUOeGk/E4I8zg5k5KTFqIKcp+2igTOpKuIygTzlITXXSP6GuPxqAVfmFys/cu1baF3 pb1mJVwpNlEN4dv6/4FlflAYxw4uA6y7EvdKD9k0qrsIo+7GR+LNw3axfZdfq5uKJgfG NJxouEw3/c0sVlEBwg46HzcenijXKUnS2940CnyZFgwA6F8JOfOKZKxHGIcc5lB5t0N4 2QMXnjiuEGnmhRbVo2MVGz4cVVnMn1krd2xXPa4npnXK1jlxUIvGxulbScK2XC+sGrV4 B4Rjr+ESEQZk3uxMXcRxgt/xI9UTl38/AxjUxrq990ewjIILLzIIBLasCiRLEK493gEl FPNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780054455; x=1780659255; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QWXlHKTSa6jbTlPQqXflZFEjWNMHtxbOFAcz50SUsYQ=; b=gnNvlF8erBxvaNn16DiIssH1UdtLUh/HIHbEnC4uuPfU1bt5QHcC3+8QnLmfpPFbm9 O1PeHEYKIIqgJQjj5uAQTZNvpZ2MpdUl727/OUl06y8S1XHembGnj7rfr+hRxE46soaU JmnBRx2DV0+CanhX2R4p+Zx12jwLrSaTyaO0hN4aORvoemzUyU4byd2dfr+sC9fOjF94 jLiud2Co2Ielq3xtY8euKvPxxGS/poPraiSKvcg6tXuDMJ83nuNX1m60V59bZy3e3tsD LzzMwAlNdVfn+/6qOzCdSSoCVAI/BulPzdSyK6R3FKMlqLnSHkI7/ENwIjWzt7af2THS SpOA== X-Forwarded-Encrypted: i=1; AFNElJ/SHN1tjJcySl74+zdVpt4yBE4o+XcRaHUbB7v/HY7BFaA4q7MO0cCs5mwEKE4aARYYGllgQv5jmd244X0=@vger.kernel.org X-Gm-Message-State: AOJu0YyVoI99c9RHKgpShKlIGSTcc03ym9f6gf6ZC/y9CYluhhl5+gnT QPqhhi9zVQqVDlEbXf5nG7xB/DKqf2YlWsdW1S2FMIxf12cuxWDCtj/PFXcm4Z76npuAkYGPdyC 7eQ== X-Received: from pllg4.prod.google.com ([2002:a17:902:7404:b0:2ba:3f4e:3d6]) (user=praan job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d4c9:b0:2bf:11ed:3d64 with SMTP id d9443c01a7336-2bf2098181cmr34231215ad.18.1780054454473; Fri, 29 May 2026 04:34:14 -0700 (PDT) Date: Fri, 29 May 2026 11:34:09 +0000 In-Reply-To: <20260529113410.491538-1-praan@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260529113410.491538-1-praan@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260529113410.491538-2-praan@google.com> Subject: [PATCH 1/2] iommu/vt-d: Fix RB-tree corruption in probe error path From: Pranjal Shrivastava To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Cc: David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Robin Murphy , Kevin Tian , Samiullah Khawaja , Pranjal Shrivastava , sashiko-bot@kernel.org Content-Type: text/plain; charset="UTF-8" The info->node RB-tree member is zero-initialized via kzalloc. If a device does not support ATS, the device_rbtree_insert() call is skipped. If a subsequent probe step fails, the error path jumps to device_rbtree_remove(), which misinterprets the zeroed node as a tree root and corrupts the device RB-tree. Fix this by explicitly initializing the RB-node as empty using RB_CLEAR_NODE() during initialization and guarding the removal with RB_EMPTY_NODE(). Fixes: 4f1492efb495 ("iommu/vt-d: Revert ATS timing change to fix boot failure") Reported-by: sashiko-bot@kernel.org Closes: https://lore.kernel.org/all/20260525205628.CD4431F000E9@smtp.kernel.org/ Suggested-by: Baolu Lu Signed-off-by: Pranjal Shrivastava --- drivers/iommu/intel/iommu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index c3d18cd77d2f..2702e9aa2241 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -157,7 +157,10 @@ static void device_rbtree_remove(struct device_domain_info *info) unsigned long flags; spin_lock_irqsave(&iommu->device_rbtree_lock, flags); - rb_erase(&info->node, &iommu->device_rbtree); + if (!RB_EMPTY_NODE(&info->node)) { + rb_erase(&info->node, &iommu->device_rbtree); + RB_CLEAR_NODE(&info->node); + } spin_unlock_irqrestore(&iommu->device_rbtree_lock, flags); } @@ -3254,6 +3257,7 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev) info->dev = dev; info->iommu = iommu; + RB_CLEAR_NODE(&info->node); if (dev_is_pci(dev)) { if (ecap_dev_iotlb_support(iommu->ecap) && pci_ats_supported(pdev) && -- 2.54.0.823.g6e5bcc1fc9-goog