linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] firmware: qcom: scm: Fix crash in qcom_scm_call_atomic1()
@ 2018-04-09 21:40 Niklas Cassel
  2018-04-10 18:58 ` Bjorn Andersson
  2018-04-11  1:55 ` Stephen Boyd
  0 siblings, 2 replies; 3+ messages in thread
From: Niklas Cassel @ 2018-04-09 21:40 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Stephen Boyd,
	Avaneesh Kumar Dwivedi, Niklas Cassel
  Cc: linux-arm-msm, linux-kernel

qcom_scm_call_atomic1() can crash with a NULL pointer dereference at
qcom_scm_call_atomic1+0x30/0x48.

disassembly of qcom_scm_call_atomic1():
...
<0xc08d73b0 <+12>: ldr r3, [r12]
... (no instruction explicitly modifies r12)
0xc08d73cc <+40>: smc 0
... (no instruction explicitly modifies r12)
0xc08d73d4 <+48>: ldr r3, [r12] <- crashing instruction
...

Since the first ldr is successful, and since r12 isn't explicitly
modified by any instruction between the first and the second ldr,
it must have been modified by the smc call, which is ok,
since r12 is caller save according to the AAPCS.

Add r12 to the clobber list so that the compiler knows that the
callee potentially overwrites the value in r12.
Clobber descriptions may not in any way overlap with an input or
output operand.

Signed-off-by: Niklas Cassel <niklas.cassel@linaro.org>
---
 drivers/firmware/qcom_scm-32.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/firmware/qcom_scm-32.c b/drivers/firmware/qcom_scm-32.c
index dfbd894d5bb7..4e24e591ae74 100644
--- a/drivers/firmware/qcom_scm-32.c
+++ b/drivers/firmware/qcom_scm-32.c
@@ -147,7 +147,7 @@ static u32 smc(u32 cmd_addr)
 			"smc	#0	@ switch to secure world\n"
 			: "=r" (r0)
 			: "r" (r0), "r" (r1), "r" (r2)
-			: "r3");
+			: "r3", "r12");
 	} while (r0 == QCOM_SCM_INTERRUPTED);
 
 	return r0;
@@ -263,7 +263,7 @@ static s32 qcom_scm_call_atomic1(u32 svc, u32 cmd, u32 arg1)
 			"smc    #0      @ switch to secure world\n"
 			: "=r" (r0)
 			: "r" (r0), "r" (r1), "r" (r2)
-			: "r3");
+			: "r3", "r12");
 	return r0;
 }
 
@@ -298,7 +298,7 @@ static s32 qcom_scm_call_atomic2(u32 svc, u32 cmd, u32 arg1, u32 arg2)
 			"smc    #0      @ switch to secure world\n"
 			: "=r" (r0)
 			: "r" (r0), "r" (r1), "r" (r2), "r" (r3)
-			);
+			: "r12");
 	return r0;
 }
 
@@ -328,7 +328,7 @@ u32 qcom_scm_get_version(void)
 			"smc	#0	@ switch to secure world\n"
 			: "=r" (r0), "=r" (r1)
 			: "r" (r0), "r" (r1)
-			: "r2", "r3");
+			: "r2", "r3", "r12");
 	} while (r0 == QCOM_SCM_INTERRUPTED);
 
 	version = r1;
-- 
2.14.3

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

* Re: [PATCH] firmware: qcom: scm: Fix crash in qcom_scm_call_atomic1()
  2018-04-09 21:40 [PATCH] firmware: qcom: scm: Fix crash in qcom_scm_call_atomic1() Niklas Cassel
@ 2018-04-10 18:58 ` Bjorn Andersson
  2018-04-11  1:55 ` Stephen Boyd
  1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Andersson @ 2018-04-10 18:58 UTC (permalink / raw)
  To: Niklas Cassel
  Cc: Andy Gross, Stephen Boyd, Avaneesh Kumar Dwivedi, linux-arm-msm,
	linux-kernel

On Mon 09 Apr 14:40 PDT 2018, Niklas Cassel wrote:

> qcom_scm_call_atomic1() can crash with a NULL pointer dereference at
> qcom_scm_call_atomic1+0x30/0x48.
> 
> disassembly of qcom_scm_call_atomic1():
> ...
> <0xc08d73b0 <+12>: ldr r3, [r12]
> ... (no instruction explicitly modifies r12)
> 0xc08d73cc <+40>: smc 0
> ... (no instruction explicitly modifies r12)
> 0xc08d73d4 <+48>: ldr r3, [r12] <- crashing instruction
> ...
> 
> Since the first ldr is successful, and since r12 isn't explicitly
> modified by any instruction between the first and the second ldr,
> it must have been modified by the smc call, which is ok,
> since r12 is caller save according to the AAPCS.
> 
> Add r12 to the clobber list so that the compiler knows that the
> callee potentially overwrites the value in r12.
> Clobber descriptions may not in any way overlap with an input or
> output operand.
> 

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

