linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Miaohe Lin <linmiaohe@huawei.com>
To: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Linux-MM <linux-mm@kvack.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Muchun Song <songmuchun@bytedance.com>
Subject: Re: [bug report] mm/hugetlb: possible data leak with huge pmd sharing
Date: Tue, 26 Jul 2022 15:14:17 +0800	[thread overview]
Message-ID: <2ec4cd05-5b3a-cd5c-7785-5a7236804bef@huawei.com> (raw)
In-Reply-To: <Yt7iVRaDGuIx8LVE@monkey>

On 2022/7/26 2:35, Mike Kravetz wrote:
> On 07/25/22 17:07, Miaohe Lin wrote:
>> Hi all:
>>     When I investigate the mm/hugetlb code, I found there's a possible data leak issue
>> with huge pmd sharing. Thank about the below scene:
>>
>>     1. Process A and process B shares huge pmd page.(vm_flags: VM_MAYSHARE but !VM_SHARED)
> 
> Thanks,
> 
> I often get confused about the setting of VM_MAYSHARE and VM_SHARED.  When
> you throw in the possibility of shared and anonymous, then I struggle a bit
> more.  At one time did an audit to get the meaning clear in my mind, but still
> struggle with the meanings.
> 
> Is it possible to have VM_MAYSHARE and !VM_SHARED on a hugetlb vma?  I only
> took a quick look and could not find a way for this to happen.  But, I> could have easily missed something.

Thanks for your reply. It's possible to have VM_MAYSHARE and !VM_SHARED on a hugetlb vma
with below code snippet:

...
    fd = open("/root/huge/hugepagefile", O_CREAT | O_RDONLY, 0755);
    if (fd < 0) {
            perror("Open failed");
            exit(1);
    }

    addr = mmap(0, 32UL*1024*1024, PROT_READ, MAP_SHARED, fd, 0);
...

cat /proc/<pid>/smaps:

400000000000-400002000000 r--s 00000000 00:2f 153780886                  /root/huge/hugepagefile
Size:              32768 kB
KernelPageSize:     2048 kB
MMUPageSize:        2048 kB
...
VmFlags: rd mr me ms de ht

/* sh: VM_SHARED, mw: VM_MAYWRITE, ms:VM_MAYSHARE */

So vm_flags is VM_MAYSHARE but !VM_SHARED.

But in this case, it's readonly. So the above scene won't happen. Sorry for make noise.

> 

Thanks for your comment again. :)



  reply	other threads:[~2022-07-26  7:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-25  9:07 Miaohe Lin
2022-07-25 18:35 ` Mike Kravetz
2022-07-26  7:14   ` Miaohe Lin [this message]
2022-07-26 17:18     ` Mike Kravetz
2022-07-27  1:49       ` Miaohe Lin

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=2ec4cd05-5b3a-cd5c-7785-5a7236804bef@huawei.com \
    --to=linmiaohe@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    --cc=songmuchun@bytedance.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