From: Vaibhav Jain <vaibhav@linux.vnet.ibm.com>
To: linuxppc-dev@lists.ozlabs.org,
Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>,
Christophe Lombard <christophe_lombard@fr.ibm.com>,
Philippe Bergheaud <philippe.bergheaud@fr.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>
Cc: Vaibhav Jain <vaibhav@linux.vnet.ibm.com>,
Frederic Barrat <fbarrat@linux.vnet.ibm.com>,
Andrew Donnellan <andrew.donnellan@au1.ibm.com>,
"Alastair D'Silva" <alastair@linux.ibm.com>
Subject: [PATCH v3] powerpc: Avoid signed to unsigned conversion in set_thread_tidr()
Date: Mon, 27 Nov 2017 22:49:35 +0530 [thread overview]
Message-ID: <20171127171935.21364-1-vaibhav@linux.vnet.ibm.com> (raw)
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>
---
Changelog:
v3 -> Updated the patch to not impact the calling convention [Mpe, Christophe]
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 | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index bfdd783e3916..9fb69211a3d4 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1569,19 +1569,22 @@ 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);
-
- return 0;
+ rc = assign_thread_tidr();
+ if (rc > 0) {
+ t->thread.tidr = rc;
+ mtspr(SPRN_TIDR, t->thread.tidr);
+ return 0;
+ } else {
+ return rc;
+ }
}
#endif /* CONFIG_PPC64 */
--
2.14.3
next reply other threads:[~2017-11-27 17:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-27 17:19 Vaibhav Jain [this message]
2017-11-27 23:41 ` [PATCH v3] powerpc: Avoid signed to unsigned conversion in set_thread_tidr() Sukadev Bhattiprolu
2017-11-28 2:57 ` Vaibhav Jain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171127171935.21364-1-vaibhav@linux.vnet.ibm.com \
--to=vaibhav@linux.vnet.ibm.com \
--cc=alastair@linux.ibm.com \
--cc=andrew.donnellan@au1.ibm.com \
--cc=christophe_lombard@fr.ibm.com \
--cc=fbarrat@linux.vnet.ibm.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=philippe.bergheaud@fr.ibm.com \
--cc=sukadev@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).