lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87b9f23ba8b123a765c4139c2112aa365546c1e5.camel@xry111.site>
Date:   Wed, 08 Feb 2023 16:27:31 +0800
From:   Xi Ruoyao <xry111@...111.site>
To:     Youling Tang <tangyouling@...ngson.cn>
Cc:     Jinyang He <hejinyang@...ngson.cn>,
        Huacai Chen <chenhuacai@...nel.org>,
        Xuerui Wang <kernel@...0n.name>, loongarch@...ts.linux.dev,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 0/5] LoongArch: Add kernel relocation and KASLR
 support

On Wed, 2023-02-08 at 12:37 +0800, Youling Tang wrote:
> In the case of "[Patch v2 2/5] LoongArch: use la.pcrel instenad of
> la.abs for exception handlerS", the above failure will occur.
> 
> Patch2 may have certain problems when using the old toolchains.
> 
> Youling.

Thanks for the test...

The problem is: old toolchain uses pcaddu12i/ori/lu32i.d/lu52i.d/add.d
for a 3-operand la.pcrel, while the new toolchain uses
pcalau12i/addi.d/lu32i/lu52i/add.d.  (I've somehow forgotten all the
difference!)

We can fix it with something like...

> +void reloc_handler(unsigned long handler, struct handler_reloc *rel)
> +{
> +	if (!rel)
> +		return;
> +
> +	for (unsigned long i = 0; i < rel->cnt; i++) {
> +		unsigned long pc = handler + rel->entries[i].offset;
> +		unsigned long v = rel->entries[i].sym;

                /* anchor etc. moved into do_reloc_pcalau12i */

> +		union loongarch_instruction *insn =
> +			(union loongarch_instruction *)pc;

                switch insn[0]->reg1i20_format->reg1i20_format {
                case pcaddu12i_op:
                        do_reloc_pcaddu12i(insn, pc, v);
                        break;
                case pcalau12i_op: /* TODO: add it for asm/inst.h */
                        do_reloc_pcalau12i(insn, pc, v);
                        break;
                default:
                        panic("what the f**k");
                }

Alternatively, we can also emit the pcalau12i/addi.d/lu32i/lu52i
sequence and overwrite the pcaddu12i/ori sequence generated by the old
toolchain.

Which way do you like?
-- 
Xi Ruoyao <xry111@...111.site>
School of Aerospace Science and Technology, Xidian University

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