linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Guo Ren <guoren@kernel.org>
Cc: Palmer Dabbelt <palmer@dabbelt.com>,
	Arnd Bergmann <arnd@arndb.de>, Anup Patel <anup.patel@wdc.com>,
	 gregkh <gregkh@linuxfoundation.org>,
	liush <liush@allwinnertech.com>,  Wei Fu <wefu@redhat.com>,
	Drew Fustini <drew@beagleboard.org>,
	 Wang Junqiang <wangjunqiang@iscas.ac.cn>,
	Christoph Hellwig <hch@infradead.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	 linux-riscv <linux-riscv@lists.infradead.org>,
	linux-csky@vger.kernel.org,
	 linux-s390 <linux-s390@vger.kernel.org>,
	sparclinux <sparclinux@vger.kernel.org>,
	 linuxppc-dev <linuxppc-dev@lists.ozlabs.org>,
	inux-parisc@vger.kernel.org,
	 "open list:BROADCOM NVRAM DRIVER" <linux-mips@vger.kernel.org>,
	 Linux ARM <linux-arm-kernel@lists.infradead.org>,
	 "the arch/x86 maintainers" <x86@kernel.org>,
	Guo Ren <guoren@linux.alibaba.com>
Subject: Re: [PATCH V2 11/17] riscv: compat: Add elf.h implementation
Date: Mon, 10 Jan 2022 15:28:40 +0100	[thread overview]
Message-ID: <CAK8P3a0H2Nq=bFdzWGzzGuFWP85JA7=Td6_rb8GqOF3bYCRJBw@mail.gmail.com> (raw)
In-Reply-To: <20211228143958.3409187-12-guoren@kernel.org>

On Tue, Dec 28, 2021 at 3:39 PM <guoren@kernel.org> wrote:
>
> From: Guo Ren <guoren@linux.alibaba.com>
>
> Implement necessary type and macro for compat elf. See the code
> comment for detail.
>
> Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
> Signed-off-by: Guo Ren <guoren@kernel.org>
> Cc: Arnd Bergmann <arnd@arndb.de>

This looks mostly correct,

> +/*
> + * FIXME: not sure SET_PERSONALITY for compat process is right!
> + */
> +#define SET_PERSONALITY(ex)                                               \
> +do {    if ((ex).e_ident[EI_CLASS] == ELFCLASS32)                         \
> +               set_thread_flag(TIF_32BIT);                                \
> +       else                                                               \
> +               clear_thread_flag(TIF_32BIT);                              \
> +       set_personality(PER_LINUX | (current->personality & (~PER_MASK))); \
> +} while (0)

This means the personality after exec is always set to PER_LINUX, not
PER_LINUX32, which I think is wrong: you want the PER_LINUX32
setting to stick, just like the upper bits do in the default implementation.

What the other ones do is:

| arch/parisc/include/asm/elf.h-
set_personality((current->personality & ~PER_MASK) | PER_LINUX); \

This looks like the same problem you introduce here: always forcing PER_LINUX
instead of PER_LINUX32 makes it impossible to use PER_LINUX32.

| arch/alpha/include/asm/elf.h:#define SET_PERSONALITY(EX)
                           \
| arch/alpha/include/asm/elf.h-   set_personality(((EX).e_flags &
EF_ALPHA_32BIT)         \
| arch/alpha/include/asm/elf.h-      ? PER_LINUX_32BIT : PER_LINUX)
| arch/csky/include/asm/elf.h:#define SET_PERSONALITY(ex)
set_personality(PER_LINUX)
| arch/nds32/include/asm/elf.h:#define SET_PERSONALITY(ex)
set_personality(PER_LINUX)

These look even worse: instead of forcing the lower bits to
PER_LINUX/PER_LINUX32 and
leaving the upper bits untouched, these also clear the upper bits
unconditionally.

| arch/arm64/include/asm/elf.h:#define SET_PERSONALITY(ex)
                                   \
| arch/arm64/include/asm/elf.h-   current->personality &=
~READ_IMPLIES_EXEC;                     \
| arch/x86/um/asm/elf.h:#define SET_PERSONALITY(ex) do {} while(0)
| arch/x86/include/asm/elf.h:#define set_personality_64bit()      do {
} while (0)
| arch/x86/kernel/process_64.c:static void __set_personality_ia32(void)
|         current->personality |= force_personality32;

Inconsistent: does not enforce PER_LINUX/PER_LINUX32 as the default
implementation
does, but just leaves the value untouched (other than (re)setting
READ_IMPLIES_EXEC).
I think this is harmless otherwise, as we generally ignore the lower
bits, except for the
bit of code that checks for PER_LINUX32 in override_architecture() to mangle the
output of sys_newuname() or in /proc/cpuinfo.

