diff mbox series

[10/12] powerpc/entry32: Blacklist exception entry points for kprobe.

Message ID aea027844b12fcbc29ea78d26c5848a6794d1688.1585474724.git.christophe.leroy@c-s.fr (mailing list archive)
State Superseded
Headers show
Series [01/12] powerpc/52xx: Blacklist functions running with MMU disabled for kprobe | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch powerpc/merge (c6624071c338732402e8c726df6a4074473eaa0e)
snowpatch_ozlabs/checkpatch success total: 0 errors, 0 warnings, 0 checks, 43 lines checked
snowpatch_ozlabs/needsstable success Patch has no Fixes tags

Commit Message

Christophe Leroy March 29, 2020, 9:41 a.m. UTC
kprobe does not handle events happening in real mode.

As exception entry points are running with MMU disabled,
blacklist them.

Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
 arch/powerpc/kernel/entry_32.S | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Naveen N. Rao March 30, 2020, 5:08 p.m. UTC | #1
Christophe Leroy wrote:
> kprobe does not handle events happening in real mode.
> 
> As exception entry points are running with MMU disabled,
> blacklist them.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> ---
>  arch/powerpc/kernel/entry_32.S | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
> index 94f78c03cb79..9a1a45d6038a 100644
> --- a/arch/powerpc/kernel/entry_32.S
> +++ b/arch/powerpc/kernel/entry_32.S
> @@ -51,6 +51,7 @@ mcheck_transfer_to_handler:
>  	mfspr	r0,SPRN_DSRR1
>  	stw	r0,_DSRR1(r11)
>  	/* fall through */
> +_ASM_NOKPROBE_SYMBOL(mcheck_transfer_to_handler)
> 
>  	.globl	debug_transfer_to_handler
>  debug_transfer_to_handler:
> @@ -59,6 +60,7 @@ debug_transfer_to_handler:
>  	mfspr	r0,SPRN_CSRR1
>  	stw	r0,_CSRR1(r11)
>  	/* fall through */
> +_ASM_NOKPROBE_SYMBOL(debug_transfer_to_handler)
> 
>  	.globl	crit_transfer_to_handler
>  crit_transfer_to_handler:
> @@ -94,6 +96,7 @@ crit_transfer_to_handler:
>  	rlwinm	r0,r1,0,0,(31 - THREAD_SHIFT)
>  	stw	r0,KSP_LIMIT(r8)
>  	/* fall through */
> +_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
>  #endif
> 
>  #ifdef CONFIG_40x
> @@ -115,6 +118,7 @@ crit_transfer_to_handler:
>  	rlwinm	r0,r1,0,0,(31 - THREAD_SHIFT)
>  	stw	r0,KSP_LIMIT(r8)
>  	/* fall through */
> +_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
>  #endif
> 
>  /*
> @@ -127,6 +131,7 @@ crit_transfer_to_handler:
>  	.globl	transfer_to_handler_full
>  transfer_to_handler_full:
>  	SAVE_NVGPRS(r11)
> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler_full)
>  	/* fall through */
> 
>  	.globl	transfer_to_handler
> @@ -286,6 +291,8 @@ reenable_mmu:
>  	lwz	r2, GPR2(r11)
>  	b	fast_exception_return
>  #endif
> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler)
> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler_cont)

These are added after 'reenable_mmu', which is itself not blacklisted.  
Is that intentional?


