tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: PAX mprotect and JIT



In article <20170226213704.DED726038D%jupiter.mumble.net@localhost>,
Taylor R Campbell  <campbell+netbsd-tech-kern%mumble.net@localhost> wrote:
>
>The idiom I imagine is something like:
>
>	void *buf = mmap(NULL, len, PROT_READ|PROT_WRITE|PROT_EXEC,
>	    MAP_ANON|MAP_REMAPDUP, -1, 0);

This is never allowed (rwx).

>	/* initialize buf with machine instructions */
>	void *ip = mremap(buf, len, NULL, len, MAP_REMAPDUP);
>	mprotect(ip, len, PROT_EXEC);
>	munmap(buf, len);
>	/* jump to *ip */
>	void *buf = mremap(ip, len, NULL, len, MAP_REMAPDUP);
>	mprotect(buf, len, PROT_READ|PROT_WRITE);
>	/* update buf with modified instructions */
>	munmap(buf, len);

Why not:

	void *buf = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
	void *ip = mmap(buf, len, PROT_READ|PROT_EXEC, MAP_DUP, -1, 0);
	/* update buf with modified instructions */

christos



Home | Main Index | Thread Index | Old Index