Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <CAMo8BfJhv6U2VGtd7H3f2Z6xDXAvkHRapZVaKZ1GWJmkBn7tUg@mail.gmail.com>
Date: Wed, 20 Mar 2024 08:54:56 -0700
From: Max Filippov <jcmvbkbc@...il.com>
To: Rich Felker <dalias@...c.org>
Cc: musl@...ts.openwall.com
Subject: AT_EXECFN aux entry passed by the linux kernel is broken in NOMMU

Hi Rich,

I began testing xtensa FDPIC musl port in full system emulation and
found that /sbin/init crashes inside __dls3() on the following line:

               if ((aux[0] & (1UL<<AT_EXECFN))
                   && strncmp((char *)aux[AT_EXECFN], "/proc/", 6))

I see that aux[AT_EXECFN] equals 0x1fff1, it can be traced back to the value
0x1fffc written into the bprm->p on its initialization in the
__bprm_mm_init() here:
  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/exec.c?h=v6.8#n352
moved backwards by the copy_string_kernel() call here:
  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/exec.c?h=v6.8#n1958
copied to bprm->exec and then written to the aux vector unchanged here:
  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/binfmt_elf_fdpic.c?h=v6.8#n661

I understand that in NOMMU kernel the bprm->p is the offset inside the
temporary program arguments array maintained in separate pages
in the linux_binprm::page and it needs translation to the actual address
when that array is finally copied to the user stack. It seems that both the
kernel code that creates aux[AT_EXECFN] and the musl code that
examines it predate the SH FDPIC port, so somehow it worked for SH,
I guess because on SH accessing the addresses below 0x20000 didn't
cause a crash?

Disabling the above reference to aux[AT_EXECFN] fixes the boot on
xtensa NOMMU kernel for me.

-- 
Thanks.
-- Max

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.