From: Ralph Campbell <rcampbell@nvidia.com> To: <linux-mm@kvack.org> Cc: linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, "Jérôme Glisse" <jglisse@redhat.com>, "Jason Gunthorpe" <jgg@mellanox.com>, "Andrew Morton" <akpm@linux-foundation.org>, "Christoph Hellwig" <hch@lst.de>, "Ralph Campbell" <rcampbell@nvidia.com> Subject: [PATCH 1/2] mm/hmm: hmm_range_fault() NULL pointer bug Date: Fri, 23 Aug 2019 15:17:52 -0700 [thread overview] Message-ID: <20190823221753.2514-2-rcampbell@nvidia.com> (raw) In-Reply-To: <20190823221753.2514-1-rcampbell@nvidia.com> Although hmm_range_fault() calls find_vma() to make sure that a vma exists before calling walk_page_range(), hmm_vma_walk_hole() can still be called with walk->vma == NULL if the start and end address are not contained within the vma range. hmm_range_fault() /* calls find_vma() but no range check */ walk_page_range() /* calls find_vma(), sets walk->vma = NULL */ __walk_page_range() walk_pgd_range() walk_p4d_range() walk_pud_range() hmm_vma_walk_hole() hmm_vma_walk_hole_() hmm_vma_do_fault() handle_mm_fault(vma=0) Signed-off-by: Ralph Campbell <rcampbell@nvidia.com> --- mm/hmm.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/hmm.c b/mm/hmm.c index fc05c8fe78b4..29371485fe94 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -229,6 +229,9 @@ static int hmm_vma_do_fault(struct mm_walk *walk, unsigned long addr, struct vm_area_struct *vma = walk->vma; vm_fault_t ret; + if (!vma) + goto err; + if (hmm_vma_walk->flags & HMM_FAULT_ALLOW_RETRY) flags |= FAULT_FLAG_ALLOW_RETRY; if (write_fault) @@ -239,12 +242,14 @@ static int hmm_vma_do_fault(struct mm_walk *walk, unsigned long addr, /* Note, handle_mm_fault did up_read(&mm->mmap_sem)) */ return -EAGAIN; } - if (ret & VM_FAULT_ERROR) { - *pfn = range->values[HMM_PFN_ERROR]; - return -EFAULT; - } + if (ret & VM_FAULT_ERROR) + goto err; return -EBUSY; + +err: + *pfn = range->values[HMM_PFN_ERROR]; + return -EFAULT; } static int hmm_pfns_bad(unsigned long addr, -- 2.20.1
WARNING: multiple messages have this Message-ID (diff)
From: Ralph Campbell <rcampbell@nvidia.com> To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, "Jérôme Glisse" <jglisse@redhat.com>, "Jason Gunthorpe" <jgg@mellanox.com>, "Andrew Morton" <akpm@linux-foundation.org>, "Christoph Hellwig" <hch@lst.de>, "Ralph Campbell" <rcampbell@nvidia.com> Subject: [PATCH 1/2] mm/hmm: hmm_range_fault() NULL pointer bug Date: Fri, 23 Aug 2019 15:17:52 -0700 [thread overview] Message-ID: <20190823221753.2514-2-rcampbell@nvidia.com> (raw) In-Reply-To: <20190823221753.2514-1-rcampbell@nvidia.com> Although hmm_range_fault() calls find_vma() to make sure that a vma exists before calling walk_page_range(), hmm_vma_walk_hole() can still be called with walk->vma == NULL if the start and end address are not contained within the vma range. hmm_range_fault() /* calls find_vma() but no range check */ walk_page_range() /* calls find_vma(), sets walk->vma = NULL */ __walk_page_range() walk_pgd_range() walk_p4d_range() walk_pud_range() hmm_vma_walk_hole() hmm_vma_walk_hole_() hmm_vma_do_fault() handle_mm_fault(vma=0) Signed-off-by: Ralph Campbell <rcampbell@nvidia.com> --- mm/hmm.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/hmm.c b/mm/hmm.c index fc05c8fe78b4..29371485fe94 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -229,6 +229,9 @@ static int hmm_vma_do_fault(struct mm_walk *walk, unsigned long addr, struct vm_area_struct *vma = walk->vma; vm_fault_t ret; + if (!vma) + goto err; + if (hmm_vma_walk->flags & HMM_FAULT_ALLOW_RETRY) flags |= FAULT_FLAG_ALLOW_RETRY; if (write_fault) @@ -239,12 +242,14 @@ static int hmm_vma_do_fault(struct mm_walk *walk, unsigned long addr, /* Note, handle_mm_fault did up_read(&mm->mmap_sem)) */ return -EAGAIN; } - if (ret & VM_FAULT_ERROR) { - *pfn = range->values[HMM_PFN_ERROR]; - return -EFAULT; - } + if (ret & VM_FAULT_ERROR) + goto err; return -EBUSY; + +err: + *pfn = range->values[HMM_PFN_ERROR]; + return -EFAULT; } static int hmm_pfns_bad(unsigned long addr, -- 2.20.1
next prev parent reply other threads:[~2019-08-23 22:18 UTC|newest] Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-08-23 22:17 [PATCH 0/2] mm/hmm: two bug fixes for hmm_range_fault() Ralph Campbell 2019-08-23 22:17 ` Ralph Campbell 2019-08-23 22:17 ` Ralph Campbell [this message] 2019-08-23 22:17 ` [PATCH 1/2] mm/hmm: hmm_range_fault() NULL pointer bug Ralph Campbell 2019-08-24 22:37 ` Christoph Hellwig 2019-08-24 22:37 ` Christoph Hellwig 2019-08-26 18:02 ` Ralph Campbell 2019-08-26 18:02 ` Ralph Campbell 2019-08-26 18:09 ` Jason Gunthorpe 2019-08-26 18:21 ` Ralph Campbell 2019-08-23 22:17 ` [PATCH 2/2] mm/hmm: hmm_range_fault() infinite loop Ralph Campbell 2019-08-23 22:17 ` Ralph Campbell 2019-08-24 22:39 ` Christoph Hellwig 2019-08-27 18:41 ` Jason Gunthorpe 2019-08-27 20:16 ` Ralph Campbell 2019-08-27 20:16 ` Ralph Campbell 2019-08-27 22:22 ` Jason Gunthorpe 2019-08-27 22:48 ` [PATCH 0/2] mm/hmm: two bug fixes for hmm_range_fault() Jason Gunthorpe
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=20190823221753.2514-2-rcampbell@nvidia.com \ --to=rcampbell@nvidia.com \ --cc=akpm@linux-foundation.org \ --cc=amd-gfx@lists.freedesktop.org \ --cc=dri-devel@lists.freedesktop.org \ --cc=hch@lst.de \ --cc=jgg@mellanox.com \ --cc=jglisse@redhat.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=nouveau@lists.freedesktop.org \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.