From: David Hildenbrand <david@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>,
liusongtang <liusongtang@huawei.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
nixiaoming@huawei.com, young.liuyang@huawei.com,
wangkefeng@huawei.com
Subject: Re: [PATCH] mm/mprotect: reduce Committed_AS if memory protection is changed to PROT_NONE
Date: Tue, 3 May 2022 20:35:59 +0200 [thread overview]
Message-ID: <0fa49d1f-a05d-bdb1-df60-800ff5999d8e@redhat.com> (raw)
In-Reply-To: <20220426133401.9404190c5a5c6ff58b694c59@linux-foundation.org>
On 26.04.22 22:34, Andrew Morton wrote:
> On Tue, 26 Apr 2022 19:27:05 +0800 liusongtang <liusongtang@huawei.com> wrote:
>
>> If PROT_WRITE is set, the size of vm area will be added to Committed_AS.
>> However, if memory protection is changed to PROT_NONE,
>> the corresponding physical memory will not be used, but Committed_AS still
>> count the size of the PROT_NONE memory.
>>
>> This patch reduce Committed_AS and free the corresponding memory if
>> memory protection is changed to PROT_NONE.
>>
>> ...
>>
>> --- a/mm/mprotect.c
>> +++ b/mm/mprotect.c
>> @@ -497,6 +497,12 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
>> }
>>
>> success:
>> + if ((newflags & (VM_READ | VM_WRITE | VM_EXEC | VM_LOCKED | VM_ACCOUNT)) == VM_ACCOUNT) {
>> + zap_page_range(vma, start, end - start);
>> + newflags &= ~VM_ACCOUNT;
>> + vm_unacct_memory((end - start) >> PAGE_SHIFT);
>> + }
>> +
>> /*
>> * vm_flags and vm_page_prot are protected by the mmap_lock
>> * held in write mode.
>
> Surprised. If userspace does mprotect(addr, len. PROT_NONE) then
> mprotect(addr, len. PROT_READ), what is now at *addr? Zeroes?
>
I don't think so. I don't see any pages getting zapped at my quick test
(unless it's wrong) shows that data is maintained. Further, it could
violate POSIX semantics.
So this patch is wrong, there might have been anonymous pages populated.
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2022-05-03 18:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-26 11:27 [PATCH] mm/mprotect: reduce Committed_AS if memory protection is changed to PROT_NONE liusongtang
2022-04-26 20:34 ` Andrew Morton
2022-04-27 6:34 ` liusongtang
2022-05-03 18:35 ` David Hildenbrand [this message]
2022-04-30 15:41 ` [mm/mprotect] 5e1e18b334: kvm-unit-tests.eventinj.fail kernel test robot
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=0fa49d1f-a05d-bdb1-df60-800ff5999d8e@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liusongtang@huawei.com \
--cc=nixiaoming@huawei.com \
--cc=wangkefeng@huawei.com \
--cc=young.liuyang@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).