
On 2023/12/4 17:17, Wang Wensheng wrote:
ascend inclusion category: Feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8LNGH
---------------------------------------------
Add protections for the va reserved for sharepool. Forbid mremap/munmap to access that range.
Signed-off-by: Wang Wensheng <wangwensheng4@huawei.com> --- include/linux/share_pool.h | 27 +++++++++++++++++++++++++++ mm/mmap.c | 9 +++++++++ mm/mremap.c | 4 ++++ 3 files changed, 40 insertions(+)
diff --git a/include/linux/share_pool.h b/include/linux/share_pool.h index 87ce9eb9fa3e..bd2e0ca8f975 100644 --- a/include/linux/share_pool.h +++ b/include/linux/share_pool.h @@ -157,6 +157,23 @@ static inline void sp_init_mm(struct mm_struct *mm) mm->sp_group_master = NULL; }
+static inline bool sp_check_addr(unsigned long addr) +{ + if (sp_is_enabled() && mg_is_sharepool_addr(addr)) + return true; + else + return false; +} + +static inline bool sp_check_mmap_addr(unsigned long addr, unsigned long flags) +{ + if (sp_is_enabled() && mg_is_sharepool_addr(addr) && + !(flags & MAP_SHARE_POOL)) + return true; + else + return false; +} +
这种都可以直接return false了,不用else