All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] powerpc: Avoid signed to unsigned conversion in set_thread_tidr()
@ 2017-11-23 12:47 Vaibhav Jain
  2017-11-23 12:47 ` [PATCH 2/2] powerpc: Do not assign thread.tidr if already assigned Vaibhav Jain
  2017-11-24  6:17 ` [PATCH 1/2] powerpc: Avoid signed to unsigned conversion in set_thread_tidr() Michael Ellerman
  0 siblings, 2 replies; 6+ messages in thread
From: Vaibhav Jain @ 2017-11-23 12:47 UTC (permalink / raw)
  To: linuxppc-dev, Sukadev Bhattiprolu, Christophe Lombard,
	Philippe Bergheaud
  Cc: Vaibhav Jain, Andrew Donnellan, Alastair D'Silva, Frederic Barrat

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

Fixes: ec233ede4c86("powerpc: Add support for setting SPRN_TIDR")
Signed-off-by: Vaibhav Jain <vaibhav@linux.vnet.ibm.com>
---
 arch/powerpc/kernel/process.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

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

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

end of thread, other threads:[~2017-11-27 17:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-23 12:47 [PATCH 1/2] powerpc: Avoid signed to unsigned conversion in set_thread_tidr() Vaibhav Jain
2017-11-23 12:47 ` [PATCH 2/2] powerpc: Do not assign thread.tidr if already assigned Vaibhav Jain
2017-11-24  6:17 ` [PATCH 1/2] powerpc: Avoid signed to unsigned conversion in set_thread_tidr() Michael Ellerman
2017-11-24  7:08   ` Vaibhav Jain
2017-11-27  3:44     ` Michael Ellerman
2017-11-27 17:05       ` Vaibhav Jain

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.