From: yuyufen <yuyufen@huawei.com>
To: Mike Kravetz <mike.kravetz@oracle.com>, <linux-mm@kvack.org>
Cc: <kirill.shutemov@linux.intel.com>, <n-horiguchi@ah.jp.nec.com>,
<mhocko@kernel.org>
Subject: Re: [PATCH] hugetlbfs: fix protential null pointer dereference
Date: Thu, 11 Apr 2019 11:30:34 +0800 [thread overview]
Message-ID: <2b558d9b-0c43-0974-2eb0-e23d4d02b272@huawei.com> (raw)
In-Reply-To: <c7daf190-6a8b-0e3a-7eba-854d01962675@oracle.com>
On 2019/4/11 2:56, Mike Kravetz wrote:
> On 4/9/19 9:20 PM, yuyufen wrote:
>> Hi, Mike
>>
>> On 2019/4/10 11:38, Mike Kravetz wrote:
>>> On 4/9/19 7:50 PM, Yufen Yu wrote:
>>>> After commit 58b6e5e8f1ad ("hugetlbfs: fix memory leak for resv_map"),
>>>> i_mapping->private_data will be NULL for mode that is not regular and link.
>>>> Then, it might cause NULL pointer derefernce in hugetlb_reserve_pages()
>>>> when do_mmap. We can avoid protential null pointer dereference by
>>>> judging whether it have been allocated.
>>>>
>>>> Fixes: 58b6e5e8f1ad ("hugetlbfs: fix memory leak for resv_map")
>>>> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
>>>> Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
>>>> Cc: Michal Hocko <mhocko@kernel.org>
>>>> Signed-off-by: Yufen Yu <yuyufen@huawei.com>
>>> Thanks for catching this. I mistakenly thought all the code was checking
>>> for NULL resv_map. That certainly is one (and only) place where it is not
>>> checked. Have you verified that this is possible? Should be pretty easy
>>> to do. If you have not, I can try to verify tomorrow.
>> I honestly say that I don't have verified.
> I do not believe it is possible to hit this condition in the existing code.
> Why? hugetlb_reserve_pages is only called from two places:
> 1) hugetlb_file_setup. In this case the inode is created immediately before
> the call with S_IFREG. Hence a regular file so resv_map created.
> 2) hugetlbfs_file_mmap called via do_mmap. In do_mmap, there is the following
> check:
> if (!file->f_op->mmap)
> return -ENODEV;
> In the hugetlbfs inode creation code (hugetlbfs_get_inode), note that
> inode->i_fop = &hugetlbfs_file_operations (containing hugetlbfs_file_mmap)
> is only set for inodes of type S_IFREG. And, resv_map are created
> for these. So, mmap will not call hugetlbfs_file_mmap for non-S_IFREG
> hugetlbfs inode. Instead, it will return ENODEV.
>
> Even if we can not hit this condition today, I still believe it would be
> a good idea to make this type of change. It would prevent a possible NULL
> dereference in case the structure of code changes in the future. However,
> unless I am mistaken this is not needed as an urgent fix.
Thanks for so much detailed explanation. I will resend v2 including
these suggestion.
prev parent reply other threads:[~2019-04-11 3:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-10 2:50 Yufen Yu
2019-04-10 3:38 ` Mike Kravetz
2019-04-10 4:20 ` yuyufen
2019-04-10 18:56 ` Mike Kravetz
2019-04-11 3:30 ` yuyufen [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=2b558d9b-0c43-0974-2eb0-e23d4d02b272@huawei.com \
--to=yuyufen@huawei.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mike.kravetz@oracle.com \
--cc=n-horiguchi@ah.jp.nec.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