forbid ptrace changes psr.ri to 3
PATCH 1/1 forbid ptrace changes psr.ri to 3
PSR.ri bits 3 are reserved, change to 3 will break kernel.
The patch ignore such change, if you thought access_urea should return an error in the case, please let me know.
arch/ia64/kernel/ptrace.c +7 -3
@@ -951,10 +951,14 @@ access_uarea (struct task_struct *child,return 0 ;case PT_CR_IPSR : -if (write_access) - pt->cr_ipsr = ((*data &IPSR_MASK ) +if (write_access) { +unsigned long tmp = *data; +/* psr.ri bits 11 are reserved, ingore the change */ +if ((tmp &IA64_PSR_RI ) =IA64_PSR_RI ) + tmp &= ~IA64_PSR_RI ; + pt->cr_ipsr = ((tmp &IPSR_MASK ) | (pt->cr_ipsr & ~IPSR_MASK )); -else + }else *data = (pt->cr_ipsr &IPSR_MASK );return 0 ;
IA64_PSR_RI is in IPSR_MASK, apparently by intent.
If you want to change the behavior, you should simply change that mask.
Thanks,
Roland
Quoted 2 lines
IA64_PSR_RIis inIPSR_MASK, apparently by intent.
If you want to change the behavior, you should simply change that mask.
psr.ri is more complex because it is two bits where not all of the possible bit settings are defined. We definitely want to allow ptrace to set psr.ri (how else can we single step through instructions in a bundle?) But we should only allow psr.ri to be set to 0, 1, or 2.
I don't see how changing IPSR_MASK can help solve this.
-Tony
Quoted 7 lines · Tony
Quoted 2 lines
IA64_PSR_RIis inIPSR_MASK, apparently by intent.
If you want to change the behavior, you should simply change that mask.psr.ri is more complex because it is two bits where not all of the possible bit settings are defined. We definitely want to allow ptrace to set psr.ri (how else can we single step through instructions in a bundle?) But we should only allow psr.ri to be set to 0, 1, or 2.
This confused me, too, because the changelog and comments say "PSR.ri bits 3 are reserved" and "psr.ri bits 11 are reserved".
Something like "PSR.ri value 3 is reserved" would have made the intent more clear.
Bjorn
Quoted 5 lines
This confused me, too, because the changelog and comments say "PSR.ri bits 3 are reserved" and "psr.ri bits 11 are reserved".
Something like "PSR.ri value 3 is reserved" would have made the intent more clear.
Is this better? I'd already re-worded it a bit when I was checking into my GIT tree yesterday ... but I can make more changes if this is still causing confusion.
commit f8655358b7a6f527a5b102cb7d36b4eb14414860
Author: Shaohua Li <[email protected]> Date: Thu Aug 16 10:47:05 2007 -0700
[IA64] forbid ptrace changes psr.ri to 3
The "ri" field in the processor status register only has defined values of 0, 1, 2. Do not let ptrace set this to 3. As with other reserved fields in registers we silently discard the value.
arch/ia64/kernel/ptrace.c +7 -3
@@ -951,10 +951,14 @@ access_uarea (struct task_struct *child, unsigned long addr,return 0 ;case PT_CR_IPSR : -if (write_access) - pt->cr_ipsr = ((*data &IPSR_MASK ) +if (write_access) { +unsigned long tmp = *data; +/* psr.ri bits 11 are reserved, ignore the change */ +if ((tmp &IA64_PSR_RI ) =IA64_PSR_RI ) + tmp &= ~IA64_PSR_RI ; + pt->cr_ipsr = ((tmp &IPSR_MASK ) | (pt->cr_ipsr & ~IPSR_MASK )); -else + }else *data = (pt->cr_ipsr &IPSR_MASK );return 0 ;
Quoted 9 lines · Tony
Quoted 5 lines
This confused me, too, because the changelog and comments say "PSR.ri bits 3 are reserved" and "psr.ri bits 11 are reserved".
Something like "PSR.ri value 3 is reserved" would have made the intent more clear.
Is this better? I'd already re-worded it a bit when I was checking into my GIT tree yesterday ... but I can make more changes if this is still causing confusion.
I like the changelog a lot, but you might touch up the comment in the code as well.
Quoted 37 lines
commit
f8655358b7a6f527a5b102cb7d36b4eb14414860Author: Shaohua Li <[email protected]> Date: Thu Aug 16 10:47:05 2007 -0700[IA64] forbid ptrace changes psr.ri to 3
The "ri" field in the processor status register only has defined values of 0, 1, 2. Do not let ptrace set this to 3. As with other reserved fields in registers we silently discard the value.
Signed-off-by Shaohua Li <[email protected]>Signed-off-by Tony Luck <[email protected]>arch/ia64/kernel/ptrace.c +7
-3@@ -951,10 +951,14 @@ access_uarea (struct task_struct *child, unsigned long addr,return 0 ;case PT_CR_IPSR : -if (write_access) - pt->cr_ipsr = ((*data &IPSR_MASK ) +if (write_access) { +unsigned long tmp = *data; +/* psr.ri bits 11 are reserved, ignore the change */ +if ((tmp &IA64_PSR_RI ) =IA64_PSR_RI ) + tmp &= ~IA64_PSR_RI ; + pt->cr_ipsr = ((tmp &IPSR_MASK ) | (pt->cr_ipsr & ~IPSR_MASK )); -else + }else *data = (pt->cr_ipsr &IPSR_MASK );return 0 ;