From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=85.214.250.239 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796033062; b=W/JNwRNGbpwLYBZanUELzJosganIuPbf1OXjmoZr/V2kdQWQbprxGj2pJL+EZLe+4HOW cDHiVjw6uIUGw256+zkt6Ye8kSuEy1TH66KIDz8WU6HjKrgroU3CStPexTMR0DkdJovL0 gvKLik870y1hF/0aS4B1zipmGOYnoiWewQ6M7q66g/0DBiNDLLRjvguDFJ1HZ8kLMhog5 IVMBnOCBYt24APDg8txC57htmbXyvoQVNnd7M3UOOQKQhQJ3oEU/4Oylur02gKwX5mxX3 g1zQmN+frM3r2eNO0YoHv074Miwf7YxT/Kx872bcO+KHx3B1y1mmaqWEU0z/Ag4XXLQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796033062; h=DMARC-Filter:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition: Content-Transfer-Encoding:In-Reply-To; bh=HPfEfLAm2aw/5+WB82TOcJ9DaVMY06lYZwWigAhenVg=; b=1AGEjungbVOEs9uXjxdlkvRG9yJfuHTEjmExgqPgXKcj1GzXKc0djyrTjr28uTI7oDtV y8WqU2bd1KNd8Bgu+Ix2rfL3iPLrTXHQ4pueg/zcLT9jo4LBq4HTAzjVYmL8CBVSQ1DOc bwIykidBnP+rzXz04MMmwUUmyDIFXuidAkdjE67kHm8vd8nGLMlIUEYDJvSb7pQNIE1zw 84l0qbumHfZ31nWLFbAP1XPwygrcm2c/gfOeiIVkUgo59aeVg7Hyy/GlsKlqnymhT3Ru3 cV2HWw/5x6WRwEpi9S3VbGWWwon9m/mjJxjbXzDQZvNZzGkYIJfAyJk1rECTTZdhkuQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=8bytes.org; spf=pass smtp.mailfrom=8bytes.org; arc=none smtp.remote-ip=85.214.250.239 Received: from mail.8bytes.org (mail.8bytes.org [85.214.250.239]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 74072606A337; Mon, 30 Nov 2026 10:04:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 74072606A337 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=8bytes.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=8bytes.org Received: from 8bytes.org (p549216fa.dip0.t-ipconnect.de [84.146.22.250]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.8bytes.org (Postfix) with ESMTPSA id 6DDB42454FB; Mon, 30 Nov 2026 11:04:20 +0100 (CET) Date: Mon, 30 Nov 2026 11:04:19 +0100 From: Joerg Roedel To: Anton Protopopov Cc: Sven Peter , Will Deacon , Janne Grunau , Neal Gompa , Robin Murphy , iommu@lists.linux.dev, asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] iommu/apple-dart: Properly check the error Message-ID: References: <20261127095119.1342988-1-a.s.protopopov@gmail.com> X-Mailing-List: asahi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20261127095119.1342988-1-a.s.protopopov@gmail.com> On Fri, Nov 27, 2026 at 09:51:18AM +0000, Anton Protopopov wrote: > The apple_dart_device_group() function expects pci_device_group() > (or generic_device_group() for a non-PCI device) to return NULL on > failure. However, both of them return an error pointer instead of > NULL. The error pointer then is immediately dereferenced by the > iommu_group_get_iommudata() function. > > Check for an error pointer instead of NULL and return the error. > > Fixes: f0b636804c7c ("iommu/dart: Clear sid2group entry when a group is freed") > Signed-off-by: Anton Protopopov > --- > > (Found accidentally, while working on BPF stuff.) > > drivers/iommu/apple-dart.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c > index d8302128b465..36ce5ac39b7b 100644 > --- a/drivers/iommu/apple-dart.c > +++ b/drivers/iommu/apple-dart.c > @@ -981,8 +981,8 @@ static struct iommu_group *apple_dart_device_group(struct device *dev) > #endif > group = generic_device_group(dev); > > - res = ERR_PTR(-ENOMEM); > - if (!group) > + res = group; > + if (IS_ERR(group)) > goto out; Assigning `group` to `res` seems problematic, here is what AI found: Return -ENOMEM when copying the DART group configuration fails — /home/joro/src/iommu/linux/drivers/iommu/apple-dart.c:984-984 If kmemdup() fails in apple_dart_device_group(), the error path drops the group reference with iommu_group_put() but returns res, which now holds the group pointer. iommu_init_device() treats that pointer as success and stores it in dev->iommu_group, so the probe can use a freed group. Preserve ERR_PTR(-ENOMEM) on the copy-failure path while still propagating errors from the group lookup. -Joerg