> Signed-off-by: Niklas Cassel <niklas.cassel@linaro.org>
> ---
>  drivers/firmware/qcom_scm-32.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/firmware/qcom_scm-32.c b/drivers/firmware/qcom_scm-32.c
> index dfbd894d5bb7..4e24e591ae74 100644
> --- a/drivers/firmware/qcom_scm-32.c
> +++ b/drivers/firmware/qcom_scm-32.c
> @@ -147,7 +147,7 @@ static u32 smc(u32 cmd_addr)
>  			"smc	#0	@ switch to secure world\n"
>  			: "=r" (r0)
>  			: "r" (r0), "r" (r1), "r" (r2)
> -			: "r3");
> +			: "r3", "r12");
>  	} while (r0 == QCOM_SCM_INTERRUPTED);
>  
>  	return r0;
> @@ -263,7 +263,7 @@ static s32 qcom_scm_call_atomic1(u32 svc, u32 cmd, u32 arg1)
>  			"smc    #0      @ switch to secure world\n"
>  			: "=r" (r0)
>  			: "r" (r0), "r" (r1), "r" (r2)
> -			: "r3");
> +			: "r3", "r12");
>  	return r0;
>  }
>  
> @@ -298,7 +298,7 @@ static s32 qcom_scm_call_atomic2(u32 svc, u32 cmd, u32 arg1, u32 arg2)
>  			"smc    #0      @ switch to secure world\n"
>  			: "=r" (r0)
>  			: "r" (r0), "r" (r1), "r" (r2), "r" (r3)
> -			);
> +			: "r12");
>  	return r0;
>  }
>  
> @@ -328,7 +328,7 @@ u32 qcom_scm_get_version(void)
>  			"smc	#0	@ switch to secure world\n"
>  			: "=r" (r0), "=r" (r1)
>  			: "r" (r0), "r" (r1)
> -			: "r2", "r3");
> +			: "r2", "r3", "r12");
>  	} while (r0 == QCOM_SCM_INTERRUPTED);
>  
>  	version = r1;
> -- 
> 2.14.3
> 

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

* Re: [PATCH] firmware: qcom: scm: Fix crash in qcom_scm_call_atomic1()
  2018-04-09 21:40 [PATCH] firmware: qcom: scm: Fix crash in qcom_scm_call_atomic1() Niklas Cassel
  2018-04-10 18:58 ` Bjorn Andersson
@ 2018-04-11  1:55 ` Stephen Boyd
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Boyd @ 2018-04-11  1:55 UTC (permalink / raw)
  To: Andy Gross, Avaneesh Kumar Dwivedi, Bjorn Andersson,
	Niklas Cassel, Stephen Boyd
  Cc: linux-arm-msm, linux-kernel

Quoting Niklas Cassel (2018-04-09 14:40:15)
> qcom_scm_call_atomic1() can crash with a NULL pointer dereference at
> qcom_scm_call_atomic1+0x30/0x48.
> 
> disassembly of qcom_scm_call_atomic1():
> ...
> <0xc08d73b0 <+12>: ldr r3, [r12]
> ... (no instruction explicitly modifies r12)
> 0xc08d73cc <+40>: smc 0
> ... (no instruction explicitly modifies r12)
> 0xc08d73d4 <+48>: ldr r3, [r12] <- crashing instruction
> ...
> 
> Since the first ldr is successful, and since r12 isn't explicitly
> modified by any instruction between the first and the second ldr,
> it must have been modified by the smc call, which is ok,
> since r12 is caller save according to the AAPCS.
> 
> Add r12 to the clobber list so that the compiler knows that the
> callee potentially overwrites the value in r12.
> Clobber descriptions may not in any way overlap with an input or
> output operand.
> 
> Signed-off-by: Niklas Cassel <niklas.cassel@linaro.org>
> ---

Reviewed-by: Stephen Boyd <sboyd@kernel.org>

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

end of thread, other threads:[~2018-04-11  1:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-09 21:40 [PATCH] firmware: qcom: scm: Fix crash in qcom_scm_call_atomic1() Niklas Cassel
2018-04-10 18:58 ` Bjorn Andersson
2018-04-11  1:55 ` Stephen Boyd

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).