]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
um: Calculate stub data address relative to stub code
authorBenjamin Berg <benjamin.berg@intel.com>
Thu, 19 Sep 2024 12:45:07 +0000 (14:45 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Thu, 10 Oct 2024 11:37:22 +0000 (13:37 +0200)
Instead of using the current stack pointer, we can also use the current
instruction to calculate where the stub data is. With this the stub data
only needs to be aligned to a full page boundary.

Changing this has the advantage that we do not have a hole in the memory
space above the stub data (which would need to be explicitly cleared).

Another motivation to do this is that with the planned addition of a
SECCOMP based userspace the stack pointer may not be fully trustworthy.

Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
Link: https://patch.msgid.link/20240919124511.282088-7-benjamin@sipsolutions.net
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
arch/um/kernel/um_arch.c
arch/x86/um/shared/sysdep/stub_32.h
arch/x86/um/shared/sysdep/stub_64.h

index 99cdf4b2d6482d23a7df9a8a229d23400a8a8957..427024f32b9fe35c0aec4efecf211db6994848f7 100644 (file)
@@ -325,10 +325,8 @@ int __init linux_main(int argc, char **argv)
                add_arg(DEFAULT_COMMAND_LINE_CONSOLE);
 
        host_task_size = os_get_top_address();
-       /* reserve a few pages for the stubs (taking care of data alignment) */
-       /* align the data portion */
-       BUILD_BUG_ON(!is_power_of_2(STUB_DATA_PAGES));
-       stub_start = (host_task_size - 1) & ~(STUB_DATA_PAGES * PAGE_SIZE - 1);
+       /* reserve a few pages for the stubs */
+       stub_start = host_task_size - STUB_DATA_PAGES * PAGE_SIZE;
        /* another page for the code portion */
        stub_start -= PAGE_SIZE;
        host_task_size = stub_start;
index 0b44a86dd346e414505b7f91279388fc02d03e8f..631a18d0ff441f09bea2f2fe4fb7d978bbcc7cbb 100644 (file)
@@ -112,10 +112,14 @@ static __always_inline void *get_stub_data(void)
        unsigned long ret;
 
        asm volatile (
-               "movl %%esp,%0 ;"
-               "andl %1,%0"
+               "call _here_%=;"
+               "_here_%=:"
+               "popl %0;"
+               "andl %1, %0 ;"
+               "addl %2, %0 ;"
                : "=a" (ret)
-               : "g" (~(STUB_DATA_PAGES * UM_KERN_PAGE_SIZE - 1)));
+               : "g" (~(UM_KERN_PAGE_SIZE - 1)),
+                 "g" (UM_KERN_PAGE_SIZE));
 
        return (void *)ret;
 }
index 8e4ff39dcade59ad9ee4933366440c69c43e1d7b..17153dfd780a435fe2c6f25f94ff0a6edefbb0b9 100644 (file)
@@ -117,10 +117,12 @@ static __always_inline void *get_stub_data(void)
        unsigned long ret;
 
        asm volatile (
-               "movq %%rsp,%0 ;"
-               "andq %1,%0"
+               "lea 0(%%rip), %0;"
+               "andq %1, %0 ;"
+               "addq %2, %0 ;"
                : "=a" (ret)
-               : "g" (~(STUB_DATA_PAGES * UM_KERN_PAGE_SIZE - 1)));
+               : "g" (~(UM_KERN_PAGE_SIZE - 1)),
+                 "g" (UM_KERN_PAGE_SIZE));
 
        return (void *)ret;
 }