* [PATCH mm] mm: hugetlb: Add checks for NULL for vma returned from find_vma. find_vma may return NULL, that's why its return value is usually checked for NULL.
@ 2023-01-16 10:05 Esina Ekaterina
2023-01-16 13:24 ` David Hildenbrand
0 siblings, 1 reply; 4+ messages in thread
From: Esina Ekaterina @ 2023-01-16 10:05 UTC (permalink / raw)
To: Mike Kravetz
Cc: Esina Ekaterina, Andrew Morton, linux-mm, linux-kernel, lvc-project
Found by Astra Linux on behalf of Linux Verification Center
(linuxtesting.org) with SVACE.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Esina Ekaterina <eesina@astralinux.ru>
---
mm/hugetlb.c | 32 ++++++++++++++++++--------------
1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 3499b3803384..2162bfcf8f46 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -5394,9 +5394,6 @@ void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma,
pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud)
{
struct vm_area_struct *vma = find_vma(mm, addr);
- struct address_space *mapping = vma->vm_file->f_mapping;
- pgoff_t idx = ((addr - vma->vm_start) >> PAGE_SHIFT) +
- vma->vm_pgoff;
struct vm_area_struct *svma;
unsigned long saddr;
pte_t *spte = NULL;
@@ -5406,18 +5403,25 @@ pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud)
if (!vma_shareable(vma, addr))
return (pte_t *)pmd_alloc(mm, pud, addr);
- i_mmap_assert_locked(mapping);
- vma_interval_tree_foreach(svma, &mapping->i_mmap, idx, idx) {
- if (svma == vma)
- continue;
+ if (vma && vma->vm_file && vm->vm_file->f_mapping
+ && vma->vm_start && vma->vm->vm_pgoff) {
+ struct address_space *mapping = vma->vm_file->f_mapping;
+ pgoff_t idx = ((addr - vma->vm_start) >> PAGE_SHIFT) +
+ vma->vm_pgoff;
- saddr = page_table_shareable(svma, vma, addr, idx);
- if (saddr) {
- spte = huge_pte_offset(svma->vm_mm, saddr,
- vma_mmu_pagesize(svma));
- if (spte) {
- get_page(virt_to_page(spte));
- break;
+ i_mmap_assert_locked(mapping);
+ vma_interval_tree_foreach(svma, &mapping->i_mmap, idx, idx) {
+ if (svma == vma)
+ continue;
+
+ saddr = page_table_shareable(svma, vma, addr, idx);
+ if (saddr) {
+ spte = huge_pte_offset(svma->vm_mm, saddr,
+ vma_mmu_pagesize(svma));
+ if (spte) {
+ get_page(virt_to_page(spte));
+ break;
+ }
}
}
}
--
2.39.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH mm] mm: hugetlb: Add checks for NULL for vma returned from find_vma. find_vma may return NULL, that's why its return value is usually checked for NULL.
2023-01-16 10:05 [PATCH mm] mm: hugetlb: Add checks for NULL for vma returned from find_vma. find_vma may return NULL, that's why its return value is usually checked for NULL Esina Ekaterina
@ 2023-01-16 13:24 ` David Hildenbrand
[not found] ` <182575210.374192581.1673881818398.JavaMail.zimbra@astralinux.ru>
0 siblings, 1 reply; 4+ messages in thread
From: David Hildenbrand @ 2023-01-16 13:24 UTC (permalink / raw)
To: Esina Ekaterina, Mike Kravetz
Cc: Andrew Morton, linux-mm, linux-kernel, lvc-project
On 16.01.23 11:05, Esina Ekaterina wrote:
> Found by Astra Linux on behalf of Linux Verification Center
> (linuxtesting.org) with SVACE.
Please trim the subject and move details to the description.
What are the symptoms? How exactly does this BUG manifest? What is this
patch fixing?
--
Thanks,
David / dhildenb
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH mm] mm: hugetlb: Add checks for NULL for vma returned from find_vma. find_vma may return NULL, that's why its return value is usually checked for NULL.
[not found] ` <182575210.374192581.1673881818398.JavaMail.zimbra@astralinux.ru>
@ 2023-01-16 15:12 ` David Hildenbrand
2023-01-16 15:21 ` Matthew Wilcox
0 siblings, 1 reply; 4+ messages in thread
From: David Hildenbrand @ 2023-01-16 15:12 UTC (permalink / raw)
To: Екатерина
Есина,
Mike Kravetz
Cc: Andrew Morton, linux-mm, linux-kernel, lvc-project
On 16.01.23 16:10, Екатерина Есина wrote:
> Sorry, I've noticed that I'd sent the patch without description and sent
> version 2.
> Function find_vma may return NULL, that's why its return value is
> usually checked for NULL. In this case vma and its fields also should be
> checked before dereferencing to avoid NULL pointer dereference
Thanks, but again
What are the symptoms? How exactly does this BUG manifest?
For example, does the kernel crash, and if so, how can it be triggered?
--
Thanks,
David / dhildenb
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH mm] mm: hugetlb: Add checks for NULL for vma returned from find_vma. find_vma may return NULL, that's why its return value is usually checked for NULL.
2023-01-16 15:12 ` David Hildenbrand
@ 2023-01-16 15:21 ` Matthew Wilcox
0 siblings, 0 replies; 4+ messages in thread
From: Matthew Wilcox @ 2023-01-16 15:21 UTC (permalink / raw)
To: David Hildenbrand
Cc: Екатерина
Есина,
Mike Kravetz, Andrew Morton, linux-mm, linux-kernel, lvc-project
On Mon, Jan 16, 2023 at 04:12:48PM +0100, David Hildenbrand wrote:
> On 16.01.23 16:10, Екатерина Есина wrote:
> > Sorry, I've noticed that I'd sent the patch without description and sent
> > version 2.
> > Function find_vma may return NULL, that's why its return value is
> > usually checked for NULL. In this case vma and its fields also should be
> > checked before dereferencing to avoid NULL pointer dereference
>
> Thanks, but again
>
> What are the symptoms? How exactly does this BUG manifest?
>
> For example, does the kernel crash, and if so, how can it be triggered?
SVACE is a static analyser. It's not very good, but the people who run
it are extremely persistent about submitting patches based solely on the
output of the tool and doing no human checks of their own. Probably best
to just ignore them, or NACK them.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-01-16 15:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-16 10:05 [PATCH mm] mm: hugetlb: Add checks for NULL for vma returned from find_vma. find_vma may return NULL, that's why its return value is usually checked for NULL Esina Ekaterina
2023-01-16 13:24 ` David Hildenbrand
[not found] ` <182575210.374192581.1673881818398.JavaMail.zimbra@astralinux.ru>
2023-01-16 15:12 ` David Hildenbrand
2023-01-16 15:21 ` Matthew Wilcox
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®