- Naveen
Christophe Leroy March 30, 2020, 6:33 p.m. UTC | #2
Le 30/03/2020 à 19:08, Naveen N. Rao a écrit :
> Christophe Leroy wrote:
>> kprobe does not handle events happening in real mode.
>>
>> As exception entry points are running with MMU disabled,
>> blacklist them.
>>
>> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
>> ---
>>  arch/powerpc/kernel/entry_32.S | 7 +++++++
>>  1 file changed, 7 insertions(+)
>>
>> diff --git a/arch/powerpc/kernel/entry_32.S 
>> b/arch/powerpc/kernel/entry_32.S
>> index 94f78c03cb79..9a1a45d6038a 100644
>> --- a/arch/powerpc/kernel/entry_32.S
>> +++ b/arch/powerpc/kernel/entry_32.S
>> @@ -51,6 +51,7 @@ mcheck_transfer_to_handler:
>>      mfspr    r0,SPRN_DSRR1
>>      stw    r0,_DSRR1(r11)
>>      /* fall through */
>> +_ASM_NOKPROBE_SYMBOL(mcheck_transfer_to_handler)
>>
>>      .globl    debug_transfer_to_handler
>>  debug_transfer_to_handler:
>> @@ -59,6 +60,7 @@ debug_transfer_to_handler:
>>      mfspr    r0,SPRN_CSRR1
>>      stw    r0,_CSRR1(r11)
>>      /* fall through */
>> +_ASM_NOKPROBE_SYMBOL(debug_transfer_to_handler)
>>
>>      .globl    crit_transfer_to_handler
>>  crit_transfer_to_handler:
>> @@ -94,6 +96,7 @@ crit_transfer_to_handler:
>>      rlwinm    r0,r1,0,0,(31 - THREAD_SHIFT)
>>      stw    r0,KSP_LIMIT(r8)
>>      /* fall through */
>> +_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
>>  #endif
>>
>>  #ifdef CONFIG_40x
>> @@ -115,6 +118,7 @@ crit_transfer_to_handler:
>>      rlwinm    r0,r1,0,0,(31 - THREAD_SHIFT)
>>      stw    r0,KSP_LIMIT(r8)
>>      /* fall through */
>> +_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
>>  #endif
>>
>>  /*
>> @@ -127,6 +131,7 @@ crit_transfer_to_handler:
>>      .globl    transfer_to_handler_full
>>  transfer_to_handler_full:
>>      SAVE_NVGPRS(r11)
>> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler_full)
>>      /* fall through */
>>
>>      .globl    transfer_to_handler
>> @@ -286,6 +291,8 @@ reenable_mmu:
>>      lwz    r2, GPR2(r11)
>>      b    fast_exception_return
>>  #endif
>> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler)
>> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler_cont)
> 
> These are added after 'reenable_mmu', which is itself not blacklisted. 
> Is that intentional?

Yes I put it as the complete end of the entry part, ie just before 
stack_ovf which is a function by itself.

Note that reenable_mmu is inside an #ifdef CONFIG_TRACE_IRQFLAGS.

I'm not completely sure where to put the _ASM_NOKPROBE_SYMBOL()s, that's 
the reason why I put it close to the symbol itself in my first series.

Could you have a look at the code and tell me what looks the most 
appropriate as a location to you ?

https://elixir.bootlin.com/linux/v5.6/source/arch/powerpc/kernel/entry_32.S#L230

Thanks
Christophe
Christophe Leroy March 31, 2020, 5:51 a.m. UTC | #3
Le 30/03/2020 à 20:33, Christophe Leroy a écrit :
> 
> 
> Le 30/03/2020 à 19:08, Naveen N. Rao a écrit :
>> Christophe Leroy wrote:
>>> kprobe does not handle events happening in real mode.
>>>
>>> As exception entry points are running with MMU disabled,
>>> blacklist them.
>>>
>>> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
>>> ---
>>>  arch/powerpc/kernel/entry_32.S | 7 +++++++
>>>  1 file changed, 7 insertions(+)
>>>
>>> diff --git a/arch/powerpc/kernel/entry_32.S 
>>> b/arch/powerpc/kernel/entry_32.S
>>> index 94f78c03cb79..9a1a45d6038a 100644
>>> --- a/arch/powerpc/kernel/entry_32.S
>>> +++ b/arch/powerpc/kernel/entry_32.S
>>> @@ -51,6 +51,7 @@ mcheck_transfer_to_handler:
>>>      mfspr    r0,SPRN_DSRR1
>>>      stw    r0,_DSRR1(r11)
>>>      /* fall through */
>>> +_ASM_NOKPROBE_SYMBOL(mcheck_transfer_to_handler)
>>>
>>>      .globl    debug_transfer_to_handler
>>>  debug_transfer_to_handler:
>>> @@ -59,6 +60,7 @@ debug_transfer_to_handler:
>>>      mfspr    r0,SPRN_CSRR1
>>>      stw    r0,_CSRR1(r11)
>>>      /* fall through */
>>> +_ASM_NOKPROBE_SYMBOL(debug_transfer_to_handler)
>>>
>>>      .globl    crit_transfer_to_handler
>>>  crit_transfer_to_handler:
>>> @@ -94,6 +96,7 @@ crit_transfer_to_handler:
>>>      rlwinm    r0,r1,0,0,(31 - THREAD_SHIFT)
>>>      stw    r0,KSP_LIMIT(r8)
>>>      /* fall through */
>>> +_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
>>>  #endif
>>>
>>>  #ifdef CONFIG_40x
>>> @@ -115,6 +118,7 @@ crit_transfer_to_handler:
>>>      rlwinm    r0,r1,0,0,(31 - THREAD_SHIFT)
>>>      stw    r0,KSP_LIMIT(r8)
>>>      /* fall through */
>>> +_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
>>>  #endif
>>>
>>>  /*
>>> @@ -127,6 +131,7 @@ crit_transfer_to_handler:
>>>      .globl    transfer_to_handler_full
>>>  transfer_to_handler_full:
>>>      SAVE_NVGPRS(r11)
>>> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler_full)
>>>      /* fall through */
>>>
>>>      .globl    transfer_to_handler
>>> @@ -286,6 +291,8 @@ reenable_mmu:
>>>      lwz    r2, GPR2(r11)
>>>      b    fast_exception_return
>>>  #endif
>>> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler)
>>> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler_cont)
>>
>> These are added after 'reenable_mmu', which is itself not blacklisted. 
>> Is that intentional?
> 
> Yes I put it as the complete end of the entry part, ie just before 
> stack_ovf which is a function by itself.
> 
> Note that reenable_mmu is inside an #ifdef CONFIG_TRACE_IRQFLAGS.
> 
> I'm not completely sure where to put the _ASM_NOKPROBE_SYMBOL()s, that's 
> the reason why I put it close to the symbol itself in my first series.
> 
> Could you have a look at the code and tell me what looks the most 
> appropriate as a location to you ?
> 
> https://elixir.bootlin.com/linux/v5.6/source/arch/powerpc/kernel/entry_32.S#L230 

