From: Michal Hocko <mhocko@kernel.org>
To: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Yufen Yu <yuyufen@huawei.com>,
linux-mm@kvack.org, kirill.shutemov@linux.intel.com,
n-horiguchi@ah.jp.nec.com
Subject: Re: [PATCH v2] hugetlbfs: fix protential null pointer dereference
Date: Thu, 11 Apr 2019 20:22:20 +0200 [thread overview]
Message-ID: <20190411182220.GD10383@dhcp22.suse.cz> (raw)
In-Reply-To: <b3287006-2d80-8ead-ea63-2047fc5ef602@oracle.com>
On Thu 11-04-19 09:52:45, Mike Kravetz wrote:
> On 4/11/19 1:19 AM, Michal Hocko wrote:
> > On Thu 11-04-19 11:53:18, Yufen Yu wrote:
> >> This patch can avoid protential null pointer dereference for resv_map.
> >>
> >> As Mike Kravetz say:
> >> 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.
> >
> > What kind of change would that be and wouldn't it require much more
> > changes?
> >
> > In other words it is not really clear why is this an improvement. Random
> > checks for NULL that cannot happen tend to be more confusing long term
> > because people will simply blindly follow them and build a cargo cult
> > around.
>
> Since that was my comment, I should reply.
>
> You are correct in that it would require significant changes to hit this
> issue. I 'think' Yufen Yu came up with this patch by examining the hugetlbfs
> code and noticing that this is the ONLY place where we do not check for
> NULL. Since I knew those other NULL checks were required, I was initially
> concerned about this situation. It took me some time and analysis to convince
> myself that this was OK. I don't want to make someone else repeat that.
> Perhaps we should just comment this to avoid any confusion?
>
> /*
> * resv_map can not be NULL here. 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;
> * hugetlbfs_get_inode only assigns hugetlbfs_file_operations to S_IFREG
> * inodes. Hence, resv_map will not be NULL.
> */
>
> Or, do you think that is too much?
> Ideally, that comment should have been added as part of 58b6e5e8f1ad
> ("hugetlbfs: fix memory leak for resv_map") as it could cause one to wonder
> if resv_map could be NULL.
I would much rather explain a comment explaining _when_ inode_resv_map
might return NULL than add checks just to be sure.
--
Michal Hocko
SUSE Labs
next prev parent reply other threads:[~2019-04-11 18:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-11 3:53 [PATCH v2] hugetlbfs: fix protential null pointer dereference Yufen Yu
2019-04-11 8:19 ` Michal Hocko
2019-04-11 16:52 ` Mike Kravetz
2019-04-11 18:22 ` Michal Hocko [this message]
2019-04-11 18:40 ` Mike Kravetz
2019-04-11 18:49 ` Michal Hocko
2019-04-15 10:26 ` William Kucharski
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=20190411182220.GD10383@dhcp22.suse.cz \
--to=mhocko@kernel.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=n-horiguchi@ah.jp.nec.com \
--cc=yuyufen@huawei.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;
as well as URLs for NNTP newsgroup(s).