[PATCH 1/2] powerpc: Avoid signed to unsigned conversion in set_thread_tidr()
Michael Ellerman
mpe at ellerman.id.au
Fri Nov 24 17:17:30 AEDT 2017
Vaibhav Jain <vaibhav at linux.vnet.ibm.com> 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'.
.. and changes the calling convention of the function.
Now it returns -ve error values, or a +ve TIDR value when it succeeds,
or possibly 0 if that's returned by assign_thread_tidr().
Which I'm not sure you meant to do. If you did, you should at least
document it.
But frankly I'd rather we left it the way it was, -ve error or 0 for
success.
cheers
> diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
> index bfdd783e3916..a6eaf924c8b6 100644
> --- a/arch/powerpc/kernel/process.c
> +++ b/arch/powerpc/kernel/process.c
> @@ -1569,19 +1569,21 @@ void arch_release_task_struct(struct task_struct *t)
> */
> int set_thread_tidr(struct task_struct *t)
> {
> + int rc;
> +
> if (!cpu_has_feature(CPU_FTR_ARCH_300))
> return -EINVAL;
>
> if (t != current)
> return -EINVAL;
>
> - t->thread.tidr = assign_thread_tidr();
> - if (t->thread.tidr < 0)
> - return t->thread.tidr;
> -
> - mtspr(SPRN_TIDR, t->thread.tidr);
> + rc = assign_thread_tidr();
> + if (rc > 0) {
> + t->thread.tidr = assign_thread_tidr();
> + mtspr(SPRN_TIDR, t->thread.tidr);
> + }
>
> - return 0;
> + return rc;
> }
>
> #endif /* CONFIG_PPC64 */
> --
> 2.14.3
More information about the Linuxppc-dev
mailing list