Ok, thinking about it once more, I guess we have a problem as everything 
after that reenable_mmu will be visible.

So I'll respin

Christophe
Naveen N. Rao March 31, 2020, 6:13 a.m. UTC | #4
Christophe Leroy wrote:
> 
> 
> Le 30/03/2020 à 19:08, Naveen N. Rao a écrit :
>> Christophe Leroy wrote:
>>> kprobe does not handle events happening in real mode.
>>>
>>> As exception entry points are running with MMU disabled,
>>> blacklist them.
>>>
>>> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
>>> ---
>>>  arch/powerpc/kernel/entry_32.S | 7 +++++++
>>>  1 file changed, 7 insertions(+)
>>>
>>> diff --git a/arch/powerpc/kernel/entry_32.S 
>>> b/arch/powerpc/kernel/entry_32.S
>>> index 94f78c03cb79..9a1a45d6038a 100644
>>> --- a/arch/powerpc/kernel/entry_32.S
>>> +++ b/arch/powerpc/kernel/entry_32.S
>>> @@ -51,6 +51,7 @@ mcheck_transfer_to_handler:
>>>      mfspr    r0,SPRN_DSRR1
>>>      stw    r0,_DSRR1(r11)
>>>      /* fall through */
>>> +_ASM_NOKPROBE_SYMBOL(mcheck_transfer_to_handler)
>>>
>>>      .globl    debug_transfer_to_handler
>>>  debug_transfer_to_handler:
>>> @@ -59,6 +60,7 @@ debug_transfer_to_handler:
>>>      mfspr    r0,SPRN_CSRR1
>>>      stw    r0,_CSRR1(r11)
>>>      /* fall through */
>>> +_ASM_NOKPROBE_SYMBOL(debug_transfer_to_handler)
>>>
>>>      .globl    crit_transfer_to_handler
>>>  crit_transfer_to_handler:
>>> @@ -94,6 +96,7 @@ crit_transfer_to_handler:
>>>      rlwinm    r0,r1,0,0,(31 - THREAD_SHIFT)
>>>      stw    r0,KSP_LIMIT(r8)
>>>      /* fall through */
>>> +_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
>>>  #endif
>>>
>>>  #ifdef CONFIG_40x
>>> @@ -115,6 +118,7 @@ crit_transfer_to_handler:
>>>      rlwinm    r0,r1,0,0,(31 - THREAD_SHIFT)
>>>      stw    r0,KSP_LIMIT(r8)
>>>      /* fall through */
>>> +_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
>>>  #endif
>>>
>>>  /*
>>> @@ -127,6 +131,7 @@ crit_transfer_to_handler:
>>>      .globl    transfer_to_handler_full
>>>  transfer_to_handler_full:
>>>      SAVE_NVGPRS(r11)
>>> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler_full)
>>>      /* fall through */
>>>
>>>      .globl    transfer_to_handler
>>> @@ -286,6 +291,8 @@ reenable_mmu:
>>>      lwz    r2, GPR2(r11)
>>>      b    fast_exception_return
>>>  #endif
>>> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler)
>>> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler_cont)
>> 
>> These are added after 'reenable_mmu', which is itself not blacklisted. 
>> Is that intentional?
> 
> Yes I put it as the complete end of the entry part, ie just before 
> stack_ovf which is a function by itself.
> 
> Note that reenable_mmu is inside an #ifdef CONFIG_TRACE_IRQFLAGS.
> 
> I'm not completely sure where to put the _ASM_NOKPROBE_SYMBOL()s, that's 
> the reason why I put it close to the symbol itself in my first series.

