[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <9b1749f0-e936-4bf5-90d6-8cf15e4f0ed9@app.fastmail.com>
Date: Thu, 09 Jan 2025 17:52:18 +0100
From: "Arnd Bergmann" <arnd@...db.de>
To: "Eric W. Biederman" <ebiederm@...ssion.com>,
"John Paul Adrian Glaubitz" <glaubitz@...sik.fu-berlin.de>
Cc: "Richard Henderson" <richard.henderson@...aro.org>,
"Matt Turner" <mattst88@...il.com>, "Kees Cook" <kees@...nel.org>,
"Paul E. McKenney" <paulmck@...nel.org>, linux-alpha@...r.kernel.org,
linux-mm@...ck.org, linux-kernel@...r.kernel.org,
"Michael Cree" <mcree@...on.net.nz>, "Sam James" <sam@...too.org>,
"Maciej W. Rozycki" <macro@...am.me.uk>,
"Geert Uytterhoeven" <geert@...ux-m68k.org>,
"Michael Karcher" <kernel@...rcher.dialup.fu-berlin.de>,
"Chris Hofstaedtler" <zeha@...ian.org>, util-linux@...r.kernel.org,
linux-mips@...r.kernel.org, loongarch@...ts.linux.dev
Subject: Re: [PATCH] alpha: Fix personality flag propagation across an exec
On Thu, Jan 9, 2025, at 17:18, Eric W. Biederman wrote:
> John Paul Adrian Glaubitz <glaubitz@...sik.fu-berlin.de> writes:
>> 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:
>>> > > > 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.
There was a well-documented use case for taso with emulation for
OSF/1 a.out binaries, in particular Netscape used 32-bit pointers.
However, the a.out support got removed a while back, and I have
not figured out why it was ever added for ELF. Maybe it was just
easy to duplicate this from the a.out loader?
Obviously some 30 years ago it was common that software was
broken on 64-bit because of invalid integer-pointer casting,
but these days, it's much more common to be broken on 32-bit
instead.
> 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)
Yes, that was what I was suggesting.
> 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.
MIPS introduced the SET_PERSONALITY2() macro specifically to
allow the TIF flags to be set early enough to apply to the
stack allocation, so I suspect it only works partially.
Arnd
Powered by blists - more mailing lists