ptrace: add ability to get/set signal-blocked mask
authorAndrey Vagin <avagin@openvz.org>
Wed, 3 Jul 2013 22:08:12 +0000 (15:08 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 3 Jul 2013 23:08:01 +0000 (16:08 -0700)
crtools uses a parasite code for dumping processes.  The parasite code is
injected into a process with help PTRACE_SEIZE.

Currently crtools blocks signals from a parasite code.  If a process has
pending signals, crtools wait while a process handles these signals.

This method is not suitable for stopped tasks.  A stopped task can have a
few pending signals, when we will try to execute a parasite code, we will
need to drop SIGSTOP, but all other signals must remain pending, because a
state of processes must not be changed during checkpointing.

This patch adds two ptrace commands to set/get signal-blocked mask.

I think gdb can use this commands too.

[akpm@linux-foundation.org: be consistent with brace layout]
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Cc: Roland McGrath <roland@redhat.com>
Cc: Michael Kerrisk <mtk.manpages@gmail.com>
Cc: Pavel Emelyanov <xemul@parallels.com>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/uapi/linux/ptrace.h
kernel/ptrace.c

index 52ebcc89f306a3106489597c504ae60c0469b9ca..cf1019e15f5bc57c0fbf6120a96deb2340465294 100644 (file)
@@ -61,6 +61,9 @@ struct ptrace_peeksiginfo_args {
        __s32 nr;       /* how may siginfos to take */
 };
 
+#define PTRACE_GETSIGMASK      0x420a
+#define PTRACE_SETSIGMASK      0x420b
+
 /* Read signals from a shared (process wide) queue */
 #define PTRACE_PEEKSIGINFO_SHARED      (1 << 0)
 
index 335a7ae697f5986269d94a445fd27142fc75c09f..ba5e6cea181afecb583d567c38c23008142567c9 100644 (file)
@@ -844,6 +844,47 @@ int ptrace_request(struct task_struct *child, long request,
                        ret = ptrace_setsiginfo(child, &siginfo);
                break;
 
+       case PTRACE_GETSIGMASK:
+               if (addr != sizeof(sigset_t)) {
+                       ret = -EINVAL;
+                       break;
+               }
+
+               if (copy_to_user(datavp, &child->blocked, sizeof(sigset_t)))
+                       ret = -EFAULT;
+               else
+                       ret = 0;
+
+               break;
+
+       case PTRACE_SETSIGMASK: {
+               sigset_t new_set;
+
+               if (addr != sizeof(sigset_t)) {
+                       ret = -EINVAL;
+                       break;
+               }
+
+               if (copy_from_user(&new_set, datavp, sizeof(sigset_t))) {
+                       ret = -EFAULT;
+                       break;
+               }
+
+               sigdelsetmask(&new_set, sigmask(SIGKILL)|sigmask(SIGSTOP));
+
+               /*
+                * Every thread does recalc_sigpending() after resume, so
+                * retarget_shared_pending() and recalc_sigpending() are not
+                * called here.
+                */
+               spin_lock_irq(&child->sighand->siglock);
+               child->blocked = new_set;
+               spin_unlock_irq(&child->sighand->siglock);
+
+               ret = 0;
+               break;
+       }
+
        case PTRACE_INTERRUPT:
                /*
                 * Stop tracee without any side-effect on signal or job
@@ -948,8 +989,7 @@ int ptrace_request(struct task_struct *child, long request,
 
 #ifdef CONFIG_HAVE_ARCH_TRACEHOOK
        case PTRACE_GETREGSET:
-       case PTRACE_SETREGSET:
-       {
+       case PTRACE_SETREGSET: {
                struct iovec kiov;
                struct iovec __user *uiov = datavp;