Ok, I see what you mean. 'reenable_mmu' can probably be moved after the 
end of 'transfer_to_handler_cont' (as also removing what looks to be an 
unused label '1' for the branch to trace_hardirqs_off), but that's a 
minor thing. From the blacklisting point, this is not an issue.

- Naveen
Naveen N. Rao March 31, 2020, 6:17 a.m. UTC | #5
Christophe Leroy wrote:
> 
> 
> Le 30/03/2020 à 20:33, Christophe Leroy a écrit :
>> 
>> 
>> Le 30/03/2020 à 19:08, Naveen N. Rao a écrit :
>>> Christophe Leroy wrote:
>>>> kprobe does not handle events happening in real mode.
>>>>
>>>> As exception entry points are running with MMU disabled,
>>>> blacklist them.
>>>>
>>>> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
>>>> ---
>>>>  arch/powerpc/kernel/entry_32.S | 7 +++++++
>>>>  1 file changed, 7 insertions(+)
>>>>
>>>> diff --git a/arch/powerpc/kernel/entry_32.S 
>>>> b/arch/powerpc/kernel/entry_32.S
>>>> index 94f78c03cb79..9a1a45d6038a 100644
>>>> --- a/arch/powerpc/kernel/entry_32.S
>>>> +++ b/arch/powerpc/kernel/entry_32.S
>>>> @@ -51,6 +51,7 @@ mcheck_transfer_to_handler:
>>>>      mfspr    r0,SPRN_DSRR1
>>>>      stw    r0,_DSRR1(r11)
>>>>      /* fall through */
>>>> +_ASM_NOKPROBE_SYMBOL(mcheck_transfer_to_handler)
>>>>
>>>>      .globl    debug_transfer_to_handler
>>>>  debug_transfer_to_handler:
>>>> @@ -59,6 +60,7 @@ debug_transfer_to_handler:
>>>>      mfspr    r0,SPRN_CSRR1
>>>>      stw    r0,_CSRR1(r11)
>>>>      /* fall through */
>>>> +_ASM_NOKPROBE_SYMBOL(debug_transfer_to_handler)
>>>>
>>>>      .globl    crit_transfer_to_handler
>>>>  crit_transfer_to_handler:
>>>> @@ -94,6 +96,7 @@ crit_transfer_to_handler:
>>>>      rlwinm    r0,r1,0,0,(31 - THREAD_SHIFT)
>>>>      stw    r0,KSP_LIMIT(r8)
>>>>      /* fall through */
>>>> +_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
>>>>  #endif
>>>>
>>>>  #ifdef CONFIG_40x
>>>> @@ -115,6 +118,7 @@ crit_transfer_to_handler:
>>>>      rlwinm    r0,r1,0,0,(31 - THREAD_SHIFT)
>>>>      stw    r0,KSP_LIMIT(r8)
>>>>      /* fall through */
>>>> +_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
>>>>  #endif
>>>>
>>>>  /*
>>>> @@ -127,6 +131,7 @@ crit_transfer_to_handler:
>>>>      .globl    transfer_to_handler_full
>>>>  transfer_to_handler_full:
>>>>      SAVE_NVGPRS(r11)
>>>> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler_full)
>>>>      /* fall through */
>>>>
>>>>      .globl    transfer_to_handler
>>>> @@ -286,6 +291,8 @@ reenable_mmu:
>>>>      lwz    r2, GPR2(r11)
>>>>      b    fast_exception_return
>>>>  #endif
>>>> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler)
>>>> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler_cont)
>>>
>>> These are added after 'reenable_mmu', which is itself not blacklisted. 
>>> Is that intentional?
>> 
>> Yes I put it as the complete end of the entry part, ie just before 
>> stack_ovf which is a function by itself.
>> 
>> Note that reenable_mmu is inside an #ifdef CONFIG_TRACE_IRQFLAGS.
>> 
>> I'm not completely sure where to put the _ASM_NOKPROBE_SYMBOL()s, that's 
>> the reason why I put it close to the symbol itself in my first series.
>> 
>> Could you have a look at the code and tell me what looks the most 
>> appropriate as a location to you ?
>> 
>> https://elixir.bootlin.com/linux/v5.6/source/arch/powerpc/kernel/entry_32.S#L230 
> 
> Ok, thinking about it once more, I guess we have a problem as everything 
> after that reenable_mmu will be visible.

