linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* a question about protection_map[]
@ 2016-07-11 10:12 Xishi Qiu
  2016-07-11 13:30 ` Kirill A. Shutemov
  0 siblings, 1 reply; 4+ messages in thread
From: Xishi Qiu @ 2016-07-11 10:12 UTC (permalink / raw)
  To: alan; +Cc: Linux MM, LKML

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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: a question about protection_map[]
  2016-07-11 10:12 a question about protection_map[] Xishi Qiu
@ 2016-07-11 13:30 ` Kirill A. Shutemov
  2016-07-12  1:31   ` Xishi Qiu
  0 siblings, 1 reply; 4+ messages in thread
From: Kirill A. Shutemov @ 2016-07-11 13:30 UTC (permalink / raw)
  To: Xishi Qiu; +Cc: alan, Linux MM, LKML

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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: a question about protection_map[]
  2016-07-11 13:30 ` Kirill A. Shutemov
@ 2016-07-12  1:31   ` Xishi Qiu
  2016-07-12  1:46     ` Kirill A. Shutemov
  0 siblings, 1 reply; 4+ messages in thread
From: Xishi Qiu @ 2016-07-12  1:31 UTC (permalink / raw)
  To: Kirill A. Shutemov; +Cc: alan, Linux MM, LKML

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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: a question about protection_map[]
  2016-07-12  1:31   ` Xishi Qiu
@ 2016-07-12  1:46     ` Kirill A. Shutemov
  0 siblings, 0 replies; 4+ messages in thread
From: Kirill A. Shutemov @ 2016-07-12  1:46 UTC (permalink / raw)
  To: Xishi Qiu; +Cc: alan, Linux MM, LKML

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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-07-12  1:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-11 10:12 a question about protection_map[] Xishi Qiu
2016-07-11 13:30 ` Kirill A. Shutemov
2016-07-12  1:31   ` Xishi Qiu
2016-07-12  1:46     ` Kirill A. Shutemov

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).