[PATCH v8 2/7] um: use execveat to create userspace MMs
Tiwei Bie
tiwei.btw at antgroup.com
Thu Sep 19 05:18:52 PDT 2024
On 2024/7/5 03:05, Benjamin Berg wrote:
[...]
> static int userspace_tramp(void *stack)
> {
> - struct sigaction sa;
> - void *addr;
> - int fd;
> + char *const argv[] = { "uml-userspace", NULL };
> + int pipe_fds[2];
> unsigned long long offset;
> - unsigned long segv_handler = STUB_CODE +
> - (unsigned long) stub_segv_handler -
> - (unsigned long) __syscall_stub_start;
> -
> - ptrace(PTRACE_TRACEME, 0, 0, 0);
> -
> - signal(SIGTERM, SIG_DFL);
> - signal(SIGWINCH, SIG_IGN);
> -
> - fd = phys_mapping(uml_to_phys(__syscall_stub_start), &offset);
> - addr = mmap64((void *) STUB_CODE, UM_KERN_PAGE_SIZE,
> - PROT_EXEC, MAP_FIXED | MAP_PRIVATE, fd, offset);
> - if (addr == MAP_FAILED) {
> - os_info("mapping mmap stub at 0x%lx failed, errno = %d\n",
> - STUB_CODE, errno);
> - exit(1);
> + struct stub_init_data init_data = {
> + .stub_start = STUB_START,
> + .segv_handler = STUB_CODE +
> + (unsigned long) stub_segv_handler -
> + (unsigned long) __syscall_stub_start,
> + };
> + struct iomem_region *iomem;
> + int ret;
> +
> + init_data.stub_code_fd = phys_mapping(uml_to_phys(__syscall_stub_start),
> + &offset);
> + init_data.stub_code_offset = MMAP_OFFSET(offset);
> +
> + init_data.stub_data_fd = phys_mapping(uml_to_phys(stack), &offset);
> + init_data.stub_data_offset = MMAP_OFFSET(offset);
> +
> + /* Set CLOEXEC on all FDs and then unset on all memory related FDs */
> + close_range(0, ~0U, CLOSE_RANGE_CLOEXEC);
I got a link error on Ubuntu 22.04.4 (glibc-2.35) when STATIC_LINK is enabled:
/usr/bin/ld:
/usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libc.a(close_range.o):
in function `__close_range':
(.text+0x0): multiple definition of `__close_range';
fs/file.o:/home/test/linux/fs/file.c:741: first defined here
We probably need something like this:
diff --git a/arch/um/Makefile b/arch/um/Makefile
index 00b63bac5eff..31e367e8ab4d 100644
--- a/arch/um/Makefile
+++ b/arch/um/Makefile
@@ -61,7 +61,8 @@ KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
$(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap \
-Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp \
-Din6addr_loopback=kernel_in6addr_loopback \
- -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr
+ -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr \
+ -D__close_range=kernel__close_range
KBUILD_RUSTFLAGS += -Crelocation-model=pie
Regards,
Tiwei
More information about the linux-um
mailing list