All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] MIPS: KASLR: Correcte valid bits in apply_r_mips_26_rel
@ 2020-11-19  2:29 Jinyang He
  2020-11-19  2:29 ` [PATCH 2/3] MIPS: Loongson64: Add KASLR support Jinyang He
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Jinyang He @ 2020-11-19  2:29 UTC (permalink / raw)
  To: Thomas Bogendoerfer, Huacai Chen, Jiaxun Yang; +Cc: linux-mips, linux-kernel

Apply_r_mips_26_rel() relocates instructions like j, jal and etc. These
instructions consist of 6bits function field and 26bits address field.
The value of target_addr as follows,
=================================================================
|     high 4bits           |            low 28bits              |
=================================================================
|the high 4bits of this PC | the low 26bits of instructions << 2|
=================================================================
Thus, loc_orig and log_new both need high 4bits ranther than high 6bits.
Replace 0x3ffffff with 0xfffffff.

Signed-off-by: Jinyang He <hejinyang@loongson.cn>
---
 arch/mips/kernel/relocate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/mips/kernel/relocate.c b/arch/mips/kernel/relocate.c
index 3d80a51..709cfa0 100644
--- a/arch/mips/kernel/relocate.c
+++ b/arch/mips/kernel/relocate.c
@@ -95,7 +95,7 @@ static int __init apply_r_mips_26_rel(u32 *loc_orig, u32 *loc_new, long offset)
 
 	/* Original target address */
 	target_addr <<= 2;
-	target_addr += (unsigned long)loc_orig & ~0x03ffffff;
+	target_addr += (unsigned long)loc_orig & ~0x0fffffff;
 
 	/* Get the new target address */
 	target_addr += offset;
@@ -105,7 +105,7 @@ static int __init apply_r_mips_26_rel(u32 *loc_orig, u32 *loc_new, long offset)
 		return -ENOEXEC;
 	}
 
-	target_addr -= (unsigned long)loc_new & ~0x03ffffff;
+	target_addr -= (unsigned long)loc_new & ~0x0fffffff;
 	target_addr >>= 2;
 
 	*loc_new = (*loc_new & ~0x03ffffff) | (target_addr & 0x03ffffff);
-- 
2.1.0


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

end of thread, other threads:[~2020-11-20  2:48 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-19  2:29 [PATCH 1/3] MIPS: KASLR: Correcte valid bits in apply_r_mips_26_rel Jinyang He
2020-11-19  2:29 ` [PATCH 2/3] MIPS: Loongson64: Add KASLR support Jinyang He
2020-11-19  2:29 ` [PATCH 3/3] MIPS: KASLR: Make relocation_address can be configured Jinyang He
2020-11-19  8:06   ` Sergei Shtylyov
2020-11-19  9:31     ` Jinyang He
2020-11-19 12:45   ` Thomas Bogendoerfer
2020-11-20  2:43     ` Jinyang He
2020-11-19 12:36 ` [PATCH 1/3] MIPS: KASLR: Correcte valid bits in apply_r_mips_26_rel Thomas Bogendoerfer
2020-11-20  2:48   ` Jinyang He

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.