public inbox for linux-mips@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
To: Jinyang He <hejinyang@loongson.cn>
Cc: Huacai Chen <chenhc@lemote.com>,
	Jiaxun Yang <jiaxun.yang@flygoat.com>,
	linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] MIPS: KASLR: Correcte valid bits in apply_r_mips_26_rel
Date: Thu, 19 Nov 2020 13:36:36 +0100	[thread overview]
Message-ID: <20201119123636.GA4936@alpha.franken.de> (raw)
In-Reply-To: <1605752954-10368-1-git-send-email-hejinyang@loongson.cn>

On Thu, Nov 19, 2020 at 10:29:12AM +0800, Jinyang He wrote:
> 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.
						  rather

> 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;

how about using 

	target_addr += (unsigned long)log_orig & 0xf0000000;

which makes it IMHO even clearer what this does ?

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

  parent reply	other threads:[~2020-11-19 13:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Thomas Bogendoerfer [this message]
2020-11-20  2:48   ` [PATCH 1/3] MIPS: KASLR: Correcte valid bits in apply_r_mips_26_rel Jinyang He

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=20201119123636.GA4936@alpha.franken.de \
    --to=tsbogend@alpha.franken.de \
    --cc=chenhc@lemote.com \
    --cc=hejinyang@loongson.cn \
    --cc=jiaxun.yang@flygoat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    /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