Skip to content

Commit

Permalink
sh: use set_current_blocked() and block_sigmask()
Browse files Browse the repository at this point in the history
As described in e6fa16a ("signal: sigprocmask() should do
retarget_shared_pending()") the modification of current->blocked is
incorrect as we need to check whether the signal we're about to block is
pending in the shared queue.

Also, use the new helper function introduced in commit 5e6292c
("signal: add block_sigmask() for adding sigmask to current->blocked")
which centralises the code for updating current->blocked after
successfully delivering a signal and reduces the amount of duplicate code
across architectures.  In the past some architectures got this code wrong,
so using this helper function should stop that from happening again.

Acked-by: Oleg Nesterov <oleg@redhat.com>
Cc: Paul Mundt <lethal@linux-sh.org>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
  • Loading branch information
Matt Fleming authored and pmundt committed Mar 29, 2012
1 parent 8368b0e commit 5e047fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 49 deletions.
32 changes: 10 additions & 22 deletions arch/sh/kernel/signal_32.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ sys_sigsuspend(old_sigset_t mask,
unsigned long r5, unsigned long r6, unsigned long r7, unsigned long r5, unsigned long r6, unsigned long r7,
struct pt_regs __regs) struct pt_regs __regs)
{ {
mask &= _BLOCKABLE; sigset_t blocked;
spin_lock_irq(&current->sighand->siglock);
current->saved_sigmask = current->blocked; current->saved_sigmask = current->blocked;
siginitset(&current->blocked, mask);
recalc_sigpending(); mask &= _BLOCKABLE;
spin_unlock_irq(&current->sighand->siglock); siginitset(&blocked, mask);
set_current_blocked(&blocked);


current->state = TASK_INTERRUPTIBLE; current->state = TASK_INTERRUPTIBLE;
schedule(); schedule();
Expand Down Expand Up @@ -240,11 +241,7 @@ asmlinkage int sys_sigreturn(unsigned long r4, unsigned long r5,
goto badframe; goto badframe;


sigdelsetmask(&set, ~_BLOCKABLE); sigdelsetmask(&set, ~_BLOCKABLE);

set_current_blocked(&set);
spin_lock_irq(&current->sighand->siglock);
current->blocked = set;
recalc_sigpending();
spin_unlock_irq(&current->sighand->siglock);


if (restore_sigcontext(regs, &frame->sc, &r0)) if (restore_sigcontext(regs, &frame->sc, &r0))
goto badframe; goto badframe;
Expand Down Expand Up @@ -274,10 +271,7 @@ asmlinkage int sys_rt_sigreturn(unsigned long r4, unsigned long r5,
goto badframe; goto badframe;


sigdelsetmask(&set, ~_BLOCKABLE); sigdelsetmask(&set, ~_BLOCKABLE);
spin_lock_irq(&current->sighand->siglock); set_current_blocked(&set);
current->blocked = set;
recalc_sigpending();
spin_unlock_irq(&current->sighand->siglock);


if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &r0)) if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &r0))
goto badframe; goto badframe;
Expand Down Expand Up @@ -548,14 +542,8 @@ handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
else else
ret = setup_frame(sig, ka, oldset, regs); ret = setup_frame(sig, ka, oldset, regs);


if (ret == 0) { if (ret == 0)
spin_lock_irq(&current->sighand->siglock); block_sigmask(ka, sig);
sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
if (!(ka->sa.sa_flags & SA_NODEFER))
sigaddset(&current->blocked,sig);
recalc_sigpending();
spin_unlock_irq(&current->sighand->siglock);
}


return ret; return ret;
} }
Expand Down
37 changes: 10 additions & 27 deletions arch/sh/kernel/signal_64.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -159,14 +159,13 @@ sys_sigsuspend(old_sigset_t mask,
unsigned long r6, unsigned long r7, unsigned long r6, unsigned long r7,
struct pt_regs * regs) struct pt_regs * regs)
{ {
sigset_t saveset; sigset_t saveset, blocked;


mask &= _BLOCKABLE;
spin_lock_irq(&current->sighand->siglock);
saveset = current->blocked; saveset = current->blocked;
siginitset(&current->blocked, mask);
recalc_sigpending(); mask &= _BLOCKABLE;
spin_unlock_irq(&current->sighand->siglock); siginitset(&blocked, mask);
set_current_blocked(&blocked);


REF_REG_RET = -EINTR; REF_REG_RET = -EINTR;
while (1) { while (1) {
Expand Down Expand Up @@ -198,11 +197,8 @@ sys_rt_sigsuspend(sigset_t *unewset, size_t sigsetsize,
if (copy_from_user(&newset, unewset, sizeof(newset))) if (copy_from_user(&newset, unewset, sizeof(newset)))
return -EFAULT; return -EFAULT;
sigdelsetmask(&newset, ~_BLOCKABLE); sigdelsetmask(&newset, ~_BLOCKABLE);
spin_lock_irq(&current->sighand->siglock);
saveset = current->blocked; saveset = current->blocked;
current->blocked = newset; set_current_blocked(&newset);
recalc_sigpending();
spin_unlock_irq(&current->sighand->siglock);


REF_REG_RET = -EINTR; REF_REG_RET = -EINTR;
while (1) { while (1) {
Expand Down Expand Up @@ -408,11 +404,7 @@ asmlinkage int sys_sigreturn(unsigned long r2, unsigned long r3,
goto badframe; goto badframe;


sigdelsetmask(&set, ~_BLOCKABLE); sigdelsetmask(&set, ~_BLOCKABLE);

set_current_blocked(&set);
spin_lock_irq(&current->sighand->siglock);
current->blocked = set;
recalc_sigpending();
spin_unlock_irq(&current->sighand->siglock);


if (restore_sigcontext(regs, &frame->sc, &ret)) if (restore_sigcontext(regs, &frame->sc, &ret))
goto badframe; goto badframe;
Expand Down Expand Up @@ -445,10 +437,7 @@ asmlinkage int sys_rt_sigreturn(unsigned long r2, unsigned long r3,
goto badframe; goto badframe;


sigdelsetmask(&set, ~_BLOCKABLE); sigdelsetmask(&set, ~_BLOCKABLE);
spin_lock_irq(&current->sighand->siglock); set_current_blocked(&set);
current->blocked = set;
recalc_sigpending();
spin_unlock_irq(&current->sighand->siglock);


if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ret)) if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ret))
goto badframe; goto badframe;
Expand Down Expand Up @@ -734,14 +723,8 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
else else
ret = setup_frame(sig, ka, oldset, regs); ret = setup_frame(sig, ka, oldset, regs);


if (ret == 0) { if (ret == 0)
spin_lock_irq(&current->sighand->siglock); block_sigmask(ka, sig);
sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
if (!(ka->sa.sa_flags & SA_NODEFER))
sigaddset(&current->blocked,sig);
recalc_sigpending();
spin_unlock_irq(&current->sighand->siglock);
}


return ret; return ret;
} }
Expand Down

0 comments on commit 5e047fa

Please sign in to comment.