From e425187d176a5e09bc5253faefc9cfc8454da0a3 Mon Sep 17 00:00:00 2001 From: Haryslee Date: Tue, 3 Aug 2021 20:40:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dmprotect=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=9C=B0=E5=9D=80=E5=8C=BA=E9=97=B4=E7=9A=84=E6=9D=83?= =?UTF-8?q?=E9=99=90=E5=90=8E=EF=BC=8C=E7=9B=B8=E5=BA=94=E7=9A=84=E5=8C=BA?= =?UTF-8?q?=E9=97=B4=E5=90=8D=E4=B8=A2=E5=A4=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 背景:对于mmap映射的区间,修改权限后对应的区间名丢失 方案:mprotect修改权限后,对应区间名继承原区间名 close #I43R40 Signed-off-by: Haryslee Change-Id: I969c93528cbecc2ded4e437e5aac8f82b8baa609 --- kernel/base/vm/los_vm_syscall.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/kernel/base/vm/los_vm_syscall.c b/kernel/base/vm/los_vm_syscall.c index 01890a7b..df8b246d 100644 --- a/kernel/base/vm/los_vm_syscall.c +++ b/kernel/base/vm/los_vm_syscall.c @@ -257,7 +257,28 @@ REGION_ALLOC_FAILED: return ret; } -int LOS_DoMprotect(VADDR_T vaddr, size_t len, unsigned long prot) +STATIC UINT32 OsInheritOldRegionName(UINT32 oldRegionFlags) +{ + UINT32 vmFlags = 0; + + if (oldRegionFlags & VM_MAP_REGION_FLAG_HEAP) { + vmFlags |= VM_MAP_REGION_FLAG_HEAP; + } else if (oldRegionFlags & VM_MAP_REGION_FLAG_STACK) { + vmFlags |= VM_MAP_REGION_FLAG_STACK; + } else if (oldRegionFlags & VM_MAP_REGION_FLAG_TEXT) { + vmFlags |= VM_MAP_REGION_FLAG_TEXT; + } else if (oldRegionFlags & VM_MAP_REGION_FLAG_VDSO) { + vmFlags |= VM_MAP_REGION_FLAG_VDSO; + } else if (oldRegionFlags & VM_MAP_REGION_FLAG_MMAP) { + vmFlags |= VM_MAP_REGION_FLAG_MMAP; + } else if (oldRegionFlags & VM_MAP_REGION_FLAG_SHM) { + vmFlags |= VM_MAP_REGION_FLAG_SHM; + } + + return vmFlags; +} + +INT32 LOS_DoMprotect(VADDR_T vaddr, size_t len, unsigned long prot) { LosVmSpace *space = OsCurrProcessGet()->vmSpace; LosVmMapRegion *region = NULL; @@ -291,7 +312,7 @@ int LOS_DoMprotect(VADDR_T vaddr, size_t len, unsigned long prot) len = LOS_Align(len, PAGE_SIZE); /* can't operation cross region */ - if (region->range.base + region->range.size < vaddr + len) { + if ((region->range.base + region->range.size) < (vaddr + len)) { ret = -EINVAL; goto OUT_MPROTECT; } @@ -303,6 +324,7 @@ int LOS_DoMprotect(VADDR_T vaddr, size_t len, unsigned long prot) vmFlags = OsCvtProtFlagsToRegionFlags(prot, 0); vmFlags |= (region->regionFlags & VM_MAP_REGION_FLAG_SHARED) ? VM_MAP_REGION_FLAG_SHARED : 0; + vmFlags |= OsInheritOldRegionName(region->regionFlags); region = LOS_RegionFind(space, vaddr); if (region == NULL) { ret = -ENOMEM;