* iommu/vt-d: drop mm use count if address is not canonical @ 2019-04-17 9:12 Pan Bian 2019-04-26 13:38 ` Joerg Roedel 0 siblings, 1 reply; 3+ messages in thread From: Pan Bian @ 2019-04-17 9:12 UTC (permalink / raw) To: Joerg Roedel; +Cc: iommu, linux-kernel, Pan Bian The use count of svm->mm is incremented by mmget_not_zero. However, it is not dropped when the address is not canonical. This patch fixes the bug. Fixes: 9d8c3af31607("iommu/vt-d: IOMMU Page Request needs to check if address is canonical.") Signed-off-by: Pan Bian <bianpan2016@163.com> --- drivers/iommu/intel-svm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c index 3a4b09a..2630d2e 100644 --- a/drivers/iommu/intel-svm.c +++ b/drivers/iommu/intel-svm.c @@ -574,8 +574,10 @@ static irqreturn_t prq_event_thread(int irq, void *d) goto bad_req; /* If address is not canonical, return invalid response */ - if (!is_canonical_address(address)) + if (!is_canonical_address(address)) { + mmput(svm->mm); goto bad_req; + } down_read(&svm->mm->mmap_sem); vma = find_extend_vma(svm->mm, address); -- 2.7.4 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: iommu/vt-d: drop mm use count if address is not canonical 2019-04-17 9:12 iommu/vt-d: drop mm use count if address is not canonical Pan Bian @ 2019-04-26 13:38 ` Joerg Roedel 2019-04-26 15:47 ` Jacob Pan 0 siblings, 1 reply; 3+ messages in thread From: Joerg Roedel @ 2019-04-26 13:38 UTC (permalink / raw) To: Pan Bian; +Cc: iommu, linux-kernel, Jacob Pan, David Woodhouse [ Adding more people. ] On Wed, Apr 17, 2019 at 05:12:57PM +0800, Pan Bian wrote: > The use count of svm->mm is incremented by mmget_not_zero. However, it > is not dropped when the address is not canonical. This patch fixes the > bug. > > Fixes: 9d8c3af31607("iommu/vt-d: IOMMU Page Request needs to check if > address is canonical.") > > Signed-off-by: Pan Bian <bianpan2016@163.com> > --- > drivers/iommu/intel-svm.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c > index 3a4b09a..2630d2e 100644 > --- a/drivers/iommu/intel-svm.c > +++ b/drivers/iommu/intel-svm.c > @@ -574,8 +574,10 @@ static irqreturn_t prq_event_thread(int irq, void *d) > goto bad_req; > > /* If address is not canonical, return invalid response */ > - if (!is_canonical_address(address)) > + if (!is_canonical_address(address)) { > + mmput(svm->mm); > goto bad_req; > + } > > down_read(&svm->mm->mmap_sem); > vma = find_extend_vma(svm->mm, address); I think it is better to move the canonical address check before mmget_not_zero() like in the diff below. But I let David and Jacob comment on this. Regards, Joerg diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c index 8f87304f915c..5e9e1eee8336 100644 --- a/drivers/iommu/intel-svm.c +++ b/drivers/iommu/intel-svm.c @@ -586,14 +586,15 @@ static irqreturn_t prq_event_thread(int irq, void *d) * any faults on kernel addresses. */ if (!svm->mm) goto bad_req; - /* If the mm is already defunct, don't handle faults. */ - if (!mmget_not_zero(svm->mm)) - goto bad_req; /* If address is not canonical, return invalid response */ if (!is_canonical_address(address)) goto bad_req; + /* If the mm is already defunct, don't handle faults. */ + if (!mmget_not_zero(svm->mm)) + goto bad_req; + down_read(&svm->mm->mmap_sem); vma = find_extend_vma(svm->mm, address); if (!vma || address < vma->vm_start) ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: iommu/vt-d: drop mm use count if address is not canonical 2019-04-26 13:38 ` Joerg Roedel @ 2019-04-26 15:47 ` Jacob Pan 0 siblings, 0 replies; 3+ messages in thread From: Jacob Pan @ 2019-04-26 15:47 UTC (permalink / raw) To: Joerg Roedel Cc: Pan Bian, iommu, linux-kernel, David Woodhouse, jacob.jun.pan On Fri, 26 Apr 2019 15:38:46 +0200 Joerg Roedel <joro@8bytes.org> wrote: > [ Adding more people. ] > > On Wed, Apr 17, 2019 at 05:12:57PM +0800, Pan Bian wrote: > > The use count of svm->mm is incremented by mmget_not_zero. However, > > it is not dropped when the address is not canonical. This patch > > fixes the bug. > > > > Fixes: 9d8c3af31607("iommu/vt-d: IOMMU Page Request needs to check > > if address is canonical.") > > > > Signed-off-by: Pan Bian <bianpan2016@163.com> > > --- > > drivers/iommu/intel-svm.c | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c > > index 3a4b09a..2630d2e 100644 > > --- a/drivers/iommu/intel-svm.c > > +++ b/drivers/iommu/intel-svm.c > > @@ -574,8 +574,10 @@ static irqreturn_t prq_event_thread(int irq, > > void *d) goto bad_req; > > > > /* If address is not canonical, return invalid > > response */ > > - if (!is_canonical_address(address)) > > + if (!is_canonical_address(address)) { > > + mmput(svm->mm); > > goto bad_req; > > + } > > > > down_read(&svm->mm->mmap_sem); > > vma = find_extend_vma(svm->mm, address); > > I think it is better to move the canonical address check before > mmget_not_zero() like in the diff below. But I let David and Jacob > comment on this. > Looks good to me. Tested with PRQ and fake non canonical address then send an invalid page response. Tested-by: Jacob Pan <jacob.jun.pan@linux.intel.com> > Regards, > > Joerg > > diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c > index 8f87304f915c..5e9e1eee8336 100644 > --- a/drivers/iommu/intel-svm.c > +++ b/drivers/iommu/intel-svm.c > @@ -586,14 +586,15 @@ static irqreturn_t prq_event_thread(int irq, > void *d) > * any faults on kernel addresses. */ > if (!svm->mm) > goto bad_req; > - /* If the mm is already defunct, don't handle > faults. */ > - if (!mmget_not_zero(svm->mm)) > - goto bad_req; > > /* If address is not canonical, return invalid > response */ if (!is_canonical_address(address)) > goto bad_req; > > + /* If the mm is already defunct, don't handle > faults. */ > + if (!mmget_not_zero(svm->mm)) > + goto bad_req; > + > down_read(&svm->mm->mmap_sem); > vma = find_extend_vma(svm->mm, address); > if (!vma || address < vma->vm_start) [Jacob Pan] ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-04-26 15:44 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-04-17 9:12 iommu/vt-d: drop mm use count if address is not canonical Pan Bian 2019-04-26 13:38 ` Joerg Roedel 2019-04-26 15:47 ` Jacob Pan
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).