Re: [PATCH] alpha: Fix personality flag propagation across an exec

John Paul Adrian Glaubitz
2025-01-09T08:47:00Z

Hi Arnd,

thanks a lot for your feedback!

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)))
> >
> > 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()").
> >
> > At the time, the same bug existed on mips, parisc and tile, but those
> > got fixed quickly.
>
> Correction: from what I can tell, mips still has the bug (and now
> also loongarch), it's just in SET_PERSONALITY2() now instead of
> SET_PERSONALITY():
>
> current->personality &= ~READ_IMPLIES_EXEC;
> ...
> p = personality(current->personality); \
> if (p != PER_LINUX32 && p != PER_LINUX) \
> set_personality(PER_LINUX); \
>
> personality() only returns the lower 8 bits (execution domain),
> so if any of them are set (BSD/HPUX/IRIX32/IRIX64/...), both
> the upper and the lower bits are cleared, otherwise neither
> of them are.
>
> The behavior on the other architectures is that we clear the
> lower bits but keep the upper ones.

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?

Adrian

--
.''`. John Paul Adrian Glaubitz
: :' : Debian Developer
`. `' Physicist
`- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913