From: Nicolin Chen <nicolinc@nvidia.com>
To: Jason Gunthorpe <jgg@nvidia.com>, Tina Zhang <tina.zhang@intel.com>
Cc: Kevin Tian <kevin.tian@intel.com>,
Lu Baolu <baolu.lu@linux.intel.com>, <iommu@lists.linux.dev>,
<linux-kernel@vger.kernel.org>,
Vasant Hegde <vasant.hegde@amd.com>
Subject: Re: [v6 PATCH 4/5] iommu: Support mm PASID 1:n with sva domains
Date: Wed, 11 Oct 2023 12:33:27 -0700 [thread overview]
Message-ID: <ZSb4h+I/IKHjVKLK@Asurada-Nvidia> (raw)
In-Reply-To: <ba9ed927-0672-4252-9cfd-c43febf68d49@intel.com>
On Wed, Oct 11, 2023 at 09:26:12PM +0800, Tina Zhang wrote:
> On 10/11/23 20:39, Jason Gunthorpe wrote:
> > On Wed, Oct 11, 2023 at 02:51:31PM +0800, Tina Zhang wrote:
> >
> > > diff --git a/kernel/fork.c b/kernel/fork.c
> > > index 3b6d20dfb9a8..985403a7a747 100644
> > > --- a/kernel/fork.c
> > > +++ b/kernel/fork.c
> > > @@ -1277,7 +1277,6 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p,
> > > mm_init_cpumask(mm);
> > > mm_init_aio(mm);
> > > mm_init_owner(mm, p);
> > > - mm_pasid_init(mm);
> > > RCU_INIT_POINTER(mm->exe_file, NULL);
> > > mmu_notifier_subscriptions_init(mm);
> > > init_tlb_flush_pending(mm);
> >
> > Nicolin debugged his crash report last night and sent me the details.
> >
> > This hunk is the cause of the bug that Nicolin reported.
> >
> > The dup_mm() flow does:
> >
> > static struct mm_struct *dup_mm(struct task_struct *tsk,
> > struct mm_struct *oldmm)
> > {
> > struct mm_struct *mm;
> > int err;
> >
> > mm = allocate_mm();
> > if (!mm)
> > goto fail_nomem;
> >
> > memcpy(mm, oldmm, sizeof(*mm));
> >
> > if (!mm_init(mm, tsk, mm->user_ns))
> > goto fail_nomem;
> >
> > It is essential that mm_pasid_init() zero the new pointer otherwise,
> > due to the memcpy, after a fork two mm structs will point to the same
> > thing and one will UAF/doube free.
> Good catch.
>
> Thanks,
> -Tina
> >
> > Keep mm_pasid_init() and add zeroing the new pointer to it.
Yea, testing with this sees no more WARN_ON:
---------------------------------------------------------
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 3d782fd0f485..4bc3c49cdaf9 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -1208,2 +1208,6 @@ static inline bool tegra_dev_iommu_get_stream_id(struct device *dev, u32 *stream
#ifdef CONFIG_IOMMU_SVA
+static inline void mm_pasid_init(struct mm_struct *mm)
+{
+ mm->iommu_mm = NULL;
+}
static inline bool mm_valid_pasid(struct mm_struct *mm)
@@ -1240,2 +1244,3 @@ static inline u32 iommu_sva_get_pasid(struct iommu_sva *handle)
}
+static inline void mm_pasid_init(struct mm_struct *mm) {}
static inline bool mm_valid_pasid(struct mm_struct *mm) { return false; }
diff --git a/kernel/fork.c b/kernel/fork.c
index f06392dd1ca8..d2e12b6d2b18 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1276,2 +1276,3 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p,
mm_init_owner(mm, p);
+ mm_pasid_init(mm);
RCU_INIT_POINTER(mm->exe_file, NULL);
---------------------------------------------------------
I'll confirm with v7 too.
Thanks
Nicolin
next prev parent reply other threads:[~2023-10-11 19:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-11 6:51 [v6 PATCH 0/5] Share sva domains with all devices bound to a mm Tina Zhang
2023-10-11 6:51 ` [v6 PATCH 1/5] iommu/vt-d: Remove mm->pasid in intel_sva_bind_mm() Tina Zhang
2023-10-11 6:51 ` [v6 PATCH 2/5] iommu: Add mm_get_enqcmd_pasid() helper function Tina Zhang
2023-10-11 15:44 ` Jason Gunthorpe
2023-10-11 6:51 ` [v6 PATCH 3/5] mm: Add structure to keep sva information Tina Zhang
2023-10-11 6:51 ` [v6 PATCH 4/5] iommu: Support mm PASID 1:n with sva domains Tina Zhang
2023-10-11 12:39 ` Jason Gunthorpe
2023-10-11 13:26 ` Tina Zhang
2023-10-11 19:33 ` Nicolin Chen [this message]
2023-10-11 6:51 ` [v6 PATCH 5/5] mm: Deprecate pasid field Tina Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZSb4h+I/IKHjVKLK@Asurada-Nvidia \
--to=nicolinc@nvidia.com \
--cc=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tina.zhang@intel.com \
--cc=vasant.hegde@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®