Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp613175iob; Wed, 4 May 2022 04:30:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgMsylaKaXutvGFDvTrThB1brJWuTdrWUQqRGUbTkyTxZcO9aUCJQ+dOHEhjq6m2nrALku X-Received: by 2002:a05:6402:2815:b0:420:c32e:ebe2 with SMTP id h21-20020a056402281500b00420c32eebe2mr22205921ede.1.1651663826118; Wed, 04 May 2022 04:30:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651663826; cv=none; d=google.com; s=arc-20160816; b=VWVXzRZLwe4Ja5B6q/mBTWO4Kv/3qEsBBKTDVQeKzS1hi19a5fz9R2n7n0IimOczYY 4hdABda39+zBX5wdXJM4zzJR/UhHy7BGF53uwa+19ZRQGEkWsydlkuQTzVXE/SjXn5dV u83EVyWm+XAAKn6F8bnEU0tOB1F5Z2PRaC73rAKablE7q0ie+x2LMQoMiDZ0T/+rCOa7 1qaP5AWWj4BNfjtgdzMdhsPRI/I9mWQm2cz+qFn7FHF35ZMKaZrYQ5Pq1IaJNYno8b07 3MGFsHGbBIkeBZoepGgNNQEezE9+BRaKRhmvijE6yyXwsLG/X7fPJK8EkOyTTkal6lPx p++A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=XVstjfrrSVaAw6RH43org7MDY9AU998k1cRDMjZohnY=; b=Cu+vMpfMTNDLMMSMb8/KbW3r/ej7JP72Z+DHzGPxaaUw0I7jyjxW4yusnfmtXRe+MM OKHuj4/NGt6NbFsbIWgz8aohs+wnGWHy0h7PMV7m/IoK0yDgoDEYbTkKX8mmpBO8r04h hxq0b4+1AzzOhKxP1lu9thpqh444Zy9xIOgOm4gUR7hQ3eiO0sypLOwA4Q/g454DXpvM Ks4MLlWAmuv3w4bmiihwfaNo4DM6U4zk2eNHSZQ7knKy3NszOApOEGl0eE6reuwaYrB5 gbPqp30rj/nKztfktnEV7gm8Wze6GQ4MKNLfWV5sWxyVDBHtQnP9wo7zJQzgmDQ3haSg 8tfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k12-20020a508acc000000b00425b57c4593si15640268edk.163.2022.05.04.04.30.01; Wed, 04 May 2022 04:30:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348607AbiEDLRx (ORCPT + 99 others); Wed, 4 May 2022 07:17:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348017AbiEDLRw (ORCPT ); Wed, 4 May 2022 07:17:52 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E8CBA1570A for ; Wed, 4 May 2022 04:14:16 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A906C1042; Wed, 4 May 2022 04:14:16 -0700 (PDT) Received: from [10.57.80.111] (unknown [10.57.80.111]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DAA1B3FA50; Wed, 4 May 2022 04:14:12 -0700 (PDT) Message-ID: <8d6c30e0-dcf7-56f8-c44b-2d8bdb1dc04c@arm.com> Date: Wed, 4 May 2022 12:14:07 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [bug] NULL pointer deref after 3f6634d997db ("iommu: Use right way to retrieve iommu_ops") Content-Language: en-GB To: Jan Stancek , Lu Baolu Cc: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Ben Skeggs , Kevin Tian , Ashok Raj , Will Deacon , Alex Williamson , Eric Auger , Liu Yi L , Jacob jun Pan , David Airlie , Daniel Vetter , Thierry Reding , Jonathan Hunter , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Christoph Hellwig , bgoncalv@redhat.com References: <20220216025249.3459465-1-baolu.lu@linux.intel.com> <20220216025249.3459465-8-baolu.lu@linux.intel.com> <20220504075356.GA2361844@janakin.usersys.redhat.com> From: Robin Murphy In-Reply-To: <20220504075356.GA2361844@janakin.usersys.redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-05-04 08:53, Jan Stancek wrote: [...] > Hi, > > I'm getting panics after hunk above was applied in this patch > on ppc64le KVM guest, dev->iommu is NULL. Oof, this can probably be hit with vfio-noiommu too, and by the look of things, `echo auto > /sys/kernel/iommu_groups/0/type` would likely blow up as well. Does the patch below work for you? Thanks, Robin. ----->8----- From abf0a38563bb2922a849e235d33d342170b5bc90 Mon Sep 17 00:00:00 2001 Message-Id: From: Robin Murphy Date: Wed, 4 May 2022 11:53:20 +0100 Subject: [PATCH] iommu: Make sysfs robust for non-API groups Groups created by VFIO backends outside the core IOMMU API should never be passed directly into the API itself, however they still expose their standard sysfs attributes, so we can still stumble across them that way. Take care to consider those cases before jumping into our normal assumptions of a fully-initialised core API group. Fixes: 3f6634d997db ("iommu: Use right way to retrieve iommu_ops") Reported-by: Jan Stancek Signed-off-by: Robin Murphy --- drivers/iommu/iommu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 29906bc16371..41ea2deaee03 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -510,6 +510,13 @@ int iommu_get_group_resv_regions(struct iommu_group *group, list_for_each_entry(device, &group->devices, list) { struct list_head dev_resv_regions; + /* + * Non-API groups still expose reserved_regions in sysfs, + * so filter out calls that get here that way. + */ + if (!device->dev->iommu) + break; + INIT_LIST_HEAD(&dev_resv_regions); iommu_get_resv_regions(device->dev, &dev_resv_regions); ret = iommu_insert_device_resv_regions(&dev_resv_regions, head); @@ -2977,7 +2984,7 @@ static ssize_t iommu_group_store_type(struct iommu_group *group, if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) return -EACCES; - if (WARN_ON(!group)) + if (WARN_ON(!group) || !group->default_domain) return -EINVAL; if (sysfs_streq(buf, "identity")) -- 2.35.3.dirty