Date: Fri, 25 Aug 2023 01:08:38 GMT From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 6283f6e79456 - stable/13 - linuxolator: implement Linux' PROT_GROWSDOWN Message-ID: <202308250108.37P18cN7058548@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=6283f6e79456546e836442fc27d4c52e3cbc2134 commit 6283f6e79456546e836442fc27d4c52e3cbc2134 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2023-07-29 21:00:51 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2023-08-25 01:06:44 +0000 linuxolator: implement Linux' PROT_GROWSDOWN (cherry picked from commit 9b65fa69407808e710748875b0af98902110f128) --- sys/compat/cloudabi/cloudabi_mem.c | 2 +- sys/compat/freebsd32/freebsd32_misc.c | 2 +- sys/compat/linux/linux_mmap.c | 14 ++++++++++---- sys/sys/syscallsubr.h | 3 ++- sys/vm/vm_mmap.c | 9 +++++---- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/sys/compat/cloudabi/cloudabi_mem.c b/sys/compat/cloudabi/cloudabi_mem.c index 0b721aea4016..dadf4058f30d 100644 --- a/sys/compat/cloudabi/cloudabi_mem.c +++ b/sys/compat/cloudabi/cloudabi_mem.c @@ -124,7 +124,7 @@ cloudabi_sys_mem_protect(struct thread *td, return (error); return (kern_mprotect(td, (uintptr_t)uap->mapping, uap->mapping_len, - prot)); + prot, 0)); } int diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c index ac9486eb3f66..d708efcf91fe 100644 --- a/sys/compat/freebsd32/freebsd32_misc.c +++ b/sys/compat/freebsd32/freebsd32_misc.c @@ -480,7 +480,7 @@ freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap) prot |= PROT_EXEC; #endif return (kern_mprotect(td, (uintptr_t)PTRIN(uap->addr), uap->len, - prot)); + prot, 0)); } int diff --git a/sys/compat/linux/linux_mmap.c b/sys/compat/linux/linux_mmap.c index 527bd3979584..d371c1b0935a 100644 --- a/sys/compat/linux/linux_mmap.c +++ b/sys/compat/linux/linux_mmap.c @@ -225,16 +225,22 @@ out: int linux_mprotect_common(struct thread *td, uintptr_t addr, size_t len, int prot) { + int flags = 0; - /* XXX Ignore PROT_GROWSDOWN and PROT_GROWSUP for now. */ - prot &= ~(LINUX_PROT_GROWSDOWN | LINUX_PROT_GROWSUP); - if ((prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)) != 0) + /* XXX Ignore PROT_GROWSUP for now. */ + prot &= ~LINUX_PROT_GROWSUP; + if ((prot & ~(LINUX_PROT_GROWSDOWN | PROT_READ | PROT_WRITE | + PROT_EXEC)) != 0) return (EINVAL); + if ((prot & LINUX_PROT_GROWSDOWN) != 0) { + prot &= ~LINUX_PROT_GROWSDOWN; + flags |= VM_MAP_PROTECT_GROWSDOWN; + } #if defined(__amd64__) linux_fixup_prot(td, &prot); #endif - return (kern_mprotect(td, addr, len, prot)); + return (kern_mprotect(td, addr, len, prot, flags)); } /* diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h index d9cd3e7d7f3d..de3c7780fc2c 100644 --- a/sys/sys/syscallsubr.h +++ b/sys/sys/syscallsubr.h @@ -213,7 +213,8 @@ int kern_mmap_racct_check(struct thread *td, struct vm_map *map, vm_size_t size); int kern_mmap_maxprot(struct proc *p, int prot); int kern_mmap_req(struct thread *td, const struct mmap_req *mrp); -int kern_mprotect(struct thread *td, uintptr_t addr, size_t size, int prot); +int kern_mprotect(struct thread *td, uintptr_t addr, size_t size, + int prot, int flags); int kern_msgctl(struct thread *, int, int, struct msqid_ds *); int kern_msgrcv(struct thread *, int, void *, size_t, long, int, long *); int kern_msgsnd(struct thread *, int, const void *, size_t, int, long); diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c index b1cc0741fddb..703078d81393 100644 --- a/sys/vm/vm_mmap.c +++ b/sys/vm/vm_mmap.c @@ -642,16 +642,17 @@ int sys_mprotect(struct thread *td, struct mprotect_args *uap) { - return (kern_mprotect(td, (uintptr_t)uap->addr, uap->len, uap->prot)); + return (kern_mprotect(td, (uintptr_t)uap->addr, uap->len, + uap->prot, 0)); } int -kern_mprotect(struct thread *td, uintptr_t addr0, size_t size, int prot) +kern_mprotect(struct thread *td, uintptr_t addr0, size_t size, int prot, + int flags) { vm_offset_t addr; vm_size_t pageoff; int vm_error, max_prot; - int flags; addr = addr0; if ((prot & ~(_PROT_ALL | PROT_MAX(_PROT_ALL))) != 0) @@ -671,7 +672,7 @@ kern_mprotect(struct thread *td, uintptr_t addr0, size_t size, int prot) if (addr + size < addr) return (EINVAL); - flags = VM_MAP_PROTECT_SET_PROT; + flags |= VM_MAP_PROTECT_SET_PROT; if (max_prot != 0) flags |= VM_MAP_PROTECT_SET_MAXPROT; vm_error = vm_map_protect(&td->td_proc->p_vmspace->vm_map,
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202308250108.37P18cN7058548>