powerpc/ptrace: remove BUG_ON when full register set not available
Subsystems (2)
PATCH 1/1 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. To solve this problem a poison value (0xdeadbeef) will be placed in the buffer in place of the actual register values. This will affect gpr14 to gpr31.
----------
include/linux/regset.h +28 -0
@@ -240,6 +240,34 @@ static inline int user_regset_copyout(un }return 0 ; } +/* want the count to be the registers 14-31 inclusive */ +#define POISON_REG_CNT (PT_R31-PT_R14+1) +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[POISON_REG_CNT ] = { [0 ...POISON_REG_CNT -1 ] =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,
arch/powerpc/kernel/ptrace.c +42 -6
64 lines not on this page · raw message
Quoted 5 lines
include/linux/regset.h +0
-0@@ -240,6 +240,34 @@ static inline int user_regset_copyout(un }
include/linux/regset.h static inline int user_regset_copyout(un · line 250
Quoted 10 lines
include/linux/regset.h +8
-0return 0 ; } +/* want the count to be the registers 14-31 inclusive */ +#define POISON_REG_CNT (PT_R31-PT_R14+1) +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) +{
I wouldn't put that in a generic location... especially something like POISON_REG_CNT is very specific to powerpc and our ABI.
.../...
arch/powerpc/kernel/ptrace.c static int gpr_get(struct task_struct *t · line 237
Quoted 9 lines
include/linux/regset.h +0
-0static inline int user_regset_copyin(unsigned int *pos, unsigned int *count, const void **kbuf,arch/powerpc/kernel/ptrace.c +0
-1@@ -234,11 +234,29 @@ static int gpr_get(struct task_struct *tif (target->thread.regs ==NULL )return -EIO ; -CHECK_FULL_REGS (target->thread.regs);
Wouldn't it be a simpler/cleaner approach to use a single function call here that checks if the reg set is full and if not, put poison values in the thread.regs structure itself ?
The resulting code would be more palatable...
Cheers,
Ben.
Quoted 66 lines
arch/powerpc/kernel/ptrace.c +42
-5- ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - target->thread.regs, -0 , offsetof(struct pt_regs , msr)); +if (!FULL_REGS (target->thread.regs)) { +/* Don't have the full register set. Copy out register r0-r13 */ + ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, + target->thread.regs, +0 ,sizeof (long )*PT_R14 ); + +/* Dont want to change the actual register values so rather than read the */ +/* actual register copy a poison value into the buffer instead */ +if (!ret) + ret =user_regset_copyout_poison (&pos, &count, &kbuf, &ubuf, +sizeof (long )*PT_R14 , offsetof(struct pt_regs , nip)); + +/* Copy out the rest of the registers as usual */ +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 +663,29 @@ static int gpr32_get(struct task_structif (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) { +/* Don't have the full register set. Copy out register r0-r13 */ +for (; count >0 && pos <PT_R14 ; --count) + *k++ = regs[pos++]; + +/* Dont want to change the actual register values so rather than read the */ +/* actual register copy a poison value into the buffer instead */ +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++];_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 9 lines
include/linux/regset.h +3
-0@@ -240,6 +240,34 @@ static inline int user_regset_copyout(un }return 0 ; } +/* want the count to be the registers 14-31 inclusive */ +#define POISON_REG_CNT (PT_R31-PT_R14+1) +static inline int user_regset_copyout_poison(unsigned int *pos,
Quoted 8 lines
include/linux/regset.h static inline int user_regset_copyout(un · line 250
Quoted 5 lines
include/linux/regset.h +5
-0+unsigned int *count, + void **kbuf, void __user **ubuf, + const int start_pos, + const int end_pos) +{I wouldn't put that in a generic location... especially something like
POISON_REG_CNTis very specific to powerpc and our ABI.
Yeah I put it there thinking about readability but only use it in the one place. If we go forward with this current strategy I will remove the #define and just comment more.
Quoted 11 lines
.../...
Quoted 8 lines
include/linux/regset.h +0
-0static inline int user_regset_copyin(unsigned int *pos, unsigned int *count, const void **kbuf,arch/powerpc/kernel/ptrace.c +0
-0@@ -234,11 +234,29 @@ static int gpr_get(struct task_struct *tif (target->thread.regs ==NULL )return -EIO ;
Quoted 7 lines
arch/powerpc/kernel/ptrace.c static int gpr_get(struct task_struct *t · line 237
Quoted 1 line
arch/powerpc/kernel/ptrace.c +0
-1-CHECK_FULL_REGS (target->thread.regs);Wouldn't it be a simpler/cleaner approach to use a single function call here that checks if the reg set is full and if not, put poison values in the thread.regs structure itself ?
The resulting code would be more palatable...
That was actually the way I had done the first patch while debugging the problem but Paul Mackerras didn't like that I changed the thread struct.
It is not clear to me which is better. Reporting a poison value that isn't actually there or to change the data. Hopefully a consensus can be reached and then I can submit a new patch based on that.
Quoted 72 lines
Cheers,
Ben.Quoted 66 lines
arch/powerpc/kernel/ptrace.c +42
-5- ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - target->thread.regs, -0 , offsetof(struct pt_regs , msr)); +if (!FULL_REGS (target->thread.regs)) { +/* Don't have the full register set. Copy out register r0-r13 */ + ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, + target->thread.regs, +0 ,sizeof (long )*PT_R14 ); + +/* Dont want to change the actual register values so rather than read the */ +/* actual register copy a poison value into the buffer instead */ +if (!ret) + ret =user_regset_copyout_poison (&pos, &count, &kbuf, &ubuf, +sizeof (long )*PT_R14 , offsetof(struct pt_regs , nip)); + +/* Copy out the rest of the registers as usual */ +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 +663,29 @@ static int gpr32_get(struct task_structif (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) { +/* Don't have the full register set. Copy out register r0-r13 */ +for (; count >0 && pos <PT_R14 ; --count) + *k++ = regs[pos++]; + +/* Dont want to change the actual register values so rather than read the */ +/* actual register copy a poison value into the buffer instead */ +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++];_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev