From: "Yin, Fengwei" <nh26223@qq.com>
To: Rik van Riel <riel@surriel.com>,
Edward Adam Davis <eadavis@qq.com>,
syzbot+6ada951e7c0f7bc8a71e@syzkaller.appspotmail.com
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, llvm@lists.linux.dev,
mike.kravetz@oracle.com, muchun.song@linux.dev,
nathan@kernel.org, ndesaulniers@google.com,
syzkaller-bugs@googlegroups.com, trix@redhat.com
Subject: Re: [PATCH] mm/hugetlb: fix null ptr defer in hugetlb_vma_lock_write
Date: Thu, 2 Nov 2023 21:46:31 +0800 [thread overview]
Message-ID: <tencent_43E55580901FF6162FFFE418CFA7BFE3C80A@qq.com> (raw)
In-Reply-To: <3382634358afa9b95dc4f6db8a53a136d4b9e9cb.camel@surriel.com>
On 1/11/2023 22:27, Rik van Riel wrote:
> On Wed, 2023-11-01 at 14:36 +0800, Edward Adam Davis wrote:
>> When obtaining resv_map from vma, it is necessary to simultaneously
>> determine
>> the flag HPAGE_RESV_OWNER of vm_private_data.
>> Only when they are met simultaneously, resv_map is valid.
>>
>> Reported-and-tested-by:
>> syzbot+6ada951e7c0f7bc8a71e@syzkaller.appspotmail.com
>> Fixes: bf4916922c60 ("hugetlbfs: extend hugetlb_vma_lock to private
>> VMAs")
>> Signed-off-by: Edward Adam Davis <eadavis@qq.com>
>> ---
>> include/linux/hugetlb.h | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
>> index 47d25a5e1933..1a3ec1aee1a3 100644
>> --- a/include/linux/hugetlb.h
>> +++ b/include/linux/hugetlb.h
>> @@ -1265,9 +1265,11 @@ static inline bool __vma_shareable_lock(struct
>> vm_area_struct *vma)
>> return (vma->vm_flags & VM_MAYSHARE) && vma->vm_private_data;
>> }
>>
>> +#define HPAGE_RESV_OWNER (1UL << 0)
>> static inline bool __vma_private_lock(struct vm_area_struct *vma)
>> {
>> - return (!(vma->vm_flags & VM_MAYSHARE)) && vma-
>>> vm_private_data;
>> + return (!(vma->vm_flags & VM_MAYSHARE)) && vma-
>>> vm_private_data &&
>> + ((unsigned long)vma->vm_private_data &
>> HPAGE_RESV_OWNER);
>> }
I am wondering whether this line should be:
return (!(vma->vm_flags & VM_MAYSHARE)) &&
((unsigned long)vma->vm_private_data & HPAGE_RESV_OWNER);
or even:
return (unsigned long)vma->vm_private_data & HPAGE_RESV_OWNER;
because mm/hugetlb.c has:
"We know private mapping must have HPAGE_RESV_OWNER set."
>
> This could be cleaned up a bit by moving the HPAGE_RESV_OWNER
> definition (and its friends) into hugetlb.h, as well as the
> is_vma_resv_set() helper function.
>
> Then __vma_private_lock() can just call is_vma_resv_set(),
> and open coding a duplicate of the same code.
>
> Not having duplicates of the code will make it much harder
> to "miss a spot" with future changes.
>
> I am still struggling to find a place where we might leave
> HPAGE_RESV_OWNER behind on a pointer that is otherwise NULL,
> but if your tests show this fixes the issue, I'm all for it :)
>
Like you said, vma->vm_private_data is cleared during fork().
But I saw following possible code path in child process:
hugetlb_wp()
unmap_ref_private() if alloc_hugetlb_folio fails
unmap_hugepage_range()
__unmap_hugepage_range()
set_vma_resv_flags(vma, HPAGE_RESV_UNMAPPED)
vm_private_data become 0x2 which is none NULL without HPAGE_RESV_OWNER
bit.
prev parent reply other threads:[~2023-11-02 13:46 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-29 9:27 [syzbot] [mm?] general protection fault " syzbot
2023-10-31 18:38 ` Rik van Riel
2023-11-02 12:15 ` Aleksandr Nogikh
2023-11-01 6:36 ` [PATCH] mm/hugetlb: fix null ptr defer " Edward Adam Davis
2023-11-01 14:27 ` Rik van Riel
2023-11-02 12:58 ` Edward Adam Davis
2023-11-02 23:29 ` kernel test robot
2023-11-02 23:29 ` kernel test robot
2023-11-03 0:56 ` Rik van Riel
2023-11-03 1:26 ` kernel test robot
2023-11-03 2:24 ` Mike Kravetz
2023-11-03 2:28 ` Mike Kravetz
2023-11-03 2:37 ` Mike Kravetz
2023-11-03 3:15 ` Rik van Riel
2023-11-03 4:31 ` Mike Kravetz
2023-11-08 3:22 ` Mike Kravetz
2023-11-02 13:46 ` Yin, Fengwei [this message]
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=tencent_43E55580901FF6162FFFE418CFA7BFE3C80A@qq.com \
--to=nh26223@qq.com \
--cc=akpm@linux-foundation.org \
--cc=eadavis@qq.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=llvm@lists.linux.dev \
--cc=mike.kravetz@oracle.com \
--cc=muchun.song@linux.dev \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=riel@surriel.com \
--cc=syzbot+6ada951e7c0f7bc8a71e@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=trix@redhat.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