mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-04-03 12:05:13 +02:00
[ Upstream commit e38eba3b77 ]
Flush all uncommitted user windows before calling the generic syscall
handlers for clone, fork, and vfork.
Prior to entering the arch common handlers sparc_{clone|fork|vfork}, the
arch-specific syscall wrappers for these syscalls will attempt to flush
all windows (including user windows).
In the window overflow trap handlers on both SPARC{32|64},
if the window can't be stored (i.e due to MMU related faults) the routine
backups the user window and increments a thread counter (wsaved).
By adding a synchronization point after the flush attempt, when fault
handling is enabled, any uncommitted user windows will be flushed.
Link: https://sourceware.org/bugzilla/show_bug.cgi?id=31394
Closes: https://lore.kernel.org/sparclinux/fe5cc47167430007560501aabb28ba154985b661.camel@physik.fu-berlin.de/
Signed-off-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Ludwig Rydberg <ludwig.rydberg@gaisler.com>
Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Link: https://lore.kernel.org/r/20260119144753.27945-2-ludwig.rydberg@gaisler.com
Signed-off-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
121 lines
2.9 KiB
C
121 lines
2.9 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
* This file handles the architecture independent parts of process handling..
|
|
*/
|
|
|
|
#include <linux/compat.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/ptrace.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/sched/task.h>
|
|
#include <linux/sched/task_stack.h>
|
|
#include <linux/signal.h>
|
|
|
|
#include "kernel.h"
|
|
|
|
asmlinkage long sparc_fork(struct pt_regs *regs)
|
|
{
|
|
unsigned long orig_i1;
|
|
long ret;
|
|
struct kernel_clone_args args = {
|
|
.exit_signal = SIGCHLD,
|
|
};
|
|
|
|
synchronize_user_stack();
|
|
|
|
orig_i1 = regs->u_regs[UREG_I1];
|
|
/* Reuse the parent's stack for the child. */
|
|
args.stack = regs->u_regs[UREG_FP];
|
|
|
|
ret = kernel_clone(&args);
|
|
|
|
/* If we get an error and potentially restart the system
|
|
* call, we're screwed because copy_thread() clobbered
|
|
* the parent's %o1. So detect that case and restore it
|
|
* here.
|
|
*/
|
|
if ((unsigned long)ret >= -ERESTART_RESTARTBLOCK)
|
|
regs->u_regs[UREG_I1] = orig_i1;
|
|
|
|
return ret;
|
|
}
|
|
|
|
asmlinkage long sparc_vfork(struct pt_regs *regs)
|
|
{
|
|
unsigned long orig_i1;
|
|
long ret;
|
|
struct kernel_clone_args args = {
|
|
.flags = CLONE_VFORK | CLONE_VM,
|
|
.exit_signal = SIGCHLD,
|
|
};
|
|
|
|
synchronize_user_stack();
|
|
|
|
orig_i1 = regs->u_regs[UREG_I1];
|
|
/* Reuse the parent's stack for the child. */
|
|
args.stack = regs->u_regs[UREG_FP];
|
|
|
|
ret = kernel_clone(&args);
|
|
|
|
/* If we get an error and potentially restart the system
|
|
* call, we're screwed because copy_thread() clobbered
|
|
* the parent's %o1. So detect that case and restore it
|
|
* here.
|
|
*/
|
|
if ((unsigned long)ret >= -ERESTART_RESTARTBLOCK)
|
|
regs->u_regs[UREG_I1] = orig_i1;
|
|
|
|
return ret;
|
|
}
|
|
|
|
asmlinkage long sparc_clone(struct pt_regs *regs)
|
|
{
|
|
unsigned long orig_i1;
|
|
unsigned int flags;
|
|
long ret;
|
|
struct kernel_clone_args args = {0};
|
|
|
|
synchronize_user_stack();
|
|
|
|
orig_i1 = regs->u_regs[UREG_I1];
|
|
flags = lower_32_bits(regs->u_regs[UREG_I0]);
|
|
args.flags = (flags & ~CSIGNAL);
|
|
args.exit_signal = (flags & CSIGNAL);
|
|
args.tls = regs->u_regs[UREG_I3];
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
if (test_thread_flag(TIF_32BIT)) {
|
|
args.pidfd = compat_ptr(regs->u_regs[UREG_I2]);
|
|
args.child_tid = compat_ptr(regs->u_regs[UREG_I4]);
|
|
args.parent_tid = compat_ptr(regs->u_regs[UREG_I2]);
|
|
} else
|
|
#endif
|
|
{
|
|
args.pidfd = (int __user *)regs->u_regs[UREG_I2];
|
|
args.child_tid = (int __user *)regs->u_regs[UREG_I4];
|
|
args.parent_tid = (int __user *)regs->u_regs[UREG_I2];
|
|
}
|
|
|
|
/* Did userspace give setup a separate stack for the child or are we
|
|
* reusing the parent's?
|
|
*/
|
|
if (regs->u_regs[UREG_I1])
|
|
args.stack = regs->u_regs[UREG_I1];
|
|
else
|
|
args.stack = regs->u_regs[UREG_FP];
|
|
|
|
ret = kernel_clone(&args);
|
|
|
|
/* If we get an error and potentially restart the system
|
|
* call, we're screwed because copy_thread() clobbered
|
|
* the parent's %o1. So detect that case and restore it
|
|
* here.
|
|
*/
|
|
if ((unsigned long)ret >= -ERESTART_RESTARTBLOCK)
|
|
regs->u_regs[UREG_I1] = orig_i1;
|
|
|
|
return ret;
|
|
}
|