[PATCH v6 6/7] mseal, system mappings: uprobe mapping

jeffxu
2025-02-24T17:45:32Z

From: Jeff Xu <jeffxu@chromium.org>

Provide support to mseal the uprobe mapping.

Unlike other system mappings, the uprobe mapping is not
established during program startup. However, its lifetime is the same
as the process's lifetime. It could be sealed from creation.

Signed-off-by: Jeff Xu <jeffxu@chromium.org>
---
kernel/events/uprobes.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 2ca797cbe465..c23ca39b81ac 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1662,6 +1662,7 @@ static const struct vm_special_mapping xol_mapping = {
static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
{
struct vm_area_struct *vma;
+ unsigned long vm_flags;
int ret;

if (mmap_write_lock_killable(mm))
@@ -1682,8 +1683,10 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
}
}

+ vm_flags = VM_EXEC|VM_MAYEXEC|VM_DONTCOPY|VM_IO;
+ vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;
vma = _install_special_mapping(mm, area->vaddr, PAGE_SIZE,
- VM_EXEC|VM_MAYEXEC|VM_DONTCOPY|VM_IO,
+ vm_flags,
&xol_mapping);
if (IS_ERR(vma)) {
ret = PTR_ERR(vma);
--
2.48.1.601.g30ceb7b040-goog