Skip to contentSkip to conversation

a question about protection_map[]

DISCUSSION Xishi Qiu 2 participants 4 messages Jul 11, 2016 – Jul 12, 2016 Memory management

lore
Share & tools
lore

Xishi Qiu

author
#0 lore raw

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

#1 lore raw
Quoted 4 lines · Xishi Qiu

Hi,

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

Quoted 8 lines

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.

Signature · 7 lines
 Kirill A. Shutemov

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#2 lore raw
Quoted 11 lines · Kirill A. Shutemov
Quoted 10 lines · Xishi Qiu

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)]
Quoted 9 lines
Quoted 2 lines

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

#3 lore raw
Quoted 23 lines · Xishi Qiu
Quoted 11 lines · Kirill A. Shutemov
Quoted 10 lines · Xishi Qiu

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)]
Quoted 9 lines
Quoted 2 lines

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.

Quoted 5 lines

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

Signature · 7 lines
 Kirill A. Shutemov

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