mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xi Ruoyao <xry111@xry111.site>
To: Youling Tang <tangyouling@loongson.cn>,
	Jinyang He <hejinyang@loongson.cn>,
	Huacai Chen <chenhuacai@kernel.org>
Cc: linux-kernel@vger.kernel.org, loongarch@lists.linux.dev,
	Xuerui Wang <kernel@xen0n.name>,
	Jiaxun Yang <jiaxun.yang@flygoat.com>
Subject: Re: [PATCH 1/3] LoongArch: tools: Add relocs tool support
Date: Thu, 22 Sep 2022 19:19:10 +0800	[thread overview]
Message-ID: <5e12ab67701adf81834dfb88fc3cb6fdf55f676d.camel@xry111.site> (raw)
In-Reply-To: <750719dc-d481-6eba-05c6-50cfdceb871b@loongson.cn>

On Thu, 2022-09-08 at 16:01 +0800, Youling Tang wrote:
> After adding KBUILD_CFLAGS_KERNEL += -mdirect-extern-access, the
> kernel
> will not generate .got, .plt and .got.plt sections (in the new
> toolchain), we should unexpectedly detect that the kernel has these
> sections, maybe add similar patch [1] to detect, x86_64 has the same
> operation.
> 
> But when adding LDFLAGS_vmlinux += -pie (or -shared), there will be
> .got, .plt and .got.plt sections generated, I don't know how the
> toolchain handles it :(?

Hi Youling,

I've pulled your code and make some adjustments for it:

https://github.com/xry111/linux/commits/xry111/la-dev/pie

One adjustment is for FDT removal, another uses a static-PIE style
LDFLAGS as the kernel is more "similar" to a static PIE than a shared
library. In userspace, a static PIE is linked with [1]:

 -static -pie --no-dynamic-linker -z text

[1]: https://gcc.gnu.org/r13-2728

But we have to use "-z notext" for vmlinux. I'm not an expert on kernel
hacking, and I guess it's because the kernel doesn't really care the RWX
permission of itself (I heard this during some discussion about a W/X
page warning added in Binutils-2.39 which is triggered for vmlinux).

With "-static -pie --no-dynamic-linker -z notext" (and GCC trunk &
Binutils trunk), .plt and .got.plt are gone.

.got is still there but it only contains one entry (8 bytes).  AFAIK
this entry (`_GLOBAL_OFFSET_TABLE_[0]`) is set to the link-time address
of _DYNAMIC for a userspace static PIE [2], but vmlinux does not need it
at all.  We can tell the linker to discard it IIUC.

[2]:
https://maskray.me/blog/2021-08-29-all-about-global-offset-table#global_offset_table_0

I've boot the kernel successfully and it seems KASLR is in-effect:

$ sudo cat /proc/kallsyms | grep ' _printk$'
90000000023b28f4 T _printk
$ grep ' _printk$' /boot/System.map-6.0.0-rc6-pie+ 
90000000009828f4 T _printk

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

  reply	other threads:[~2022-09-22 11:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-02 10:08 [PATCH 0/3] Add kernel relocation and KASLR support Youling Tang
2022-09-02 10:08 ` [PATCH 1/3] LoongArch: tools: Add relocs tool support Youling Tang
2022-09-02 11:10   ` Xi Ruoyao
2022-09-02 11:27     ` Xi Ruoyao
2022-09-03  1:57       ` Youling Tang
2022-09-03 10:49         ` Xi Ruoyao
2022-09-03 16:23           ` Jinyang He
2022-09-03 16:53             ` Xi Ruoyao
2022-09-05  2:52               ` Youling Tang
2022-09-06  2:16                 ` Youling Tang
2022-09-06  5:17                   ` Xi Ruoyao
2022-09-07 10:19                     ` Youling Tang
2022-09-08  2:44                       ` Youling Tang
2022-09-08  8:01                         ` Youling Tang
2022-09-22 11:19                           ` Xi Ruoyao [this message]
2022-09-23  9:56                             ` Youling Tang
2022-09-05  1:52             ` Youling Tang
2022-09-02 10:08 ` [PATCH 2/3] LoongArch: Add support for kernel relocation Youling Tang
2022-09-02 10:08 ` [PATCH 3/3] LoongArch: Add support for kernel address space layout randomization (KASLR) Youling Tang

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=5e12ab67701adf81834dfb88fc3cb6fdf55f676d.camel@xry111.site \
    --to=xry111@xry111.site \
    --cc=chenhuacai@kernel.org \
    --cc=hejinyang@loongson.cn \
    --cc=jiaxun.yang@flygoat.com \
    --cc=kernel@xen0n.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=tangyouling@loongson.cn \
    /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

all inboxes | Powered by JetHome®