I see that we reach reenable_mmu through a 'rfi' with MSR_KERNEL, which 
seems safe to me. So, I figured it can be probed without issues?

- Naveen
Christophe Leroy March 31, 2020, 6:28 a.m. UTC | #6
Le 31/03/2020 à 08:17, Naveen N. Rao a écrit :
> Christophe Leroy wrote:
>>
>>
>> Le 30/03/2020 à 20:33, Christophe Leroy a écrit :
>>>
>>>
>>> Le 30/03/2020 à 19:08, Naveen N. Rao a écrit :
>>>> Christophe Leroy wrote:
>>>>> kprobe does not handle events happening in real mode.
>>>>>
>>>>> As exception entry points are running with MMU disabled,
>>>>> blacklist them.
>>>>>
>>>>> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
>>>>> ---
>>>>>  arch/powerpc/kernel/entry_32.S | 7 +++++++
>>>>>  1 file changed, 7 insertions(+)
>>>>>
>>>>> diff --git a/arch/powerpc/kernel/entry_32.S 
>>>>> b/arch/powerpc/kernel/entry_32.S
>>>>> index 94f78c03cb79..9a1a45d6038a 100644
>>>>> --- a/arch/powerpc/kernel/entry_32.S
>>>>> +++ b/arch/powerpc/kernel/entry_32.S
>>>>> @@ -51,6 +51,7 @@ mcheck_transfer_to_handler:
>>>>>      mfspr    r0,SPRN_DSRR1
>>>>>      stw    r0,_DSRR1(r11)
>>>>>      /* fall through */
>>>>> +_ASM_NOKPROBE_SYMBOL(mcheck_transfer_to_handler)
>>>>>
>>>>>      .globl    debug_transfer_to_handler
>>>>>  debug_transfer_to_handler:
>>>>> @@ -59,6 +60,7 @@ debug_transfer_to_handler:
>>>>>      mfspr    r0,SPRN_CSRR1
>>>>>      stw    r0,_CSRR1(r11)
>>>>>      /* fall through */
>>>>> +_ASM_NOKPROBE_SYMBOL(debug_transfer_to_handler)
>>>>>
>>>>>      .globl    crit_transfer_to_handler
>>>>>  crit_transfer_to_handler:
>>>>> @@ -94,6 +96,7 @@ crit_transfer_to_handler:
>>>>>      rlwinm    r0,r1,0,0,(31 - THREAD_SHIFT)
>>>>>      stw    r0,KSP_LIMIT(r8)
>>>>>      /* fall through */
>>>>> +_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
>>>>>  #endif
>>>>>
>>>>>  #ifdef CONFIG_40x
>>>>> @@ -115,6 +118,7 @@ crit_transfer_to_handler:
>>>>>      rlwinm    r0,r1,0,0,(31 - THREAD_SHIFT)
>>>>>      stw    r0,KSP_LIMIT(r8)
>>>>>      /* fall through */
>>>>> +_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
>>>>>  #endif
>>>>>
>>>>>  /*
>>>>> @@ -127,6 +131,7 @@ crit_transfer_to_handler:
>>>>>      .globl    transfer_to_handler_full
>>>>>  transfer_to_handler_full:
>>>>>      SAVE_NVGPRS(r11)
>>>>> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler_full)
>>>>>      /* fall through */
>>>>>
>>>>>      .globl    transfer_to_handler
>>>>> @@ -286,6 +291,8 @@ reenable_mmu:
>>>>>      lwz    r2, GPR2(r11)
>>>>>      b    fast_exception_return
>>>>>  #endif
>>>>> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler)
>>>>> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler_cont)
>>>>
>>>> These are added after 'reenable_mmu', which is itself not 
>>>> blacklisted. Is that intentional?
>>>
>>> Yes I put it as the complete end of the entry part, ie just before 
>>> stack_ovf which is a function by itself.
>>>
>>> Note that reenable_mmu is inside an #ifdef CONFIG_TRACE_IRQFLAGS.
>>>
>>> I'm not completely sure where to put the _ASM_NOKPROBE_SYMBOL()s, 
>>> that's the reason why I put it close to the symbol itself in my first 
>>> series.
>>>
>>> Could you have a look at the code and tell me what looks the most 
>>> appropriate as a location to you ?
>>>
>>> https://elixir.bootlin.com/linux/v5.6/source/arch/powerpc/kernel/entry_32.S#L230 
>>
>>
>> Ok, thinking about it once more, I guess we have a problem as 
>> everything after that reenable_mmu will be visible.
> 
> I see that we reach reenable_mmu through a 'rfi' with MSR_KERNEL, which 
> seems safe to me. So, I figured it can be probed without issues?

