Commit c6f9de73 authored by Will Deacon's avatar Will Deacon Committed by Khalid Elmously

signal: Introduce COMPAT_SIGMINSTKSZ for use in compat_sys_sigaltstack

BugLink: https://bugs.launchpad.net/bugs/1844155

The sigaltstack(2) system call fails with -ENOMEM if the new alternative
signal stack is found to be smaller than SIGMINSTKSZ. On architectures
such as arm64, where the native value for SIGMINSTKSZ is larger than
the compat value, this can result in an unexpected error being reported
to a compat task. See, for example:

  https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=904385

This patch fixes the problem by extending do_sigaltstack to take the
minimum signal stack size as an additional parameter, allowing the
native and compat system call entry code to pass in their respective
values. COMPAT_SIGMINSTKSZ is just defined as SIGMINSTKSZ if it has not
been defined by the architecture.

Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Oleg Nesterov <oleg@redhat.com>
Reported-by: default avatarSteve McIntyre <steve.mcintyre@arm.com>
Tested-by: default avatarSteve McIntyre <93sam@debian.org>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>

(backported from commit 22839869)
[juergh: Adjusted context.]
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Acked-by: default avatarStefan Bader <stefan.bader@canonical.com>
Acked-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
parent 3d0c7880
...@@ -65,6 +65,9 @@ typedef struct compat_sigaltstack { ...@@ -65,6 +65,9 @@ typedef struct compat_sigaltstack {
compat_size_t ss_size; compat_size_t ss_size;
} compat_stack_t; } compat_stack_t;
#endif #endif
#ifndef COMPAT_MINSIGSTKSZ
#define COMPAT_MINSIGSTKSZ MINSIGSTKSZ
#endif
#define compat_jiffies_to_clock_t(x) \ #define compat_jiffies_to_clock_t(x) \
(((unsigned long)(x) * COMPAT_USER_HZ) / HZ) (((unsigned long)(x) * COMPAT_USER_HZ) / HZ)
......
...@@ -3170,7 +3170,8 @@ int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact) ...@@ -3170,7 +3170,8 @@ int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact)
} }
static int static int
do_sigaltstack (const stack_t __user *uss, stack_t __user *uoss, unsigned long sp) do_sigaltstack (const stack_t __user *uss, stack_t __user *uoss, unsigned long sp,
size_t min_ss_size)
{ {
stack_t oss; stack_t oss;
int error; int error;
...@@ -3213,7 +3214,7 @@ do_sigaltstack (const stack_t __user *uss, stack_t __user *uoss, unsigned long s ...@@ -3213,7 +3214,7 @@ do_sigaltstack (const stack_t __user *uss, stack_t __user *uoss, unsigned long s
ss_sp = NULL; ss_sp = NULL;
} else { } else {
error = -ENOMEM; error = -ENOMEM;
if (ss_size < MINSIGSTKSZ) if (ss_size < min_ss_size)
goto out; goto out;
} }
...@@ -3236,12 +3237,14 @@ do_sigaltstack (const stack_t __user *uss, stack_t __user *uoss, unsigned long s ...@@ -3236,12 +3237,14 @@ do_sigaltstack (const stack_t __user *uss, stack_t __user *uoss, unsigned long s
} }
SYSCALL_DEFINE2(sigaltstack,const stack_t __user *,uss, stack_t __user *,uoss) SYSCALL_DEFINE2(sigaltstack,const stack_t __user *,uss, stack_t __user *,uoss)
{ {
return do_sigaltstack(uss, uoss, current_user_stack_pointer()); return do_sigaltstack(uss, uoss, current_user_stack_pointer(),
MINSIGSTKSZ);
} }
int restore_altstack(const stack_t __user *uss) int restore_altstack(const stack_t __user *uss)
{ {
int err = do_sigaltstack(uss, NULL, current_user_stack_pointer()); int err = do_sigaltstack(uss, NULL, current_user_stack_pointer(),
MINSIGSTKSZ);
/* squash all but EFAULT for now */ /* squash all but EFAULT for now */
return err == -EFAULT ? err : 0; return err == -EFAULT ? err : 0;
} }
...@@ -3277,7 +3280,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack, ...@@ -3277,7 +3280,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
set_fs(KERNEL_DS); set_fs(KERNEL_DS);
ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL), ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
(stack_t __force __user *) &uoss, (stack_t __force __user *) &uoss,
compat_user_stack_pointer()); compat_user_stack_pointer(),
COMPAT_MINSIGSTKSZ);
set_fs(seg); set_fs(seg);
if (ret >= 0 && uoss_ptr) { if (ret >= 0 && uoss_ptr) {
if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(compat_stack_t)) || if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(compat_stack_t)) ||
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment