diff options
author | Michael Ellerman <michael@ellerman.id.au> | 2008-06-23 21:32:24 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2008-06-30 21:28:19 -0400 |
commit | 053a858efa46c9ab86363b271374ec02ad2af753 (patch) | |
tree | 21f5a7dd1718d33a38083fc51cdaad054fdbae72 /arch/powerpc/lib | |
parent | e7a57273c6407bb6903fbaddec8c2119bf318617 (diff) |
powerpc: Make create_branch() return errors if the branch target is too large
If you pass a target value to create_branch() which is more than 32MB - 4,
or - 32MB away from the branch site, then it's impossible to create an
immediate branch. The current code doesn't check, which will lead to us
creating a branch to somewhere else - which is bad.
For code that cares to check we return 0, which is easy to check for, and
for code that doesn't at least we'll be creating an illegal instruction,
rather than a branch to some random address.
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Acked-by: Kumar Gala <galak@kernel.crashing.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/lib')
-rw-r--r-- | arch/powerpc/lib/code-patching.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c index 638dde313cb..430f4c15d78 100644 --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c | |||
@@ -26,12 +26,18 @@ unsigned int create_branch(const unsigned int *addr, | |||
26 | unsigned long target, int flags) | 26 | unsigned long target, int flags) |
27 | { | 27 | { |
28 | unsigned int instruction; | 28 | unsigned int instruction; |
29 | long offset; | ||
29 | 30 | ||
31 | offset = target; | ||
30 | if (! (flags & BRANCH_ABSOLUTE)) | 32 | if (! (flags & BRANCH_ABSOLUTE)) |
31 | target = target - (unsigned long)addr; | 33 | offset = offset - (unsigned long)addr; |
34 | |||
35 | /* Check we can represent the target in the instruction format */ | ||
36 | if (offset < -0x2000000 || offset > 0x1fffffc || offset & 0x3) | ||
37 | return 0; | ||
32 | 38 | ||
33 | /* Mask out the flags and target, so they don't step on each other. */ | 39 | /* Mask out the flags and target, so they don't step on each other. */ |
34 | instruction = 0x48000000 | (flags & 0x3) | (target & 0x03FFFFFC); | 40 | instruction = 0x48000000 | (flags & 0x3) | (offset & 0x03FFFFFC); |
35 | 41 | ||
36 | return instruction; | 42 | return instruction; |
37 | } | 43 | } |