Yes it can. And that's the reason why I didn't blacklist it. However the 
4: and 7: which are after reenable_mmu are called from earlier, at a 
time we are still in real mode. So I need to do something about that I 
guess.

Christophe
Naveen N. Rao March 31, 2020, 6:44 a.m. UTC | #7
Christophe Leroy wrote:
> 
> 
> Le 31/03/2020 à 08:17, Naveen N. Rao a écrit :
>> Christophe Leroy wrote:
>>>
>>>
>>> Le 30/03/2020 à 20:33, Christophe Leroy a écrit :
>>>>
>>>>
>>>> Le 30/03/2020 à 19:08, Naveen N. Rao a écrit :
>>>>> Christophe Leroy wrote:
>>>>>> kprobe does not handle events happening in real mode.
>>>>>>
>>>>>> As exception entry points are running with MMU disabled,
>>>>>> blacklist them.
>>>>>>
>>>>>> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
>>>>>> ---
>>>>>>  arch/powerpc/kernel/entry_32.S | 7 +++++++
>>>>>>  1 file changed, 7 insertions(+)
>>>>>>
>>>>>> diff --git a/arch/powerpc/kernel/entry_32.S 
>>>>>> b/arch/powerpc/kernel/entry_32.S
>>>>>> index 94f78c03cb79..9a1a45d6038a 100644
>>>>>> --- a/arch/powerpc/kernel/entry_32.S
>>>>>> +++ b/arch/powerpc/kernel/entry_32.S
>>>>>> @@ -51,6 +51,7 @@ mcheck_transfer_to_handler:
>>>>>>      mfspr    r0,SPRN_DSRR1
>>>>>>      stw    r0,_DSRR1(r11)
>>>>>>      /* fall through */
>>>>>> +_ASM_NOKPROBE_SYMBOL(mcheck_transfer_to_handler)
>>>>>>
>>>>>>      .globl    debug_transfer_to_handler
>>>>>>  debug_transfer_to_handler:
>>>>>> @@ -59,6 +60,7 @@ debug_transfer_to_handler:
>>>>>>      mfspr    r0,SPRN_CSRR1
>>>>>>      stw    r0,_CSRR1(r11)
>>>>>>      /* fall through */
>>>>>> +_ASM_NOKPROBE_SYMBOL(debug_transfer_to_handler)
>>>>>>
>>>>>>      .globl    crit_transfer_to_handler
>>>>>>  crit_transfer_to_handler:
>>>>>> @@ -94,6 +96,7 @@ crit_transfer_to_handler:
>>>>>>      rlwinm    r0,r1,0,0,(31 - THREAD_SHIFT)
>>>>>>      stw    r0,KSP_LIMIT(r8)
>>>>>>      /* fall through */
>>>>>> +_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
>>>>>>  #endif
>>>>>>
>>>>>>  #ifdef CONFIG_40x
>>>>>> @@ -115,6 +118,7 @@ crit_transfer_to_handler:
>>>>>>      rlwinm    r0,r1,0,0,(31 - THREAD_SHIFT)
>>>>>>      stw    r0,KSP_LIMIT(r8)
>>>>>>      /* fall through */
>>>>>> +_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
>>>>>>  #endif
>>>>>>
>>>>>>  /*
>>>>>> @@ -127,6 +131,7 @@ crit_transfer_to_handler:
>>>>>>      .globl    transfer_to_handler_full
>>>>>>  transfer_to_handler_full:
>>>>>>      SAVE_NVGPRS(r11)
>>>>>> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler_full)
>>>>>>      /* fall through */
>>>>>>
>>>>>>      .globl    transfer_to_handler
>>>>>> @@ -286,6 +291,8 @@ reenable_mmu:
>>>>>>      lwz    r2, GPR2(r11)
>>>>>>      b    fast_exception_return
>>>>>>  #endif
>>>>>> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler)
>>>>>> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler_cont)
>>>>>
>>>>> These are added after 'reenable_mmu', which is itself not 
>>>>> blacklisted. Is that intentional?
>>>>
>>>> Yes I put it as the complete end of the entry part, ie just before 
>>>> stack_ovf which is a function by itself.
>>>>
>>>> Note that reenable_mmu is inside an #ifdef CONFIG_TRACE_IRQFLAGS.
>>>>
>>>> I'm not completely sure where to put the _ASM_NOKPROBE_SYMBOL()s, 
>>>> that's the reason why I put it close to the symbol itself in my first 
>>>> series.
>>>>
>>>> Could you have a look at the code and tell me what looks the most 
>>>> appropriate as a location to you ?
>>>>
>>>> https://elixir.bootlin.com/linux/v5.6/source/arch/powerpc/kernel/entry_32.S#L230 
>>>
>>>
>>> Ok, thinking about it once more, I guess we have a problem as 
>>> everything after that reenable_mmu will be visible.
>> 
>> I see that we reach reenable_mmu through a 'rfi' with MSR_KERNEL, which 
>> seems safe to me. So, I figured it can be probed without issues?
> 
> Yes it can. And that's the reason why I didn't blacklist it. However the 
> 4: and 7: which are after reenable_mmu are called from earlier, at a 
> time we are still in real mode. So I need to do something about that I 
> guess.

