Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1440433 > unrolled thread

a question about protection_map[]

Started byXishi Qiu <qiuxishi@huawei.com>
First post2016-07-11 12:20 +0200
Last post2016-07-12 03:50 +0200
Articles 4 — 2 participants

Back to article view | Back to linux.kernel


Contents

  a question about protection_map[] Xishi Qiu <qiuxishi@huawei.com> - 2016-07-11 12:20 +0200
    Re: a question about protection_map[] "Kirill A. Shutemov" <kirill@shutemov.name> - 2016-07-11 15:40 +0200
      Re: a question about protection_map[] Xishi Qiu <qiuxishi@huawei.com> - 2016-07-12 03:40 +0200
        Re: a question about protection_map[] "Kirill A. Shutemov" <kirill@shutemov.name> - 2016-07-12 03:50 +0200

#1440433 — a question about protection_map[]

FromXishi Qiu <qiuxishi@huawei.com>
Date2016-07-11 12:20 +0200
Subjecta question about protection_map[]
Message-ID<rTGtH-5FU-1@gated-at.bofh.it>
Hi,

We can use mprotect to set read only or read/write.

mprotect_fixup()
	vma_set_page_prot()
		vm_pgprot_modify()
			vm_get_page_prot()
				protection_map[vm_flags & (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]

The following code shows that prots from __P001(PROT_READ) and __P010(PROT_WRITE)
are the same, so how does it distinguish read only or read/write from mprotect?

pgprot_t protection_map[16] = {
	__P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
	__S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
};

#define __P001	PAGE_READONLY
#define __P010	PAGE_COPY

#define PAGE_READONLY		__pgprot(_PAGE_PRESENT | _PAGE_USER |	\
					 _PAGE_ACCESSED | _PAGE_NX)

#define PAGE_COPY_NOEXEC	__pgprot(_PAGE_PRESENT | _PAGE_USER |	\
					 _PAGE_ACCESSED | _PAGE_NX)
#define PAGE_COPY		PAGE_COPY_NOEXEC


Thanks,
Xishi Qiu

[toc] | [next] | [standalone]


#1440622

From"Kirill A. Shutemov" <kirill@shutemov.name>
Date2016-07-11 15:40 +0200
Message-ID<rTJBf-7EI-9@gated-at.bofh.it>
In reply to#1440433
On Mon, Jul 11, 2016 at 06:12:30PM +0800, Xishi Qiu wrote:
> Hi,
> 
> We can use mprotect to set read only or read/write.
> 
> mprotect_fixup()
> 	vma_set_page_prot()
> 		vm_pgprot_modify()
> 			vm_get_page_prot()
> 				protection_map[vm_flags & (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]
> 
> The following code shows that prots from __P001(PROT_READ) and __P010(PROT_WRITE)
> are the same, so how does it distinguish read only or read/write from mprotect?

It doesn't.

Write protection will be removed by fault handler on next write access to
the page. Somewhat suboptiomal, but zero page implemenation relies on this
to work properly.

-- 
 Kirill A. Shutemov

[toc] | [prev] | [next] | [standalone]


#1441014

FromXishi Qiu <qiuxishi@huawei.com>
Date2016-07-12 03:40 +0200
Message-ID<rTUQ2-6xe-31@gated-at.bofh.it>
In reply to#1440622
On 2016/7/11 21:30, Kirill A. Shutemov wrote:

> On Mon, Jul 11, 2016 at 06:12:30PM +0800, Xishi Qiu wrote:
>> Hi,
>>
>> We can use mprotect to set read only or read/write.
>>
>> mprotect_fixup()
>> 	vma_set_page_prot()
>> 		vm_pgprot_modify()
>> 			vm_get_page_prot()
>> 				protection_map[vm_flags & (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]
>>
>> The following code shows that prots from __P001(PROT_READ) and __P010(PROT_WRITE)
>> are the same, so how does it distinguish read only or read/write from mprotect?
> 
> It doesn't.
> 
> Write protection will be removed by fault handler on next write access to
> the page. Somewhat suboptiomal, but zero page implemenation relies on this
> to work properly.
> 

Hi Kirill,

I know, PAGE_READONLY and PAGE_COPY are both missed _PAGE_RW,
so it will cause page fault, then we will set new prot flag from
vma, right?

Thanks,
Xishi Qiu

[toc] | [prev] | [next] | [standalone]


#1441017

From"Kirill A. Shutemov" <kirill@shutemov.name>
Date2016-07-12 03:50 +0200
Message-ID<rTUZH-6B4-9@gated-at.bofh.it>
In reply to#1441014
On Tue, Jul 12, 2016 at 09:31:30AM +0800, Xishi Qiu wrote:
> On 2016/7/11 21:30, Kirill A. Shutemov wrote:
> 
> > On Mon, Jul 11, 2016 at 06:12:30PM +0800, Xishi Qiu wrote:
> >> Hi,
> >>
> >> We can use mprotect to set read only or read/write.
> >>
> >> mprotect_fixup()
> >> 	vma_set_page_prot()
> >> 		vm_pgprot_modify()
> >> 			vm_get_page_prot()
> >> 				protection_map[vm_flags & (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]
> >>
> >> The following code shows that prots from __P001(PROT_READ) and __P010(PROT_WRITE)
> >> are the same, so how does it distinguish read only or read/write from mprotect?
> > 
> > It doesn't.
> > 
> > Write protection will be removed by fault handler on next write access to
> > the page. Somewhat suboptiomal, but zero page implemenation relies on this
> > to work properly.
> > 
> 
> Hi Kirill,
> 
> I know, PAGE_READONLY and PAGE_COPY are both missed _PAGE_RW,
> so it will cause page fault, then we will set new prot flag from
> vma, right?

Yes. See wp_page_reuse().

-- 
 Kirill A. Shutemov

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web