From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BF97606A31C for ; Mon, 30 Nov 2026 10:04:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=RHTuKe98 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=HPfEfLAm2aw/5+WB82TOcJ9DaVMY06lYZwWigAhenVg=; b=RHTuKe98sGvxsJGtv2/KkAOVrG o6B2aKk14UdWSff25QvdmlO6hzqeb37OKMJFsa5fKTmSCjeHfsYB2afmMKUe2MG7ov5JjY5wtkD8d 40xOT9KVIcLUqyZBQ6fsgLEQd71gsuX6GxbjUCuoSrsPhWmSaJnU7HdGmj2tzkL6g6ux0w0n+E8LK CQ6Rg6BuSOKHOzLLMEherSfsygaYubsiMYw7OFzNDm813tm4OU11DjQXLQMly0qBt/IYDANTrhhqJ cHwIzyke8CsoK7Iw2fAH63WUmMgOgTXprO3m6l/MU1sMPeWoShFs1SKdD2f0Fee2jIZPvPX6O+fNA VWVeFLhA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXyFG-000000042r4-47j6; Mon, 30 Nov 2026 10:04:26 +0000 Received: from mail.8bytes.org ([2a01:238:42d9:3f00:e505:6202:4f0c:f051]) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXyFD-000000042oA-2KPD for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2026 10:04:25 +0000 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-Archived-By: 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261130_020423_897668_0138691B X-CRM114-Status: GOOD ( 19.07 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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