Re: [PATCH v2 19/44] metag: Signal handling

From: Al Viro
Date: Wed Dec 05 2012 - 12:15:59 EST


> + if (__copy_from_user(&st, &frame->uc.uc_stack, sizeof(st)))
> + goto badframe;
> + /* It is more difficult to avoid calling this function than to
> + call it and ignore errors. */
> + do_sigaltstack((__force const stack_t __user *)&st, NULL, regs->REG_SP);

"Dear sparse, please shut the fuck up. This function might expect a userland
pointer for some reason, but I've just copied the damn thing on stack and
if I say that it's at userland address, at userland address it is".

1) __force-cast will make sparse to STFU, indeed
2) address of local variable is not a userland pointer. In particular,
copy_from_user() will barf on it, unless you play with set_fs(), which
you don't do.
3) do_sigaltstack() *does* copy_from_user(), so it'll simply fail and do
nothing; adding set_fs() games would have prevented that, but why the hell
bother creating a local copy in the first place? Just give &frame->uc.uc_stack
to do_sigaltstack() and check that it hasn't returned -EFAULT.
4) sh et.al. were broken in exactly the same way. Fixed in mainline now.
5) if you need a force-cast, it might be worth figuring out what's going on.

> +static void do_signal(struct pt_regs *regs, int from_syscall,
> + unsigned int orig_syscall)
> +{
> + struct k_sigaction ka;
> + siginfo_t info;
> + int signr;
> +
> + /*
> + * We want the common case to go fast, which
> + * is why we may in certain cases get here from
> + * kernel mode. Just return without doing anything
> + * if so.
> + */
> + if (!user_mode(regs))
> + return;

Can you really get here with !user_mode(regs)? If so, you are very likely
screwed and badly.

> + if (from_syscall) {
> + /* Restart the system call - no handlers present */
> + switch (syscall_get_error(current, regs)) {
> + case -ERESTARTNOHAND:
> + case -ERESTARTSYS:
> + case -ERESTARTNOINTR:
> + regs->REG_SYSCALL = orig_syscall;
> + regs->REG_PC -= 4;

... and what's to prevent getting here again? Unless you only handle one
signal and bugger off to userland immediately, which is also quite broken.
BTW, what's to stop the syscall restart triggering if you catch a signal
while in rt_sigreturn(2)?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/