* [PATCH mm v2] mm: hugetlb: Add checks for NULL for vma returned from find_vma.
@ 2023-01-16 10:39 Esina Ekaterina
2023-01-16 18:30 ` Mike Kravetz
0 siblings, 1 reply; 3+ messages in thread
From: Esina Ekaterina @ 2023-01-16 10:39 UTC (permalink / raw)
To: Mike Kravetz
Cc: Esina Ekaterina, Andrew Morton, linux-mm, linux-kernel,
lvc-project
find_vma may return NULL, that's why its return value
is usually checked for NULL. vma should be checked before dereferencing
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 related [flat|nested] 3+ messages in thread* Re: [PATCH mm v2] mm: hugetlb: Add checks for NULL for vma returned from find_vma.
2023-01-16 10:39 [PATCH mm v2] mm: hugetlb: Add checks for NULL for vma returned from find_vma Esina Ekaterina
@ 2023-01-16 18:30 ` Mike Kravetz
2023-01-17 7:57 ` Екатерина Есина
0 siblings, 1 reply; 3+ messages in thread
From: Mike Kravetz @ 2023-01-16 18:30 UTC (permalink / raw)
To: Esina Ekaterina; +Cc: Andrew Morton, linux-mm, linux-kernel, lvc-project
On 01/16/23 13:39, Esina Ekaterina wrote:
> find_vma may return NULL, that's why its return value
> is usually checked for NULL. vma should be checked before dereferencing
>
> 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(-)
This is not the latest version of the code. What version are you
targeting?
I would claim that find_vma() can not return NULL in previous versions
of the code which this patch seems to target. Why? This routine is
called with mmap sema held and we know addr is part of the vma.
--
Mike Kravetz
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH mm v2] mm: hugetlb: Add checks for NULL for vma returned from find_vma.
2023-01-16 18:30 ` Mike Kravetz
@ 2023-01-17 7:57 ` Екатерина Есина
0 siblings, 0 replies; 3+ messages in thread
From: Екатерина Есина @ 2023-01-17 7:57 UTC (permalink / raw)
To: Mike Kravetz; +Cc: Andrew Morton, linux-mm, linux-kernel, lvc-project
[-- Attachment #1: Type: text/plain, Size: 1440 bytes --]
The patch can be applied up to 5.12 version and in 5.13 the logic of the function huge_pmd_share changes. And in later versions vma is passed as a function argument.
Best regards,
Ekaterina Esina
-----Original Message-----
From: Mike <mike.kravetz@oracle.com>
To: Esina <eesina@astralinux.ru>
Cc: Andrew <akpm@linux-foundation.org>; linux-mm <linux-mm@kvack.org>; linux-kernel <linux-kernel@vger.kernel.org>; lvc-project <lvc-project@linuxtesting.org>
Date: Monday, 16 January 2023 9:30 PM MSK
Subject: Re: [PATCH mm v2] mm: hugetlb: Add checks for NULL for vma returned from find_vma.
On 01/16/23 13:39, Esina Ekaterina wrote:
> find_vma may return NULL, that's why its return value
> is usually checked for NULL. vma should be checked before dereferencing
>
> 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(-)
This is not the latest version of the code. What version are you
targeting?
I would claim that find_vma() can not return NULL in previous versions
of the code which this patch seems to target. Why? This routine is
called with mmap sema held and we know addr is part of the vma.
--
Mike Kravetz
[-- Attachment #2: Type: text/html, Size: 2162 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-01-17 7:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-16 10:39 [PATCH mm v2] mm: hugetlb: Add checks for NULL for vma returned from find_vma Esina Ekaterina
2023-01-16 18:30 ` Mike Kravetz
2023-01-17 7:57 ` Екатерина Есина
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.