Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: ec233ede4c86("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>

authored by

Vaibhav Jain and committed by
Michael Ellerman
aca7573f 2621e945

+6 -3
+6 -3
arch/powerpc/kernel/process.c
··· 1569 1569 */ 1570 1570 int set_thread_tidr(struct task_struct *t) 1571 1571 { 1572 + int rc; 1573 + 1572 1574 if (!cpu_has_feature(CPU_FTR_ARCH_300)) 1573 1575 return -EINVAL; 1574 1576 1575 1577 if (t != current) 1576 1578 return -EINVAL; 1577 1579 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; 1581 1583 1584 + t->thread.tidr = rc; 1582 1585 mtspr(SPRN_TIDR, t->thread.tidr); 1583 1586 1584 1587 return 0;