| arch/s390/include/asm/elf.h-    if
(personality(current->personality) != PER_LINUX32)   \
| arch/s390/include/asm/elf.h-            set_personality(PER_LINUX |
                   \
| arch/s390/include/asm/elf.h-
(current->personality & ~PER_MASK));    \
| arch/powerpc/include/asm/elf.h- if
(personality(current->personality) != PER_LINUX32)   \
| arch/powerpc/include/asm/elf.h-         set_personality(PER_LINUX |
                   \
| arch/powerpc/include/asm/elf.h-
(current->personality & (~PER_MASK)));  \
| arch/sparc/include/asm/elf_64.h-        if
(personality(current->personality) != PER_LINUX32)   \
| arch/sparc/include/asm/elf_64.h-
set_personality(PER_LINUX |             \
| arch/sparc/include/asm/elf_64.h-
(current->personality & (~PER_MASK)));  \

This is probably the behavior you want to copy.

      Arnd

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-01-10 14:30 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-28 14:39 [PATCH V2 00/17] riscv: compat: Add COMPAT mode support for rv64 guoren
2021-12-28 14:39 ` [PATCH V2 01/17] kconfig: Add SYSVIPC_COMPAT for all architectures guoren
2022-01-10 11:43   ` Arnd Bergmann
2021-12-28 14:39 ` [PATCH V2 02/17] fs: stat: compat: Add __ARCH_WANT_COMPAT_STAT guoren
2022-01-10 11:44   ` Arnd Bergmann
2021-12-28 14:39 ` [PATCH V2 03/17] asm-generic: fcntl: compat: Remove duplicate definitions guoren
2022-01-10 13:35   ` Arnd Bergmann
2022-01-10 16:30     ` Christoph Hellwig
2022-01-11  2:43     ` Guo Ren
2022-01-10 15:56   ` Christophe Leroy
2021-12-28 14:39 ` [PATCH V2 04/17] asm-generic: compat: Cleanup " guoren
2021-12-28 14:39 ` [PATCH V2 05/17] syscalls: compat: Fix the missing part for __SYSCALL_COMPAT guoren
2021-12-28 14:39 ` [PATCH V2 06/17] riscv: Fixup difference with defconfig guoren
2021-12-28 14:39 ` [PATCH V2 07/17] riscv: compat: Add basic compat date type implementation guoren
2021-12-28 14:39 ` [PATCH V2 08/17] riscv: compat: Re-implement TASK_SIZE for COMPAT_32BIT guoren
2021-12-28 14:39 ` [PATCH V2 09/17] riscv: compat: syscall: Add compat_sys_call_table implementation guoren
2021-12-28 14:39 ` [PATCH V2 10/17] riscv: compat: syscall: Add entry.S implementation guoren
2021-12-28 14:39 ` [PATCH V2 11/17] riscv: compat: Add elf.h implementation guoren
2022-01-10 14:28   ` Arnd Bergmann [this message]
2022-01-11  2:42     ` Guo Ren
2021-12-28 14:39 ` [PATCH V2 12/17] riscv: compat: vdso: Add rv32 VDSO base code implementation guoren
2021-12-28 14:39 ` [PATCH V2 13/17] riscv: compat: vdso: Add setup additional pages implementation guoren
2021-12-28 14:39 ` [PATCH V2 14/17] riscv: compat: signal: Add rt_frame implementation guoren
2021-12-28 14:39 ` [PATCH V2 15/17] riscv: compat: ptrace: Add compat_arch_ptrace implement guoren
2021-12-28 14:39 ` [PATCH V2 16/17] riscv: compat: Add UXL_32 support in start_thread guoren
2021-12-28 14:39 ` [PATCH V2 17/17] riscv: compat: Add COMPAT Kbuild skeletal support guoren
2022-01-20  7:39 ` [PATCH V2 00/17] riscv: compat: Add COMPAT mode support for rv64 guoren

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='CAK8P3a0H2Nq=bFdzWGzzGuFWP85JA7=Td6_rb8GqOF3bYCRJBw@mail.gmail.com' \
    --to=arnd@arndb.de \
    --cc=anup.patel@wdc.com \
    --cc=drew@beagleboard.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=guoren@kernel.org \
    --cc=guoren@linux.alibaba.com \
    --cc=hch@infradead.org \
    --cc=inux-parisc@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-csky@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=liush@allwinnertech.com \
    --cc=palmer@dabbelt.com \
    --cc=sparclinux@vger.kernel.org \
    --cc=wangjunqiang@iscas.ac.cn \
    --cc=wefu@redhat.com \
    --cc=x86@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;
as well as URLs for NNTP newsgroup(s).