General cleanups and fixes from SECCOMP patchset
Subsystems (4)
v3 cover General cleanups and fixes from SECCOMP patchset
From: Benjamin Berg <[email protected]>
Hi,
the SECCOMP patchset is not ready yet as I need to change it quite a bit for the FD passing based security model that was proposed.
Until then, the cleanups and small fixes from the start of the patchset are still relevant and it could be nice to pull them in anyway. So I am resending just these.
I purely rebased the patchset. There should be no other differences between v2 and v3 here.
Benjamin
Benjamin Berg (11):
um: Drop support for hosts without SYSEMU_SINGLESTEP support
um: Drop NULL check from start_userspace
um: Make errors to stop ptraced child fatal during startup
um: Don't use vfprintf() for os_info()
um: Do not use printk in SIGWINCH helper thread
um: Reap winch thread if it fails
um: Do not use printk in userspace trampoline
um: Always inline stub functions
um: Rely on PTRACE_SETREGSET to set FS/GS base registers
um: Remove unused register save/restore functions
um: Mark 32bit syscall helpers as clobbering memory
arch/um/drivers/chan_user.c | 42 +++++---- arch/um/drivers/line.c | 13 ++- arch/um/include/asm/processor-generic.h | 1 - arch/um/include/shared/kern_util.h | 3 +- arch/um/include/shared/os.h | 3 - arch/um/include/shared/ptrace_user.h | 41 --------- arch/um/include/shared/registers.h | 2 - arch/um/kernel/process.c | 12 +-- arch/um/kernel/ptrace.c | 2 - arch/um/kernel/signal.c | 12 --- arch/um/os-Linux/registers.c | 20 ---- arch/um/os-Linux/skas/process.c | 117 ++++++++---------------- arch/um/os-Linux/start_up.c | 111 ++++------------------ arch/um/os-Linux/util.c | 19 +++- arch/x86/um/asm/elf.h | 4 +- arch/x86/um/asm/processor_64.h | 3 - arch/x86/um/os-Linux/Makefile | 1 - arch/x86/um/os-Linux/prctl.c | 12 --- arch/x86/um/ptrace_32.c | 24 ----- arch/x86/um/ptrace_64.c | 26 ------ arch/x86/um/shared/sysdep/ptrace_32.h | 4 - arch/x86/um/shared/sysdep/ptrace_user.h | 12 +-- arch/x86/um/shared/sysdep/stub_32.h | 39 ++++---- arch/x86/um/shared/sysdep/stub_64.h | 17 ++-- arch/x86/um/syscalls_64.c | 62 +++---------- arch/x86/um/tls_64.c | 2 +- 26 files changed, 159 insertions(+), 445 deletions(-) delete mode 100644 arch/x86/um/os-Linux/prctl.c
Signature · 7 lines
2.41.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
PATCH v3 1/11 um: Drop support for hosts without SYSEMU_SINGLESTEP support
From: Benjamin Berg <[email protected]>
These features have existed since Linux 2.6.14 and can be considered widely available at this point. Also drop the backward compatibility code for PTRACE_SETOPTIONS.
----
v2:
* Continue to define PTRACE_SYSEMU_SINGLESTEP as glibc only added it in version 2.27.
--- arch/um/include/asm/processor-generic.h | 1 - arch/um/include/shared/kern_util.h | 3 +- arch/um/include/shared/ptrace_user.h | 41 --------------- arch/um/kernel/process.c | 12 +---- arch/um/kernel/ptrace.c | 2 - arch/um/kernel/signal.c | 12 ----- arch/um/os-Linux/skas/process.c | 60 ++++----------------- arch/um/os-Linux/start_up.c | 70 +++---------------------- arch/x86/um/ptrace_32.c | 24 --------- arch/x86/um/ptrace_64.c | 26 --------- arch/x86/um/shared/sysdep/ptrace_32.h | 4 -- arch/x86/um/shared/sysdep/ptrace_user.h | 12 ++--- 12 files changed, 24 insertions(+), 243 deletions(-)
arch/um/include/asm/processor-generic.h +0 -1
@@ -22,7 +22,6 @@ struct mm_struct;struct thread_struct {struct pt_regs regs;struct pt_regs *segv_regs; -int singlestep_syscall;void *fault_addr;jmp_buf *fault_catcher;struct task_struct *prev_sched;
arch/um/include/shared/kern_util.h +1 -2
@@ -34,7 +34,6 @@ extern int handle_page_fault(unsigned long address, unsigned long ip,extern unsigned int do_IRQ (int irq,struct uml_pt_regs *regs);extern void initial_thread_cb (void (*proc)(void *),void *arg); -extern int is_syscall (unsigned long addr);extern void timer_handler (int sig,struct siginfo *unused_si,struct uml_pt_regs *regs);
@@ -58,7 +57,7 @@ extern char *uml_strdup(const char *string);extern unsigned long to_irq_stack (unsigned long *mask_out);extern unsigned long from_irq_stack (int nested); -extern int singlestepping (void *t); +extern int singlestepping (void );extern void segv_handler (int sig,struct siginfo *unused_si,struct uml_pt_regs *regs);extern void bus_handler (int sig,struct siginfo *si,struct uml_pt_regs *regs);
arch/um/include/shared/ptrace_user.h +0 -41
45 lines not on this page · raw message
arch/um/kernel/process.c +2 -10
@@ -332,17 +332,9 @@ int __init make_proc_sysemu(void)late_initcall (make_proc_sysemu); -int singlestepping (void * t) +int singlestepping (void ) { -struct task_struct *task = t ? t : current; - -if (!test_thread_flag (TIF_SINGLESTEP )) -return 0 ; - -if (task->thread.singlestep_syscall) -return 1 ; - -return 2 ; +return test_thread_flag (TIF_SINGLESTEP ); }/*
arch/um/kernel/ptrace.c +0 -2
@@ -12,7 +12,6 @@void user_enable_single_step (struct task_struct *child) {set_tsk_thread_flag (child,TIF_SINGLESTEP ); - child->thread.singlestep_syscall =0 ;#ifdef SUBARCH_SET_SINGLESTEPPING SUBARCH_SET_SINGLESTEPPING (child,1 );
@@ -22,7 +21,6 @@ void user_enable_single_step(struct task_struct *child)void user_disable_single_step (struct task_struct *child) {clear_tsk_thread_flag (child,TIF_SINGLESTEP ); - child->thread.singlestep_syscall =0 ;#ifdef SUBARCH_SET_SINGLESTEPPING SUBARCH_SET_SINGLESTEPPING (child,0 );
arch/um/kernel/signal.c +0 -12
@@ -120,18 +120,6 @@ void do_signal(struct pt_regs *regs) } } -/* -* This closes a way to execute a system call on the host. If -* you set a breakpoint on a system call instruction and singlestep -* from it, the tracing thread used to PTRACE_SINGLESTEP the process -* rather than PTRACE_SYSCALL it, allowing the system call to execute -* on the host. The tracing thread will check this flag and -* PTRACE_SYSCALL if necessary. -*/ -if (test_thread_flag (TIF_SINGLESTEP )) - current->thread.singlestep_syscall = -is_syscall (PT_REGS_IP (¤t->thread.regs)); -/* * if there's no signal to deliver, we just put the saved sigmask * back
arch/um/os-Linux/skas/process.c +10 -50
104 lines not on this page · raw message
arch/um/os-Linux/start_up.c +6 -64
103 lines not on this page · raw message
arch/x86/um/ptrace_32.c +0 -24
@@ -25,30 +25,6 @@ void arch_switch_to(struct task_struct *to)printk (KERN_WARNING "arch_switch_tls failed, errno = EINVAL\n" ); } -int is_syscall (unsigned long addr) -{ -unsigned short instr; -int n; - - n =copy_from_user (&instr, (void __user *) addr,sizeof (instr)); -if (n) { -/* access_process_vm() grants access to vsyscall and stub, -* while copy_from_user doesn't. Maybe access_process_vm is -* slow, but that doesn't matter, since it will be called only -* in case of singlestepping, if copy_from_user failed. -*/ - n =access_process_vm (current, addr, &instr,sizeof (instr), -FOLL_FORCE ); -if (n !=sizeof (instr)) { -printk (KERN_ERR "is_syscall : failed to read " -"instruction from 0x%lx\n" , addr); -return 1 ; - } - } -/* int 0x80 or sysenter */ -return (instr ==0x80cd ) || (instr ==0x340f ); -} -/* determines which flags the user has access to. */ /* 1 = access 0 = no access */ #define FLAG_MASK 0x00044dd5
arch/x86/um/ptrace_64.c +0 -26
@@ -188,32 +188,6 @@ int peek_user(struct task_struct *child, long addr, long data)return put_user (tmp, (unsigned long *) data); } -/* XXX Mostly copied from sys-i386 */ -int is_syscall (unsigned long addr) -{ -unsigned short instr; -int n; - - n =copy_from_user (&instr, (void __user *) addr,sizeof (instr)); -if (n) { -/* -* access_process_vm() grants access to vsyscall and stub, -* while copy_from_user doesn't. Maybe access_process_vm is -* slow, but that doesn't matter, since it will be called only -* in case of singlestepping, if copy_from_user failed. -*/ - n =access_process_vm (current, addr, &instr,sizeof (instr), -FOLL_FORCE ); -if (n !=sizeof (instr)) { -printk ("is_syscall : failed to read instruction from " -"0x%lx\n" , addr); -return 1 ; - } - } -/* sysenter */ -return instr ==0x050f ; -} -static int get_fpregs (struct user_i387_struct __user *buf,struct task_struct *child) {int err, n, cpu = ((struct thread_info *) child->stack)->cpu;
arch/x86/um/shared/sysdep/ptrace_32.h +0 -4
@@ -8,10 +8,6 @@#define MAX_FP_NR HOST_FPX_SIZE -void set_using_sysemu (int value); -int get_using_sysemu (void ); -extern int sysemu_supported; -#define UPT_SYSCALL_ARG1 (r) UPT_BX(r)#define UPT_SYSCALL_ARG2 (r) UPT_CX(r)#define UPT_SYSCALL_ARG3 (r) UPT_DX(r)
arch/x86/um/shared/sysdep/ptrace_user.h +5 -7
@@ -15,14 +15,12 @@#define FP_SIZE ((HOST_FPX_SIZE > HOST_FP_SIZE) ? HOST_FPX_SIZE : HOST_FP_SIZE)#else #define FP_SIZE HOST_FP_SIZE +#endif /* -* x86_64 FC3 doesn't define this in /usr/include/linux/ptrace.h even though -* it's defined in the kernel's include/linux/ptrace.h. Additionally, use the -* 2.4 name and value for 2.4 host compatibility. +* glibc before 2.27 does not include PTRACE_SYSEMU_SINGLESTEP in its enum, +* ensure we have a definition by (re-)defining it here. */ -#ifndef PTRACE_OLDSETOPTIONS -#define PTRACE_OLDSETOPTIONS 21 -#endif - +#ifndef PTRACE_SYSEMU_SINGLESTEP +#define PTRACE_SYSEMU_SINGLESTEP 32#endif
Signature · 7 lines
2.41.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
PATCH v3 2/11 um: Drop NULL check from start_userspace
In reply to [email protected]From: Benjamin Berg <[email protected]>
start_userspace is only called from exactly one location, and the passed pointer for the userspace process stack cannot be NULL.
Remove the check, without changing the control flow.
--- arch/um/os-Linux/skas/process.c | 53 +++++++++++++++------------------ 1 file changed, 24 insertions(+), 29 deletions(-)
arch/um/os-Linux/skas/process.c +24 -29
@@ -189,7 +189,7 @@ extern char __syscall_stub_start[];/** * userspace_tramp() - userspace trampoline -* @stack: pointer to the new userspace stack page, can be NULL, if? FIXME: +* @stack: pointer to the new userspace stack page * * The userspace trampoline is used to setup a new userspace process in start_userspace() after it was clone()'ed. * This function will run on a temporary stack page.
@@ -204,9 +204,13 @@ extern char __syscall_stub_start[];*/ static int userspace_tramp (void *stack) { +struct sigaction sa;void *addr;int fd;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 );
@@ -222,34 +226,25 @@ static int userspace_tramp(void *stack)exit (1 ); } -if (stack !=NULL ) { - fd =phys_mapping (uml_to_phys (stack), &offset); - addr =mmap ((void *)STUB_DATA , -STUB_DATA_PAGES *UM_KERN_PAGE_SIZE ,PROT_READ |PROT_WRITE , -MAP_FIXED |MAP_SHARED , fd, offset); -if (addr ==MAP_FAILED ) { -printk (UM_KERN_ERR "mapping segfault stack at 0x%lx failed, errno = %d\n" , -STUB_DATA , errno); -exit (1 ); - } + fd =phys_mapping (uml_to_phys (stack), &offset); + addr =mmap ((void *)STUB_DATA , +STUB_DATA_PAGES *UM_KERN_PAGE_SIZE ,PROT_READ |PROT_WRITE , +MAP_FIXED |MAP_SHARED , fd, offset); +if (addr ==MAP_FAILED ) { +printk (UM_KERN_ERR "mapping segfault stack at 0x%lx failed, errno = %d\n" , +STUB_DATA , errno); +exit (1 ); } -if (stack !=NULL ) { -struct sigaction sa; - -unsigned long v =STUB_CODE + - (unsigned long ) stub_segv_handler - - (unsigned long ) __syscall_stub_start; - -set_sigstack ((void *)STUB_DATA ,STUB_DATA_PAGES *UM_KERN_PAGE_SIZE ); -sigemptyset (&sa.sa_mask); - sa.sa_flags =SA_ONSTACK |SA_NODEFER |SA_SIGINFO ; - sa.sa_sigaction = (void *) v; - sa.sa_restorer =NULL ; -if (sigaction (SIGSEGV , &sa,NULL ) <0 ) { -printk (UM_KERN_ERR "%s - setting SIGSEGV handler failed - errno = %d\n" , - __func__, errno); -exit (1 ); - } + +set_sigstack ((void *)STUB_DATA ,STUB_DATA_PAGES *UM_KERN_PAGE_SIZE ); +sigemptyset (&sa.sa_mask); + sa.sa_flags =SA_ONSTACK |SA_NODEFER |SA_SIGINFO ; + sa.sa_sigaction = (void *) segv_handler; + sa.sa_restorer =NULL ; +if (sigaction (SIGSEGV , &sa,NULL ) <0 ) { +printk (UM_KERN_ERR "%s - setting SIGSEGV handler failed - errno = %d\n" , + __func__, errno); +exit (1 ); }kill (os_getpid (),SIGSTOP );
@@ -261,7 +256,7 @@ int kill_userspace_mm[NR_CPUS];/** * start_userspace() - prepare a new userspace process -* @stub_stack: pointer to the stub stack. Can be NULL, if? FIXME: +* @stub_stack: pointer to the stub stack. * * Setups a new temporary stack page that is used while userspace_tramp() runs * Clones the kernel process into a new userspace process, with FDs only.
Signature · 7 lines
2.41.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
PATCH v3 3/11 um: Make errors to stop ptraced child fatal during startup
In reply to [email protected]From: Benjamin Berg <[email protected]>
For the detection code to check whether SYSEMU_SINGLESTEP works correctly we needed some error cases while stopping to be non-fatal. However, at this point stop_ptraced_child must always succeed, and we can therefore simplify it slightly to exit immediately on error.
--- arch/um/os-Linux/start_up.c | 41 +++++++++++-------------------------- 1 file changed, 12 insertions(+), 29 deletions(-)
arch/um/os-Linux/start_up.c +12 -29
@@ -112,35 +112,20 @@ static int start_ptraced_child(void)return pid; } -/* When testing for SYSEMU support, if it is one of the broken versions, we -* must just avoid using sysemu, not panic, but only if SYSEMU features are -* broken. -* So only for SYSEMU features we test mustpanic, while normal host features -* must work anyway! -*/ -static int stop_ptraced_child (int pid,int exitcode,int mustexit) +static void stop_ptraced_child (int pid,int exitcode) { -int status, n, ret =0 ; +int status, n; + +if (ptrace (PTRACE_CONT , pid,0 ,0 ) <0 ) +fatal_perror ("stop_ptraced_child : ptrace failed" ); -if (ptrace (PTRACE_CONT , pid,0 ,0 ) <0 ) { -perror ("stop_ptraced_child : ptrace failed" ); -return -1 ; - }CATCH_EINTR (n =waitpid (pid, &status,0 ));if (!WIFEXITED (status) || (WEXITSTATUS (status) != exitcode)) {int exit_with =WEXITSTATUS (status); -if (exit_with ==2 ) -non_fatal ("check_ptrace : child exited with status 2. " -"\nDisabling SYSEMU support.\n" ); -non_fatal ("check_ptrace : child exited with exitcode %d, while " -"expecting %d; status 0x%x\n" , exit_with, - exitcode, status); -if (mustexit) -exit (1 ); - ret =-1 ; +fatal ("stop_ptraced_child : child exited with exitcode %d, " +"while expecting %d; status 0x%x\n" , exit_with, + exitcode, status); } - -return ret; }static void __init check_sysemu (void )
@@ -185,16 +170,14 @@ static void __init check_sysemu(void) goto fail; } } -if (stop_ptraced_child (pid,0 ,0 ) <0 ) - goto fail_stopped; +stop_ptraced_child (pid,0 );os_info ("OK\n" );return ; fail: -stop_ptraced_child (pid,1 ,0 ); -fail_stopped: +stop_ptraced_child (pid,1 );fatal ("missing\n" ); }
@@ -233,7 +216,7 @@ static void __init check_ptrace(void)break ; } } -stop_ptraced_child (pid,0 ,1 ); +stop_ptraced_child (pid,0 );os_info ("OK\n" );check_sysemu (); }
@@ -312,7 +295,7 @@ void __init os_early_checks(void) pid =start_ptraced_child ();if (init_pid_registers (pid))fatal ("Failed to initialize default registers" ); -stop_ptraced_child (pid,1 ,1 ); +stop_ptraced_child (pid,1 ); }int __init parse_iomem (char *str,int *add)
Signature · 7 lines
2.41.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
PATCH v3 4/11 um: Don't use vfprintf() for os_info()
In reply to [email protected]From: Benjamin Berg <[email protected]>
The threads allocated inside the kernel have only a single page of stack. Unfortunately, the vfprintf function in standard glibc may use too much stack-space, overflowing it.
To make os_info safe to be used by helper threads, use the kernel vscnprintf function into a smallish buffer and write out the information to stderr.
--- arch/um/os-Linux/util.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
arch/um/os-Linux/util.c +17 -2
@@ -173,23 +173,38 @@ __uml_setup("quiet", quiet_cmd_param,"quiet\n" " Turns off information messages during boot.\n\n"); +/* +* The os_info/os_warn functions will be called by helper threads. These +* have a very limited stack size and using the libc formatting functions +* may overflow the stack. +* So pull in the kernel vscnprintf and use that instead with a fixed +* on-stack buffer. +*/ +int vscnprintf (char *buf,size_t size,const char *fmt,va_list args); +void os_info (const char *fmt, ...) { +char buf[256 ];va_list list; +int len;if (quiet_info)return ;va_start (list, fmt); -vfprintf (stderr, fmt, list); + len =vscnprintf (buf,sizeof (buf), fmt, list); +fwrite (buf, len,1 , stderr);va_end (list); }void os_warn (const char *fmt, ...) { +char buf[256 ];va_list list; +int len;va_start (list, fmt); -vfprintf (stderr, fmt, list); + len =vscnprintf (buf,sizeof (buf), fmt, list); +fwrite (buf, len,1 , stderr);va_end (list); }
Signature · 7 lines
2.41.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v3 04/11] um: Don't use vfprintf() for os_info()
Quoted 6 lines · On Fri, Nov 10, 2023 at 12:03 PM <[email protected]> wrote:
From: Benjamin Berg <[email protected]>
The threads allocated inside the kernel have only a single page of stack. Unfortunately, the vfprintf function in standard glibc may use too much stack-space, overflowing it.
Another option is giving the helper threads more memory, we don't have that many.
Did you explore this option already?
Signature · 2 lines
Thanks, //richard
Re: [PATCH v3 04/11] um: Don't use vfprintf() for os_info()
Hi,
Quoted 11 lines · Richard Weinberger
Quoted 6 lines · On Fri, Nov 10, 2023 at 12:03 PM <[email protected]> wrote:
From: Benjamin Berg <[email protected]>
The threads allocated inside the kernel have only a single page of stack. Unfortunately, the vfprintf function in standard glibc may use too much stack-space, overflowing it.
Another option is giving the helper threads more memory, we don't have that many.
Did you explore this option already?
I had not really considered that.
One thing though is that userspace_tramp calls os_info while working with the stub stack. So that also means setting STUB_DATA_PAGES to 2. But, I suspect we may want to do that anyway eventually to fit the ever increasing mcontext size for all the AVX512 registers and such.
As I said, I think that is fine to do.
Benjamin
Johannes Berg
maintainerRe: [PATCH v3 04/11] um: Don't use vfprintf() for os_info()
Quoted 10 lines · Benjamin Berg
Quoted 3 lines
Another option is giving the helper threads more memory, we don't have that many.
Did you explore this option already?I had not really considered that.
One thing though is that
userspace_trampcallsos_infowhile working with the stub stack. So that also means settingSTUB_DATA_PAGESto 2. But, I suspect we may want to do that anyway eventually to fit the ever increasing mcontext size for all the AVX512 registers and such.
That'll probably happen eventually regardless ...
Quoted 1 line
As I said, I think that is fine to do.
But I'm not sure it's a good solution to give more stack space to the threads and think/hope that glibc won't make more assumptions about the amount of space it can use ... who knows if it uses alloca() inside somewhere, for example? After all, userspace stacks are multiple megabytes by default?
johannes
Richard Weinberger
maintainerRe: [PATCH v3 04/11] um: Don't use vfprintf() for os_info()
----- Ursprüngliche Mail -----
Quoted 20 lines
Von: "Johannes Berg" <[email protected]>
An: "Benjamin Berg" <[email protected]>, "Richard Weinberger" <[email protected]>
CC: "linux-um" <[email protected]>
Gesendet: Freitag, 5. Januar 2024 09:56:11
Betreff: Re: [PATCH v3 04/11] um: Don't usevfprintf()foros_info()Quoted 10 lines · Benjamin Berg
Quoted 3 lines
Another option is giving the helper threads more memory, we don't have that many.
Did you explore this option already?I had not really considered that.
One thing though is that
userspace_trampcallsos_infowhile working with the stub stack. So that also means settingSTUB_DATA_PAGESto 2. But, I suspect we may want to do that anyway eventually to fit the ever increasing mcontext size for all the AVX512 registers and such.That'll probably happen eventually regardless ...
Quoted 7 lines
Quoted 1 line
As I said, I think that is fine to do.
But I'm not sure it's a good solution to give more stack space to the threads and think/hope that glibc won't make more assumptions about the amount of space it can use ... who knows if it uses
alloca()inside somewhere, for example? After all, userspace stacks are multiple megabytes by default?
For thread stacks things are a bit different.
glibc is in general more heap than stack greedy, it uses malloc() almost everywhere. For pthreads the minimal stack size on x86 is 16k (_SC_THREAD_STACK_MIN). Donating four pages to each helper thread seems okay to me.
And if I understand _SC_THREAD_STACK_MIN correctly, this is the minimal stack size the glibc library can deal with.
Thanks,
//richard
PATCH v3 5/11 um: Do not use printk in SIGWINCH helper thread
In reply to [email protected]From: Benjamin Berg <[email protected]>
The thread is running outside of the UML kernel scope and is a helper. As such, printk cannot work and os_info must be used instead.
--- arch/um/drivers/chan_user.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
arch/um/drivers/chan_user.c +13 -13
@@ -153,8 +153,8 @@ static int winch_thread(void *arg) pipe_fd = data->pipe_fd; count =write (pipe_fd, &c,sizeof (c));if (count !=sizeof (c)) -printk (UM_KERN_ERR "winch_thread : failed to write " -"synchronization byte, err = %d\n" , -count); +os_info ("winch_thread : failed to write synchronization byte, err = %d\n" , + -count);/* * We are not using SIG_IGN on purpose, so don't fix it as I thought to
@@ -166,28 +166,28 @@ static int winch_thread(void *arg)sigfillset (&sigs);/* Block all signals possible. */ if (sigprocmask (SIG_SETMASK , &sigs,NULL ) <0 ) { -printk (UM_KERN_ERR "winch_thread : sigprocmask failed, " -"errno = %d\n" , errno); +os_info ("winch_thread : sigprocmask failed, errno = %d\n" , + errno);exit (1 ); }/* In sigsuspend(), block anything else than SIGWINCH. */ sigdelset (&sigs,SIGWINCH );if (setsid () <0 ) { -printk (UM_KERN_ERR "winch_thread : setsid failed, errno = %d\n" , +os_info ("winch_thread : setsid failed, errno = %d\n" , errno);exit (1 ); }if (ioctl (pty_fd,TIOCSCTTY ,0 ) <0 ) { -printk (UM_KERN_ERR "winch_thread : TIOCSCTTY failed on " -"fd %d err = %d\n" , pty_fd, errno); +os_info ("winch_thread : TIOCSCTTY failed on " +"fd %d err = %d\n" , pty_fd, errno);exit (1 ); }if (tcsetpgrp (pty_fd,os_getpid ()) <0 ) { -printk (UM_KERN_ERR "winch_thread : tcsetpgrp failed on " -"fd %d err = %d\n" , pty_fd, errno); +os_info ("winch_thread : tcsetpgrp failed on fd %d err = %d\n" , + pty_fd, errno);exit (1 ); }
@@ -199,8 +199,8 @@ static int winch_thread(void *arg)*/ count =read (pipe_fd, &c,sizeof (c));if (count !=sizeof (c)) -printk (UM_KERN_ERR "winch_thread : failed to read " -"synchronization byte, err = %d\n" , errno); +os_info ("winch_thread : failed to read synchronization byte, err = %d\n" , + errno);while (1 ) {/*
@@ -211,8 +211,8 @@ static int winch_thread(void *arg) count =write (pipe_fd, &c,sizeof (c));if (count !=sizeof (c)) -printk (UM_KERN_ERR "winch_thread : write failed, " -"err = %d\n" , errno); +os_info ("winch_thread : write failed, err = %d\n" , + errno); } }
Signature · 7 lines
2.41.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
PATCH v3 6/11 um: Reap winch thread if it fails
In reply to [email protected]From: Benjamin Berg <[email protected]>
When the winch thread runs into an error condition, it would exit(1) and never be reaped until shutdown time. Change this to write a command byte which causes the driver to kill it, therefore reaping the child.
--- arch/um/drivers/chan_user.c | 16 +++++++++++----- arch/um/drivers/line.c | 13 ++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-)
arch/um/drivers/chan_user.c +11 -5
@@ -141,7 +141,7 @@ struct winch_data {int pipe_fd; }; -static int winch_thread (void *arg) +static __noreturn int winch_thread (void *arg) {struct winch_data *data = arg;sigset_t sigs;
@@ -168,7 +168,7 @@ static int winch_thread(void *arg)if (sigprocmask (SIG_SETMASK , &sigs,NULL ) <0 ) {os_info ("winch_thread : sigprocmask failed, errno = %d\n" , errno); -exit (1 ); + goto wait_kill; }/* In sigsuspend(), block anything else than SIGWINCH. */ sigdelset (&sigs,SIGWINCH );
@@ -176,19 +176,19 @@ static int winch_thread(void *arg)if (setsid () <0 ) {os_info ("winch_thread : setsid failed, errno = %d\n" , errno); -exit (1 ); + goto wait_kill; }if (ioctl (pty_fd,TIOCSCTTY ,0 ) <0 ) {os_info ("winch_thread : TIOCSCTTY failed on " "fd %d err = %d\n" , pty_fd, errno); -exit (1 ); + goto wait_kill; }if (tcsetpgrp (pty_fd,os_getpid ()) <0 ) {os_info ("winch_thread : tcsetpgrp failed on fd %d err = %d\n" , pty_fd, errno); -exit (1 ); + goto wait_kill; }/*
@@ -214,6 +214,12 @@ static int winch_thread(void *arg)os_info ("winch_thread : write failed, err = %d\n" , errno); } + +wait_kill: + c =2 ; + count =write (pipe_fd, &c,sizeof (c)); +while (1 ) +pause (); } static int winch_tramp(int fd, struct tty_port *port, int *fd_out,
arch/um/drivers/line.c +8 -5
@@ -629,15 +629,18 @@ static irqreturn_t winch_interrupt(int irq, void *data)if (fd !=-1 ) { err =generic_read (fd, &c,NULL ); -if (err <0 ) { +/* A read of 2 means the winch thread failed and has warned */ +if (err <0 || (err ==1 && c ==2 )) {if (err != -EAGAIN ) { winch->fd =-1 ;list_del (&winch->list);os_close_file (fd); -printk (KERN_ERR "winch_interrupt : " -"read failed, errno = %d\n" , -err); -printk (KERN_ERR "fd %d is losing SIGWINCH " -"support\n" , winch->tty_fd); +if (err <0 ) { +printk (KERN_ERR "winch_interrupt : read failed, errno = %d\n" , + -err); +printk (KERN_ERR "fd %d is losing SIGWINCH support\n" , + winch->tty_fd); + }INIT_WORK (&winch->work, __free_winch);schedule_work (&winch->work);return IRQ_HANDLED ;
Signature · 7 lines
2.41.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
PATCH v3 7/11 um: Do not use printk in userspace trampoline
In reply to [email protected]From: Benjamin Berg <[email protected]>
The trampoline is running in a cloned process. It is not safe to use printk for error printing there.
--- arch/um/os-Linux/skas/process.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/um/os-Linux/skas/process.c +6 -6
@@ -221,8 +221,8 @@ static int userspace_tramp(void *stack) addr =mmap64 ((void *)STUB_CODE ,UM_KERN_PAGE_SIZE ,PROT_EXEC ,MAP_FIXED |MAP_PRIVATE , fd, offset);if (addr ==MAP_FAILED ) { -printk (UM_KERN_ERR "mapping mmap stub at 0x%lx failed, errno = %d\n" , -STUB_CODE , errno); +os_info ("mapping mmap stub at 0x%lx failed, errno = %d\n" , +STUB_CODE , errno);exit (1 ); }
@@ -231,8 +231,8 @@ static int userspace_tramp(void *stack)STUB_DATA_PAGES *UM_KERN_PAGE_SIZE ,PROT_READ |PROT_WRITE , MAP_FIXED | MAP_SHARED, fd, offset);if (addr ==MAP_FAILED ) { -printk (UM_KERN_ERR "mapping segfault stack at 0x%lx failed, errno = %d\n" , -STUB_DATA , errno); +os_info ("mapping segfault stack at 0x%lx failed, errno = %d\n" , +STUB_DATA , errno);exit (1 ); }
@@ -242,8 +242,8 @@ static int userspace_tramp(void *stack) sa.sa_sigaction = (void *) segv_handler; sa.sa_restorer =NULL ;if (sigaction (SIGSEGV , &sa,NULL ) <0 ) { -printk (UM_KERN_ERR "%s - setting SIGSEGV handler failed - errno = %d\n" , - __func__, errno); +os_info ("%s - setting SIGSEGV handler failed - errno = %d\n" , + __func__, errno);exit (1 ); }
Signature · 7 lines
2.41.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
PATCH v3 8/11 um: Always inline stub functions
In reply to [email protected]From: Benjamin Berg <[email protected]>
The stub executable page is remapped to a different location in the userland process. As these functions may be used by the stub, they really need to be always inlined rather than permitting the compiler to emit a function.
--- arch/x86/um/shared/sysdep/stub_32.h | 21 +++++++++++---------- arch/x86/um/shared/sysdep/stub_64.h | 17 +++++++++-------- 2 files changed, 20 insertions(+), 18 deletions(-)
arch/x86/um/shared/sysdep/stub_32.h +11 -10
@@ -12,7 +12,7 @@#define STUB_MMAP_NR __NR_mmap2#define MMAP_OFFSET (o) ((o) >> UM_KERN_PAGE_SHIFT) -static inline long stub_syscall0 (long syscall) +static __always_inline long stub_syscall0 (long syscall) {long ret;
@@ -21,7 +21,7 @@ static inline long stub_syscall0(long syscall)return ret; } -static inline long stub_syscall1 (long syscall,long arg1) +static __always_inline long stub_syscall1 (long syscall,long arg1) {long ret;
@@ -30,7 +30,7 @@ static inline long stub_syscall1(long syscall, long arg1)return ret; } -static inline long stub_syscall2 (long syscall,long arg1,long arg2) +static __always_inline long stub_syscall2 (long syscall,long arg1,long arg2) {long ret;
@@ -40,7 +40,8 @@ static inline long stub_syscall2(long syscall, long arg1, long arg2)return ret; } -static inline long stub_syscall3 (long syscall,long arg1,long arg2,long arg3) +static __always_inline long stub_syscall3 (long syscall,long arg1,long arg2, +long arg3) {long ret;
@@ -50,8 +51,8 @@ static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)return ret; } -static inline long stub_syscall4 (long syscall,long arg1,long arg2,long arg3, -long arg4) +static __always_inline long stub_syscall4 (long syscall,long arg1,long arg2, +long arg3,long arg4) {long ret;
@@ -61,8 +62,8 @@ static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,return ret; } -static inline long stub_syscall5 (long syscall,long arg1,long arg2,long arg3, -long arg4,long arg5) +static __always_inline long stub_syscall5 (long syscall,long arg1,long arg2, +long arg3,long arg4,long arg5) {long ret;
@@ -72,12 +73,12 @@ static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,return ret; } -static inline void trap_myself (void ) +static __always_inline void trap_myself(void) { __asm("int3" ); } -static inline void remap_stack_and_trap (void ) +static __always_inline void remap_stack_and_trap(void) { __asm__volatile ( "movl %%esp,%%ebx ;"
arch/x86/um/shared/sysdep/stub_64.h +9 -8
@@ -16,7 +16,7 @@#define __syscall_clobber "r11","rcx","memory"#define __syscall "syscall" -static inline long stub_syscall0 (long syscall) +static __always_inline long stub_syscall0 (long syscall) {long ret;
@@ -27,7 +27,7 @@ static inline long stub_syscall0(long syscall)return ret; } -static inline long stub_syscall2 (long syscall,long arg1,long arg2) +static __always_inline long stub_syscall2 (long syscall,long arg1,long arg2) {long ret;
@@ -38,7 +38,8 @@ static inline long stub_syscall2(long syscall, long arg1, long arg2)return ret; } -static inline long stub_syscall3 (long syscall,long arg1,long arg2,long arg3) +static __always_inline long stub_syscall3 (long syscall,long arg1,long arg2, +long arg3) {long ret;
@@ -50,7 +51,7 @@ static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)return ret; } -static inline long stub_syscall4 (long syscall,long arg1,long arg2,long arg3, +static __always_inline long stub_syscall4 (long syscall,long arg1,long arg2,long arg3,long arg4) {long ret;
@@ -64,8 +65,8 @@ static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,return ret; } -static inline long stub_syscall5 (long syscall,long arg1,long arg2,long arg3, -long arg4,long arg5) +static __always_inline long stub_syscall5 (long syscall,long arg1,long arg2, +long arg3,long arg4,long arg5) {long ret;
@@ -78,12 +79,12 @@ static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,return ret; } -static inline void trap_myself (void ) +static __always_inline void trap_myself(void) { __asm("int3" ); } -static inline void remap_stack_and_trap (void ) +static __always_inline void remap_stack_and_trap(void) { __asm__volatile ( "movq %0,%%rax ;"
Signature · 7 lines
2.41.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
PATCH v3 9/11 um: Rely on PTRACE_SETREGSET to set FS/GS base registers
In reply to [email protected]From: Benjamin Berg <[email protected]>
These registers are saved/restored together with the other general registers using ptrace. In arch_set_tls we then just need to set the register and it will be synced back normally.
Most of this logic was introduced in commit f355559cf7845 ("[PATCH] uml:x86_64 thread fixes"). However, at least today we can rely on ptrace to restore the base registers for us. As such, only the part of the patch that tracks the FS register for use as thread local storage is actually needed.
--- arch/um/include/shared/os.h | 3 -- arch/x86/um/asm/elf.h | 4 +-- arch/x86/um/asm/processor_64.h | 3 -- arch/x86/um/os-Linux/Makefile | 1 - arch/x86/um/os-Linux/prctl.c | 12 ------- arch/x86/um/syscalls_64.c | 62 +++++++--------------------------- arch/x86/um/tls_64.c | 2 +- 7 files changed, 16 insertions(+), 71 deletions(-) delete mode 100644 arch/x86/um/os-Linux/prctl.c
arch/um/include/shared/os.h +0 -3
@@ -323,9 +323,6 @@ extern void sigio_broken(int fd);extern int __add_sigio_fd (int fd);extern int __ignore_sigio_fd (int fd); -/* prctl.c */ -extern int os_arch_prctl (int pid,int option,unsigned long *arg2); -/* tty.c */ extern int get_pty (void );
arch/x86/um/asm/elf.h +2 -2
@@ -168,8 +168,8 @@ do { \ (pr_reg)[18 ] = (_regs)->regs.gp[18 ]; \ (pr_reg)[19 ] = (_regs)->regs.gp[19 ]; \ (pr_reg)[20 ] = (_regs)->regs.gp[20 ]; \ - (pr_reg)[21 ] = current->thread.arch.fs; \ - (pr_reg)[22 ] =0 ; \ + (pr_reg)[21 ] = (_regs)->regs.gp[21 ]; \ + (pr_reg)[22 ] = (_regs)->regs.gp[22 ]; \ (pr_reg)[23 ] =0 ; \ (pr_reg)[24 ] =0 ; \ (pr_reg)[25 ] =0 ; \
arch/x86/um/asm/processor_64.h +0 -3
@@ -10,13 +10,11 @@struct arch_thread {unsigned long debugregs[8 ];int debugregs_seq; -unsigned long fs;struct faultinfo faultinfo; };#define INIT_ARCH_THREAD { .debugregs = { [ 0 ... 7 ] = 0 }, \ .debugregs_seq = 0, \ - .fs = 0, \ .faultinfo = { 0, 0, 0 } }#define STACKSLOTS_PER_LINE 4
@@ -28,7 +26,6 @@ static inline void arch_flush_thread(struct arch_thread *thread)static inline void arch_copy_thread (struct arch_thread *from,struct arch_thread *to) { - to->fs = from->fs; }#define current_sp () ({ void *sp; __asm__("movq %%rsp, %0" : "=r" (sp) : ); sp; })
arch/x86/um/os-Linux/Makefile +0 -1
@@ -6,7 +6,6 @@ obj-y = registers.o task_size.o mcontext.o obj-$(CONFIG_X86_32) += tls.o -obj-$(CONFIG_64BIT) += prctl.o USER_OBJS := $(obj-y)
arch/x86/um/os-Linux/prctl.c deleted +0 -12
@@ -1,12 +0,0 @@ -/* -* Copyright (C) 2007 Jeff Dike (jdike@{addtoit.com,linux.intel.com}) -* Licensed under the GPL -*/ - -#include <sys/ptrace.h> -#include <asm/ptrace.h> - -int os_arch_prctl (int pid,int option,unsigned long *arg2) -{ -return ptrace (PTRACE_ARCH_PRCTL , pid, (unsigned long ) arg2, option); -}
arch/x86/um/syscalls_64.c +13 -49
83 lines not on this page · raw message
arch/x86/um/tls_64.c +1 -1
@@ -12,7 +12,7 @@ int arch_set_tls(struct task_struct *t, unsigned long tls)* If CLONE_SETTLS is set, we need to save the thread id * so it can be set during context switches. */ - t->thread.arch.fs = tls; + t->thread.regs.regs.gp[FS_BASE /sizeof (unsigned long )] = tls;return 0 ; }
Signature · 7 lines
2.41.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v3 09/11] um: Rely on PTRACE_SETREGSET to set FS/GS base registers
Quoted 9 lines · On Fri, Nov 10, 2023 at 12:03 PM <[email protected]> wrote:
From: Benjamin Berg <[email protected]>
These registers are saved/restored together with the other general registers using ptrace. In
arch_set_tlswe then just need to set the register and it will be synced back normally.Most of this logic was introduced in commit
f355559cf7845("[PATCH] uml:x86_64thread fixes"). However, at least today we can rely on ptrace to
Do you know since when exactly? I don't want to break UML in subtle ways on old kernels.
Signature · 2 lines
Thanks, //richard
Re: [PATCH v3 09/11] um: Rely on PTRACE_SETREGSET to set FS/GS base registers
Quoted 5 lines · Richard Weinberger
Quoted 2 lines
Most of this logic was introduced in commit
f355559cf7845("[PATCH] uml:x86_64thread fixes"). However, at least today we can rely on ptrace toDo you know since when exactly? I don't want to break UML in subtle ways on old kernels.
BTW: I have applied the series up to here. Thanks a lot for cleaning up all this. :-)
Signature · 2 lines
Thanks, //richard
Re: [PATCH v3 09/11] um: Rely on PTRACE_SETREGSET to set FS/GS base registers
In reply to Richard WeinbergerHi,
Quoted 9 lines · Richard Weinberger
Quoted 8 lines · On Fri, Nov 10, 2023 at 12:03 PM <[email protected]> wrote:
From: Benjamin Berg <[email protected]>
These registers are saved/restored together with the other general registers using ptrace. In
arch_set_tlswe then just need to set the
register and it will be synced back normally.
Quoted 7 lines
Quoted 4 lines
Most of this logic was introduced in commit
f355559cf7845("[PATCH] uml:x86_64thread fixes"). However, at least today we can rely on ptrace toDo you know since when exactly? I don't want to break UML in subtle ways on old kernels.
To be honest, I don't remember, and I doubt I really understood what I was doing.
Anyway, I now found this commit now, which is contained in v2.6.25:
commit df5d438e33d7fc914ba9b6e0d6b019a8966c5fcc
Author: Roland McGrath <[email protected]> Date: Wed Jan 30 13:30:45 2008 +0100
x86: ptrace fs/gs_base
The fs_base and gs_base fields are available in user_regs_struct. But reading these via ptrace (PTRACE_GETREGS or PTRACE_PEEKUSR) does not give a reliably useful value. The thread_struct fields are 0 when do_arch_prctl decided to use a GDT slot instead of MSR_FS_BASE, which it does for a value under 1<<32.
This changes ptrace access to fs_base and gs_base to work like PTRACE_ARCH_PRCTL does. That is, it reads the base address that user-mode memory access using the fs/gs instruction prefixes will use, regardless of how it's being implemented in the kernel. The MSR vs GDT is an implementation detail that is pretty much hidden from userland in the actual using, and there is no reason that ptrace should give the internal implementation picture rather than the user-mode semantic picture. In the case of setting the value, this can implicitly change the fsindex/gsindex value (also separately in user_regs_struct), which is what happens when the thread calls arch_prctl itself. In a PTRACE_SETREGS, the fs_base change will come after the fsindex change due to the order of the struct, and so a change the debugger made to fs_base will have the effect intended, another part of the user_regs_struct will now differ when read back from what the debugger wrote.
This makes PTRACE_ARCH_PRCTL obsolete. We could consider declaring it deprecated and removing it one day, though there is no hurry. For the foreseeable future, debuggers have to assume an old kernel that does not report reliable fs_base/gs_base values in user_regs_struct and stick to PTRACE_ARCH_PRCTL anyway.
I think the last paragraph is quite straight forward in saying that we do not need anything special anymore. Note that the original commit adding the code pre-dates this commit by about a year, i.e.:
commit f355559cf78455ed6be103b020e4b800230c64eb
Author: Jeff Dike <[email protected]> Date: Sat Feb 10 01:44:29 2007 -0800
[PATCH] uml: x86_64 thread fixes
x86_64 needs some TLS fixes. What was missing was remembering the child thread id during clone and stuffing it into the child during each context switch.
The %fs value is stored separately in the thread structure since the host controls what effect it has on the actual register file. The host also needs to store it in its own thread struct, so we need the value kept outside the register file.
arch_prctl_skas was fixed to call PTRACE_ARCH_PRCTL appropriately. There is some saving and restoring of registers in the ARCH_SET_* cases so that the correct set of registers are changed on the host and restored to the process when it runs again.
There was some shuffling around in the ptrace code at some point, eventually switching from doing an arch_prctl call to setting things more directly. But I don't think that matters to us.
Benjamin
Richard Weinberger
maintainerRe: [PATCH v3 09/11] um: Rely on PTRACE_SETREGSET to set FS/GS base registers
----- Ursprüngliche Mail -----
Quoted 16 lines
Von: "Benjamin Berg" <[email protected]>
Quoted 14 lines · Richard Weinberger
Quoted 12 lines · On Fri, Nov 10, 2023 at 12:03 PM <[email protected]> wrote:
From: Benjamin Berg <[email protected]>
These registers are saved/restored together with the other general registers using ptrace. In
arch_set_tlswe then just need to set the
register and it will be synced back normally.Most of this logic was introduced in commit
f355559cf7845("[PATCH] uml:x86_64thread fixes"). However, at least today we can rely on ptrace to
Quoted 7 lines
Quoted 2 lines
Do you know since when exactly? I don't want to break UML in subtle ways on old kernels.
To be honest, I don't remember, and I doubt I really understood what I was doing.
Anyway, I now found this commit now, which is contained in v2.6.25:
Okay, 2.6.26 is way older than anything supported. So I'll apply our patch. :-)
Thanks,
//richard
PATCH v3 10/11 um: Remove unused register save/restore functions
In reply to [email protected]From: Benjamin Berg <[email protected]>
These functions were only used when calling PTRACE_ARCH_PRCTL, but this code has been removed.
--- arch/um/include/shared/registers.h | 2 -- arch/um/os-Linux/registers.c | 20 -------------------- 2 files changed, 22 deletions(-)
arch/um/include/shared/registers.h +0 -2
@@ -14,8 +14,6 @@ extern int save_fp_registers(int pid, unsigned long *fp_regs);extern int restore_fp_registers (int pid,unsigned long *fp_regs);extern int save_fpx_registers (int pid,unsigned long *fp_regs);extern int restore_fpx_registers (int pid,unsigned long *fp_regs); -extern int save_registers (int pid,struct uml_pt_regs *regs); -extern int restore_pid_registers (int pid,struct uml_pt_regs *regs);extern int init_pid_registers (int pid);extern void get_safe_registers (unsigned long *regs,unsigned long *fp_regs);extern int get_fp_registers (int pid,unsigned long *regs);
arch/um/os-Linux/registers.c +0 -20
@@ -11,26 +11,6 @@#include <sysdep/ptrace_user.h> #include <registers.h> -int save_registers (int pid,struct uml_pt_regs *regs) -{ -int err; - - err =ptrace (PTRACE_GETREGS , pid,0 , regs->gp); -if (err <0 ) -return -errno; -return 0 ; -} - -int restore_pid_registers (int pid,struct uml_pt_regs *regs) -{ -int err; - - err =ptrace (PTRACE_SETREGS , pid,0 , regs->gp); -if (err <0 ) -return -errno; -return 0 ; -} -/* This is set once at boot time and not changed thereafter */ static unsigned long exec_regs[MAX_REG_NR ];
Signature · 7 lines
2.41.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
PATCH v3 11/11 um: Mark 32bit syscall helpers as clobbering memory
In reply to [email protected]From: Benjamin Berg <[email protected]>
The 64bit helper are marked to clobber the memory, but the 32bit ones are not. Add the appropriate clobber to the 32bit helper routines so that the compiler cannot do invalid optimizations.
--- arch/x86/um/shared/sysdep/stub_32.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
arch/x86/um/shared/sysdep/stub_32.h +12 -6
@@ -16,7 +16,8 @@ static __always_inline long stub_syscall0(long syscall) {long ret; - __asm__volatile ("int $0x80" :"=a" (ret) :"0" (syscall)); + __asm__volatile ("int $0x80" :"=a" (ret) :"0" (syscall) + :"memory" );return ret; }
@@ -25,7 +26,8 @@ static __always_inline long stub_syscall1(long syscall, long arg1) {long ret; - __asm__volatile ("int $0x80" :"=a" (ret) :"0" (syscall),"b" (arg1)); + __asm__volatile ("int $0x80" :"=a" (ret) :"0" (syscall),"b" (arg1) + :"memory" );return ret; }
@@ -35,7 +37,8 @@ static __always_inline long stub_syscall2(long syscall, long arg1, long arg2)long ret; __asm__volatile ("int $0x80" :"=a" (ret) :"0" (syscall),"b" (arg1), -"c" (arg2)); +"c" (arg2) + :"memory" );return ret; }
@@ -46,7 +49,8 @@ static __always_inline long stub_syscall3(long syscall, long arg1, long arg2,long ret; __asm__volatile ("int $0x80" :"=a" (ret) :"0" (syscall),"b" (arg1), -"c" (arg2),"d" (arg3)); +"c" (arg2),"d" (arg3) + :"memory" );return ret; }
@@ -57,7 +61,8 @@ static __always_inline long stub_syscall4(long syscall, long arg1, long arg2,long ret; __asm__volatile ("int $0x80" :"=a" (ret) :"0" (syscall),"b" (arg1), -"c" (arg2),"d" (arg3),"S" (arg4)); +"c" (arg2),"d" (arg3),"S" (arg4) + :"memory" );return ret; }
@@ -68,7 +73,8 @@ static __always_inline long stub_syscall5(long syscall, long arg1, long arg2,long ret; __asm__volatile ("int $0x80" :"=a" (ret) :"0" (syscall),"b" (arg1), -"c" (arg2),"d" (arg3),"S" (arg4),"D" (arg5)); +"c" (arg2),"d" (arg3),"S" (arg4),"D" (arg5) + :"memory" );return ret; }
Signature · 7 lines
2.41.0 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um