Skip to content

Commit aca7573

Browse files
vaibhav92mpe
authored andcommitted
powerpc: Avoid signed to unsigned conversion in set_thread_tidr()
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 and a return value of '0' indicates success. Fixes: ec233ed("powerpc: Add support for setting SPRN_TIDR") Signed-off-by: Vaibhav Jain <vaibhav@linux.vnet.ibm.com> Reviewed-by: Christophe Lombard clombard@linux.vnet.ibm.com Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 2621e94 commit aca7573

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

arch/powerpc/kernel/process.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,16 +1569,19 @@ void arch_release_task_struct(struct task_struct *t)
15691569
*/
15701570
int set_thread_tidr(struct task_struct *t)
15711571
{
1572+
int rc;
1573+
15721574
if (!cpu_has_feature(CPU_FTR_ARCH_300))
15731575
return -EINVAL;
15741576

15751577
if (t != current)
15761578
return -EINVAL;
15771579

1578-
t->thread.tidr = assign_thread_tidr();
1579-
if (t->thread.tidr < 0)
1580-
return t->thread.tidr;
1580+
rc = assign_thread_tidr();
1581+
if (rc < 0)
1582+
return rc;
15811583

1584+
t->thread.tidr = rc;
15821585
mtspr(SPRN_TIDR, t->thread.tidr);
15831586

15841587
return 0;

0 commit comments

Comments
 (0)