Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2129966iob; Thu, 5 May 2022 16:43:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIAWwE83p6kRNB+thG8rzmRcKy5ltyg3HqgaQtnxgJ6Q4H2Oth4/LjJeoDO9hVO+/dkBxz X-Received: by 2002:a17:906:5d05:b0:6f4:e78:a064 with SMTP id g5-20020a1709065d0500b006f40e78a064mr574259ejt.292.1651794185601; Thu, 05 May 2022 16:43:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651794185; cv=none; d=google.com; s=arc-20160816; b=LJVLpvDA6b42MzHP2A74X/RqGFIgYgTJZt5IveZ11kXVpOrWn3cmKbPTH6mmufvRpr 1+0I2VnZAhijXbpM99rMQmbjGu2Ga48ZgfUVj5qm297Gp7P0apWLXM5OIWtiCO5Qhl6v A69IKQAtnaChcaYBCBfuecL9Vov5fQD0UPHj/8jEB3vkuiBCWH8OrdQ4dnmBVghTHM4W 1C6z4dR2XehR8E8WiSBDLk8vE5aBOOL9KHMZ5MImcW6m7/J/VtwKiA5isWjm5BABGKo9 3pLquhY+Yahm5oLsfgWA5XMmlUrC0J/96Rbf0XVGDGCD02GQgN+I249Bae8m/Ax6IKOo YtXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=PaKDp0AYChF2TvU0gnmgAfapbqSSfeuarNmx4DaDCMY=; b=X+/sM9wa5Ll1fJS9jv5vao7OwOYiF+VrnFDAgLtQfEr/H1RizI8DqXW1w4fGIbD8FG 9HXZhGMx7N5aOQ8UZnmSYtLm5WwjW/piHQ9ao/32uIErmzX0WydQ46UAlnBR5xAnNoJv Dch9KVF0eoyAhPCAwCaEF6gUiKPBuoLrP3XjyYBNjOfZmuHn9lZzYTS/+pgxAkEeCRZV AMTVZMoXI31MDT1NryRmW7KGEGbA9VLfS6dIDbWxKmTckA0S9mWIJ8hD+eshtbjAEClq Kf0wa2+Hhwu8Rpn4xGPMKi2lvBLhfxzydFTiOxVC1T+yAbYk0Jm/cFyE4eNd05vj1gkK o4ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Fin0CAAM; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg12-20020a170907a40c00b006e12386caa3si4097738ejc.748.2022.05.05.16.42.41; Thu, 05 May 2022 16:43:05 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Fin0CAAM; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349303AbiEDMMm (ORCPT + 99 others); Wed, 4 May 2022 08:12:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349160AbiEDMMl (ORCPT ); Wed, 4 May 2022 08:12:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D6E5C1EAF8 for ; Wed, 4 May 2022 05:09:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651666145; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=PaKDp0AYChF2TvU0gnmgAfapbqSSfeuarNmx4DaDCMY=; b=Fin0CAAMThFakBO72tNJNbMtKS435o4Sjk11NGi++eouVMTL2A8LKdpkM+BjxyXc9IGD/0 DXFgTryD7HK4slJ1J2wExiSAKlP046yeua26M+Jq0gdgepB13cAmLEw5bHmuAzfviV4yVT ckMJChAGnwi0uCZISkOOIR87Uj5Wz+w= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-611-JWPdbUmDMxWs0ShBRo0ZOg-1; Wed, 04 May 2022 08:09:01 -0400 X-MC-Unique: JWPdbUmDMxWs0ShBRo0ZOg-1 Received: by mail-lf1-f69.google.com with SMTP id bp17-20020a056512159100b00472631eb445so532085lfb.13 for ; Wed, 04 May 2022 05:09:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PaKDp0AYChF2TvU0gnmgAfapbqSSfeuarNmx4DaDCMY=; b=BPjqzXr/kGHj3sxO9N/jl9eFDzjggw9iCVs/sOyCq9p9+htTp2TnWQG9aqtCy8S9+4 FlB9vxB53ttq8Eu37fdgN+iExUdrG9aQ2dpNA0PyLcbI1FFRWCJJ4OeDUe+5EfnJ/L9H PQ2ptLnYeD1TfwaFIOBmlapVP7U3g2AfHKsMVwvhgfkOeCVzzYd72TJvm4uhI8EnQDc9 c5ishCoYveWG/cmBth3sKXMeaOp+ZISoH5iHdtryfPul6IbP480bAaLTXeHMoYZwCWeI 5me6TSyGj0F7EjzlhPIrpVG2HrVUL7GV/+PwVxPBytmWh4eOvEk4fgS1WVFq0WtPvK1P t2Tg== X-Gm-Message-State: AOAM530+1u2aXmt1Wam25RofMOQqc0XvOCLUzTkMIJy7xxBDuj89DiuV O6Ado+xzbR1JTZqWOhwJpze6cyVyrJdCiegAOWG1/EkkftQrt2RiwnyR+tfaNhZAr2Jdfdie3EK XwCFjghvuh4j4eI7xKOh4Ejdzq7aMdbDF71YcvfBy X-Received: by 2002:a19:640d:0:b0:472:75e:7373 with SMTP id y13-20020a19640d000000b00472075e7373mr13561741lfb.46.1651666139920; Wed, 04 May 2022 05:08:59 -0700 (PDT) X-Received: by 2002:a19:640d:0:b0:472:75e:7373 with SMTP id y13-20020a19640d000000b00472075e7373mr13561730lfb.46.1651666139723; Wed, 04 May 2022 05:08:59 -0700 (PDT) MIME-Version: 1.0 References: <20220216025249.3459465-1-baolu.lu@linux.intel.com> <20220216025249.3459465-8-baolu.lu@linux.intel.com> <20220504075356.GA2361844@janakin.usersys.redhat.com> <8d6c30e0-dcf7-56f8-c44b-2d8bdb1dc04c@arm.com> In-Reply-To: <8d6c30e0-dcf7-56f8-c44b-2d8bdb1dc04c@arm.com> From: Jan Stancek Date: Wed, 4 May 2022 14:08:43 +0200 Message-ID: Subject: Re: [bug] NULL pointer deref after 3f6634d997db ("iommu: Use right way to retrieve iommu_ops") To: Robin Murphy Cc: Lu Baolu , 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, lkml , Christoph Hellwig , Bruno Goncalves Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,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 Wed, May 4, 2022 at 1:14 PM Robin Murphy wrote: > > 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 for quick reply. Yes, it does. # cat /sys/kernel/iommu_groups/0/reserved_regions # echo auto > /sys/kernel/iommu_groups/0/type -bash: echo: write error: Invalid argument Tested-by: Jan Stancek > > 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 >