There is an unsafe signed to unsigned conversion in set_thread_tidr()
that may cause an error value to be assigned to SPRN_TIDR register and
used as thread-id.
The issue happens as assign_thread_tidr() returns an int and
thread.tidr is an unsigned-long. So a negative error code returned
from assign_thread_tidr() will fail the error check and gets assigned
as tidr as a large positive value.
To fix this the patch assigns the return value of assign_thread_tidr()
to a temporary int and assigns it to thread.tidr iff its '> 0'.
The patch shouldn't impact the calling convention of set_thread_tidr()
i.e all -ve return-values are error codes, +ve return values are
assigned Thread-ids. The way function is implemented it should never
return a '0'.
Fixes: ec233ede4c86("powerpc: Add support for setting SPRN_TIDR")
Signed-off-by: Vaibhav Jain <redacted>
---
Changelog:
v2 -> * Update the patch description to document the calling
convention of set_thread_tidr(). [Mpe]
* Fix a tidr allocation leak.
---
arch/powerpc/kernel/process.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
If set_thread_tidr() is called twice for same task_struct then it will
allocate a new tidr value to it leaving the previous value still
dangling in the vas_thread_ida table.
To fix this the patch changes set_thread_tidr() to check if a tidr
value is already assigned to the task_struct and if yes then returns
the existing value from function instead of allocating a new one.
Fixes: ec233ede4c86("powerpc: Add support for setting SPRN_TIDR")
Signed-off-by: Vaibhav Jain <redacted>
---
v2 -> Fix minor spell errors in patch description
---
arch/powerpc/kernel/process.c | 3 +++
1 file changed, 3 insertions(+)
From: Andrew Donnellan <hidden> Date: 2017-11-27 01:00:48
On 24/11/17 19:33, Vaibhav Jain wrote:
There is an unsafe signed to unsigned conversion in set_thread_tidr()
that may cause an error value to be assigned to SPRN_TIDR register and
used as thread-id.
The issue happens as assign_thread_tidr() returns an int and
thread.tidr is an unsigned-long. So a negative error code returned
from assign_thread_tidr() will fail the error check and gets assigned
as tidr as a large positive value.
To fix this the patch assigns the return value of assign_thread_tidr()
to a temporary int and assigns it to thread.tidr iff its '> 0'.
The patch shouldn't impact the calling convention of set_thread_tidr()
i.e all -ve return-values are error codes, +ve return values are
assigned Thread-ids. The way function is implemented it should never
return a '0'.
Fixes: ec233ede4c86("powerpc: Add support for setting SPRN_TIDR")
Signed-off-by: Vaibhav Jain <redacted>
Reviewed-by: Andrew Donnellan <redacted>
quoted hunk
---
Changelog:
v2 -> * Update the patch description to document the calling
convention of set_thread_tidr(). [Mpe]
* Fix a tidr allocation leak.
---
arch/powerpc/kernel/process.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
From: Andrew Donnellan <hidden> Date: 2017-11-27 01:06:19
On 24/11/17 19:33, Vaibhav Jain wrote:
If set_thread_tidr() is called twice for same task_struct then it will
allocate a new tidr value to it leaving the previous value still
dangling in the vas_thread_ida table.
To fix this the patch changes set_thread_tidr() to check if a tidr
value is already assigned to the task_struct and if yes then returns
the existing value from function instead of allocating a new one.
Fixes: ec233ede4c86("powerpc: Add support for setting SPRN_TIDR")
Signed-off-by: Vaibhav Jain <redacted>
Reviewed-by: Andrew Donnellan <redacted>
quoted hunk
---
v2 -> Fix minor spell errors in patch description
---
arch/powerpc/kernel/process.c | 3 +++
1 file changed, 3 insertions(+)
From: Michael Ellerman <mpe@ellerman.id.au> Date: 2017-11-27 03:48:22
Vaibhav Jain [off-list ref] writes:
There is an unsafe signed to unsigned conversion in set_thread_tidr()
that may cause an error value to be assigned to SPRN_TIDR register and
used as thread-id.
The issue happens as assign_thread_tidr() returns an int and
thread.tidr is an unsigned-long. So a negative error code returned
from assign_thread_tidr() will fail the error check and gets assigned
as tidr as a large positive value.
To fix this the patch assigns the return value of assign_thread_tidr()
to a temporary int and assigns it to thread.tidr iff its '> 0'.
The patch shouldn't impact the calling convention of set_thread_tidr()
But it does? I'm really confused.
Please fix and resend.
cheers
int set_thread_tidr(struct task_struct *t)
{
+ int rc;
+
if (!cpu_has_feature(CPU_FTR_ARCH_300))
return -EINVAL;
Thanks for reviewing the patch Mpe, I have updated the patch and sent a
v3 with the fix that shouldn't impact the calling convention.
--
Vaibhav Jain [off-list ref]
Linux Technology Center, IBM India Pvt. Ltd.
From: Michael Ellerman <hidden> Date: 2017-11-29 12:06:44
On Fri, 2017-11-24 at 08:33:38 UTC, Vaibhav Jain wrote:
If set_thread_tidr() is called twice for same task_struct then it will
allocate a new tidr value to it leaving the previous value still
dangling in the vas_thread_ida table.
To fix this the patch changes set_thread_tidr() to check if a tidr
value is already assigned to the task_struct and if yes then returns
the existing value from function instead of allocating a new one.
Fixes: ec233ede4c86("powerpc: Add support for setting SPRN_TIDR")
Signed-off-by: Vaibhav Jain <redacted>
Reviewed-by: Andrew Donnellan <redacted>