Skip to contentSkip to conversation

ptrace: add ability to get/set signal-blocked mask (v2)

PATCH In review Andrey Vagin 3 participants 3 messages Apr 23, 2013 – May 6, 2013 ptrace support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ptrace: add ability to get/set signal-blocked mask (v2)

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.

v2: Don't use __set_task_blocked with tsk != current. recalc_sigpending() is not called here, because it will be called after resume. retarget_shared_pending() are not called, because we suppose, that other threads are stopped too.

Cc Roland McGrath <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Michael Kerrisk <[email protected]>
Cc Pavel Emelyanov <[email protected]>
Cc Cyrill Gorcunov <[email protected]>
---
 include/uapi/linux/ptrace.h |  3 +++
 kernel/ptrace.c             | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)
include/uapi/linux/ptrace.h +3 -0
index 52ebcc8..cf1019e 100644
@@ -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)
 
kernel/ptrace.c +42 -0

48 lines not on this page · raw message

Signature · 1 line
1.8.1.4
maintainer
#1 lore raw

kernel/ptrace.c int ptrace_request(struct task_struct *child, long request, · line 851

Quoted 13 lines · Andrey Vagin
kernel/ptrace.c +8 -0
@@ -841,6 +841,48 @@ 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;

Yes, we can do this lockless. Only the task itself (or the debugger with this patch) can change ->blocked, and the tracee can't run.

Quoted 18 lines
kernel/ptrace.c +18 -0
+	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

kernel/ptrace.c int ptrace_request(struct task_struct *child, long request, · line 884

Quoted 10 lines
kernel/ptrace.c +10 -0
+		 * 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;
+	}

And this looks fine too.

Personally I am not sure we need to check addr == sizeof(), debugger should know what it does... But I won't argue.

Oleg.

#2 lore raw

Andrew, let me know if you are waiting something to accept this patch.

Thanks.

Quoted 49 lines · Oleg Nesterov

kernel/ptrace.c int ptrace_request(struct task_struct *child, long request, · line 851

Quoted 13 lines · Andrey Vagin
kernel/ptrace.c +8 -0
@@ -841,6 +841,48 @@ 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;

Yes, we can do this lockless. Only the task itself (or the debugger with this patch) can change ->blocked, and the tracee can't run.

Quoted 18 lines
kernel/ptrace.c +18 -0
+	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

kernel/ptrace.c int ptrace_request(struct task_struct *child, long request, · line 884

Quoted 10 lines
kernel/ptrace.c +10 -0
+		 * 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;
+	}

And this looks fine too.

Quoted 2 lines

Personally I am not sure we need to check addr == sizeof(), debugger should know what it does... But I won't argue.

We do the same thing in sys_rt_sigaction. I think it may be useful in a future, if we decide to change the size of sigset_t.

Quoted 3 lines

Oleg.