linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* powerpc/ptrace:  Fix bug in signal handling
@ 2011-02-22 20:30 Michael Wolf
  2011-02-24  0:02 ` Michael Neuling
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Wolf @ 2011-02-22 20:30 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: anton

In some cases during a threaded core dump not all 
the threads will have a full register set.  This
will cause problems when the sigkill is sent to
the thread
        
Signed-off-by: Mike Wolf <mjw@linux.vnet.ibm.com>
-------

--- ptrace-signal.orig/arch/powerpc/kernel/ptrace.c	2011-02-20 12:15:57.000000000 -0600
+++ ptrace-signal/arch/powerpc/kernel/ptrace.c	2011-02-21 12:39:17.000000000 -0600
@@ -234,11 +234,23 @@
 	if (target->thread.regs == NULL)
 		return -EIO;
 
-	CHECK_FULL_REGS(target->thread.regs);
 
-	ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
-				  target->thread.regs,
-				  0, offsetof(struct pt_regs, msr));
+	if (!FULL_REGS(target->thread.regs)) {
+		ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
+					  target->thread.regs,
+					  0, sizeof(long)*PT_R14);
+		if (!ret)
+			ret = user_regset_copyout_poison(&pos, &count, &kbuf, &ubuf,
+						  sizeof(long)*PT_R14, offsetof(struct pt_regs, nip));
+		if (!ret)
+			ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
+						  target->thread.regs,
+						  offsetof(struct pt_regs, nip), offsetof(struct pt_regs, msr));
+		
+	} else 
+		ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
+					  target->thread.regs,
+					  0, offsetof(struct pt_regs, msr));
 	if (!ret) {
 		unsigned long msr = get_user_msr(target);
 		ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr,
@@ -645,11 +657,24 @@
 	if (target->thread.regs == NULL)
 		return -EIO;
 
-	CHECK_FULL_REGS(target->thread.regs);
-
 	pos /= sizeof(reg);
 	count /= sizeof(reg);
 
+	if(!FULL_REGS(target->thread.regs)) {
+		if (kbuf) {
+			for (; count > 0 && pos < PT_R14; --count)
+				*k++ = regs[pos++];
+			for (; count > 0 && pos < PT_R31; --count,pos++)
+				*k++ = 0xdeadbeef;
+		} else { 
+			for (; count > 0 && pos < PT_R14; --count)
+				if (__put_user((compat_ulong_t) regs[pos++], u++))
+					return -EFAULT;
+			for (; count > 0 && pos < PT_R31; --count,pos++)
+				if (__put_user((compat_ulong_t) 0xdeadbeef, u++))
+					return -EFAULT;
+		}
+	}
 	if (kbuf)
 		for (; count > 0 && pos < PT_MSR; --count)
 			*k++ = regs[pos++];
--- ptrace-signal.orig/include/linux/regset.h	2011-02-20 12:15:57.000000000 -0600
+++ ptrace-signal/include/linux/regset.h	2011-02-21 12:39:17.000000000 -0600
@@ -240,6 +240,32 @@
 	}
 	return 0;
 }
+static inline int user_regset_copyout_poison(unsigned int *pos,
+					   unsigned int *count,
+					   void **kbuf, void __user **ubuf,
+					   const int start_pos,
+					   const int end_pos)
+{
+	long poison_data[17] = { [0 ... 16] = 0xdeadbeefdeadbeefUL };
+
+	if (*count == 0)
+		return 0;
+	BUG_ON(*pos < start_pos);
+	if (end_pos < 0 || *pos < end_pos) {
+		unsigned int copy = (end_pos < 0 ? *count
+				     : min(*count, end_pos - *pos));
+		if (*kbuf) {
+			memset(*kbuf, 0xdeadbeef, copy);
+			*kbuf += copy;
+		} else if (__copy_to_user(*ubuf,poison_data, copy))
+			return -EFAULT;
+		else
+			*ubuf += copy;
+		*pos += copy;
+		*count -= copy;
+	}
+	return 0;
+}
 
 static inline int user_regset_copyin(unsigned int *pos, unsigned int *count,
 				     const void **kbuf,

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: powerpc/ptrace: Fix bug in signal handling
  2011-02-22 20:30 powerpc/ptrace: Fix bug in signal handling Michael Wolf
@ 2011-02-24  0:02 ` Michael Neuling
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Neuling @ 2011-02-24  0:02 UTC (permalink / raw)
  To: mjw, Michael Wolf; +Cc: linuxppc-dev, anton

Mike,

> Subject: powerpc/ptrace: Fix bug in signal handling

Maybe something more descriptive here like:
  powerpc/ptrace: remove BUG_ON when full register set not available

> In some cases during a threaded core dump not all 
> the threads will have a full register set.  This
> will cause problems when the sigkill is sent to
> the thread

Please add a description for how you are solving this.  Something like
"Solve this by putting poison values in the registers".  Similar inline
comments would be good too.

Also, I'm not convinced this is the right solution... not that I have a
have a better one to suggest :-)

<snip>

> +static inline int user_regset_copyout_poison(unsigned int *pos,
> +					   unsigned int *count,
> +					   void **kbuf, void __user **ubuf,
> +					   const int start_pos,
> +					   const int end_pos)
> +{
> +	long poison_data[17] = { [0 ... 16] = 0xdeadbeefdeadbeefUL };

Why only poison 17 registers?

Mikey

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-02-24  0:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-22 20:30 powerpc/ptrace: Fix bug in signal handling Michael Wolf
2011-02-24  0:02 ` Michael Neuling

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).