Ah yes, good catch. Makes sense to move 'reenable_mmu' after all.

Thanks,
Naveen
diff mbox series

Patch

diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 94f78c03cb79..9a1a45d6038a 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -51,6 +51,7 @@  mcheck_transfer_to_handler:
 	mfspr	r0,SPRN_DSRR1
 	stw	r0,_DSRR1(r11)
 	/* fall through */
+_ASM_NOKPROBE_SYMBOL(mcheck_transfer_to_handler)
 
 	.globl	debug_transfer_to_handler
 debug_transfer_to_handler:
@@ -59,6 +60,7 @@  debug_transfer_to_handler:
 	mfspr	r0,SPRN_CSRR1
 	stw	r0,_CSRR1(r11)
 	/* fall through */
+_ASM_NOKPROBE_SYMBOL(debug_transfer_to_handler)
 
 	.globl	crit_transfer_to_handler
 crit_transfer_to_handler:
@@ -94,6 +96,7 @@  crit_transfer_to_handler:
 	rlwinm	r0,r1,0,0,(31 - THREAD_SHIFT)
 	stw	r0,KSP_LIMIT(r8)
 	/* fall through */
+_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
 #endif
 
 #ifdef CONFIG_40x
@@ -115,6 +118,7 @@  crit_transfer_to_handler:
 	rlwinm	r0,r1,0,0,(31 - THREAD_SHIFT)
 	stw	r0,KSP_LIMIT(r8)
 	/* fall through */
+_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
 #endif
 
 /*
@@ -127,6 +131,7 @@  crit_transfer_to_handler:
 	.globl	transfer_to_handler_full
 transfer_to_handler_full:
 	SAVE_NVGPRS(r11)
+_ASM_NOKPROBE_SYMBOL(transfer_to_handler_full)
 	/* fall through */
 
 	.globl	transfer_to_handler
@@ -286,6 +291,8 @@  reenable_mmu:
 	lwz	r2, GPR2(r11)
 	b	fast_exception_return
 #endif
+_ASM_NOKPROBE_SYMBOL(transfer_to_handler)
+_ASM_NOKPROBE_SYMBOL(transfer_to_handler_cont)
 
 #ifndef CONFIG_VMAP_STACK
 /*