From: "Eric W. Biederman" <ebiederm@xmission.com>
To: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: Arnd Bergmann <arnd@arndb.de>,
Richard Henderson <richard.henderson@linaro.org>,
Matt Turner <mattst88@gmail.com>, Kees Cook <kees@kernel.org>,
"Paul E. McKenney" <paulmck@kernel.org>,
linux-alpha@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, Michael Cree <mcree@orcon.net.nz>,
Sam James <sam@gentoo.org>,
"Maciej W. Rozycki" <macro@orcam.me.uk>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Michael Karcher <kernel@mkarcher.dialup.fu-berlin.de>,
Chris Hofstaedtler <zeha@debian.org>,
util-linux@vger.kernel.org, linux-mips@vger.kernel.org,
loongarch@lists.linux.dev
Subject: Re: [PATCH] alpha: Fix personality flag propagation across an exec
Date: Thu, 09 Jan 2025 10:18:42 -0600 [thread overview]
Message-ID: <87ed1cufj1.fsf@email.froward.int.ebiederm.org> (raw)
In-Reply-To: <cc420e1a843da3cf349607369851c338f4049c4e.camel@physik.fu-berlin.de> (John Paul Adrian Glaubitz's message of "Thu, 09 Jan 2025 10:12:03 +0100")
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> writes:
> Hi Arnd,
>
> On Thu, 2025-01-09 at 09:56 +0100, Arnd Bergmann wrote:
>> On Thu, Jan 9, 2025, at 09:46, John Paul Adrian Glaubitz wrote:
>> > On Thu, 2025-01-09 at 09:43 +0100, Arnd Bergmann wrote:
>> > > On Thu, Jan 9, 2025, at 09:01, Arnd Bergmann wrote:
>> > > > On Fri, Jan 3, 2025, at 15:01, John Paul Adrian Glaubitz wrote:
>> > > >
>> > > > >
>> > > > > #define SET_PERSONALITY(EX) \
>> > > > > - set_personality(((EX).e_flags & EF_ALPHA_32BIT) \
>> > > > > - ? PER_LINUX_32BIT : PER_LINUX)
>> > > > > + set_personality((((EX).e_flags & EF_ALPHA_32BIT) \
>> > > > > + ? PER_LINUX_32BIT : PER_LINUX) | (current->personality & (~PER_MASK)))
*Grumble*
It would be good to move those EF_${ARCH} flags from
arch/${ARCH}/include/asm/elf.h to arch/${ARCH}/include/uapi/asm/elf.h
Simply because those flags are architecture specific ABI.
>> > > > This looks wrong to me: since ADDR_LIMIT_32BIT is not part of
>> > > > PER_MASK, executing a regular binary from a taso binary no longer
>> > > > reverts back to the entire 64-bit address space.
>> > > >
>> > > > It seems that the behavior on most other architectures changed in 2012
>> > > > commit 16f3e95b3209 ("cross-arch: don't corrupt personality flags upon
>> > > > exec()").
>> > > >
>> >
>> > So, if I understand this correctly, we should just use PER_MASK on alpha
>> > for 64-bit executables and allow the bits to be cleared for 32-bit binaries?
>>
>> I think ideally the EF_ALPHA_32BIT handling should use TIF_32BIT
>> as we do on other architectures, at that point the custom SET_PERSONALITY()
>> can be removed in favor of the asm-generic version.
>
> I have thought about that as well but I wasn't sure whether the extra
> mangling on alpha was necessary.
>
>> Alternatively this could do something like the arm32 version (note
>> that on arm, PER_LINUX_32BIT/ADDR_LIMIT_32BIT means "allow using
>> the entire 32-bit address space rather than limiting to 26 bits for
>> compatibility", while on alpha it means "use only 31 instead of
>> 42 bits for addressing", but the logic can be the same):
>>
>> unsigned int personality = current->personality & ~PER_MASK;
>> /*
>> * APCS-26 is only valid for OABI executables
>> */
>> if ((eflags & EF_ARM_EABI_MASK) == EF_ARM_EABI_UNKNOWN &&
>> (eflags & EF_ARM_APCS_26))
>> personality &= ~ADDR_LIMIT_32BIT;
>> else
>> personality |= ADDR_LIMIT_32BIT;
>> set_personality(personality);
>
> So, this would be the 100% correct for alpha then which would not loose
> any functionality even for 32-bit binaries?
I don't think it is correct to think about 32-bit binaries on alpha.
Alpha never had a 32bit instruction set. But at some point it looks
like binaries that could not handle more than 31 bits of address
space got ported and someone implemented a work-around. I guess this
is the --taso option that Arnd mentioned.
I think the alpha version would look like:
#define SET_PERSONALITY(ex) \
do { \
unsigned long personality = current->personality & ~PER_MASK; \
if ((EX).e_flags & EF_ALPHA_32BIT) \
personality |= ADDR_LIMIT_32BIT; \
else \
personality &= ~ADDR_LIMIT_32BIT \
set_personality(personality); \
while (0)
I do see code under arch/alpha/ testing ADDR_LIMIT_32BIT when
setting STACK_TOP, TASK_UNMAPPED_BASE, and arch_get_unmapped_area.
So I think the code still works.
>> In any case, I think we should fix alpha, mips and loongarch at
>> the same time, to make sure it doesn't take another decade to
>> fix the rest.
>
> If you're willing to fix all three at once, I would be happy to help
> with the testing on all three architectures as I have machines for all
> of these.
Yes getting those fixed would be nice.
I don't expect it is worth the hassle to remove support for
EF_ALPHA_32BIT, but I looked into it quickly.
I looked at the history to see if I could find any information about
what was using the EF_ALPHA_32BIT flag and unfortunately I could not
find anything. Support for the flag first appeared the 2.1.86 release,
and the change description has been lost to time.
Does anyone know if there are any remaining alpha binaries that set
EF_ALPHA_32BIT?
If no interesting binaries have EF_ALPHA_32BIT set anymore
it might be worth using the generic SET_PERSONALITY and implementing
an arch_check_elf to just fail if one of those binaries show up.
Perhaps:
static inline int arch_check_elf(struct elfhdr *ehdr, bool has_interp,
struct elfhdr *interp_ehdr,
struct arch_elf_state *state)
{
if (WARN_ON_ONCE(ehdr->e_flags & EF_ALPHA_32BIT)) {
return -ENOEXEC;
}
return 0;
}
Though frankly it might make more sense and go the other way. I think
only mips has a non-trivial implementation of arch_check_elf.
Eric
next prev parent reply other threads:[~2025-01-09 16:19 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-03 14:01 John Paul Adrian Glaubitz
2025-01-08 22:49 ` Kees Cook
2025-01-09 0:52 ` Jeff Xu
2025-01-09 8:01 ` Arnd Bergmann
2025-01-09 8:43 ` Arnd Bergmann
2025-01-09 8:46 ` John Paul Adrian Glaubitz
2025-01-09 8:56 ` Arnd Bergmann
2025-01-09 9:12 ` John Paul Adrian Glaubitz
2025-01-09 16:18 ` Eric W. Biederman [this message]
2025-01-09 16:52 ` Arnd Bergmann
2025-01-09 17:17 ` Eric W. Biederman
2025-01-09 20:10 ` Maciej W. Rozycki
2025-01-09 20:53 ` Arnd Bergmann
2025-01-12 14:40 ` Maciej W. Rozycki
2025-01-10 0:28 ` Richard Henderson
2025-01-11 0:16 ` [PATCH] alpha/elf: Fix misc/setarch test of util-linux by removing 32bit support Eric W. Biederman
2025-01-11 1:17 ` Richard Henderson
2025-01-11 10:37 ` John Paul Adrian Glaubitz
2025-01-12 14:40 ` Maciej W. Rozycki
2025-01-12 14:56 ` John Paul Adrian Glaubitz
2025-01-13 5:39 ` [PATCH v2] " Eric W. Biederman
2025-01-18 10:35 ` Ivan Kokshaysky
2025-01-26 17:15 ` John Paul Adrian Glaubitz
2025-01-27 13:27 ` Ivan Kokshaysky
2025-02-03 11:55 ` John Paul Adrian Glaubitz
2025-02-06 15:42 ` Kees Cook
2025-01-11 11:26 ` [PATCH] " Arnd Bergmann
2025-01-11 15:27 ` Ivan Kokshaysky
2025-01-13 5:32 ` Eric W. Biederman
2025-01-11 21:26 ` John Paul Adrian Glaubitz
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=87ed1cufj1.fsf@email.froward.int.ebiederm.org \
--to=ebiederm@xmission.com \
--cc=arnd@arndb.de \
--cc=geert@linux-m68k.org \
--cc=glaubitz@physik.fu-berlin.de \
--cc=kees@kernel.org \
--cc=kernel@mkarcher.dialup.fu-berlin.de \
--cc=linux-alpha@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=loongarch@lists.linux.dev \
--cc=macro@orcam.me.uk \
--cc=mattst88@gmail.com \
--cc=mcree@orcon.net.nz \
--cc=paulmck@kernel.org \
--cc=richard.henderson@linaro.org \
--cc=sam@gentoo.org \
--cc=util-linux@vger.kernel.org \
--cc=zeha@debian.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