Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Sat, 30 Jan 2021 16:40:20 -0500
From: Rich Felker <dalias@...c.org>
To: Érico Nogueira <ericonr@...root.org>
Cc: musl@...ts.openwall.com
Subject: Re: Some pending changes/patches

On Sun, Jan 17, 2021 at 04:42:31PM -0300, Érico Nogueira wrote:
> - fix type for __libc_start_main. In crt1.c and rcrt1.c, it is:
> 
> int __libc_start_main(int (*)(), int, char **,
> 	void (*)(), void(*)(), void(*)());
> 
> but in __libc_start_main.c, it is
> 
> int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
> 
> as far as I can tell the fix is simple and the signature mismatch isn't
> an issue. Since I don't know the context for the mismatch and therefore
> wouldn't be able to write an appropriate commit message, I refrained
> from sending a patch for it.

I've wanted to fix this, but actually I don't know if we can; it needs
analysis. Defining the function with the unused junk args imposes an
ABI constraint that the caller (__libc_start_main) is entered with
argument space for 6 arguments. On some pass-by-register archs this is
not a constraint at all, but on pass-by-stack archs or archs where the
ABI requires the caller to reserve stack slots for the callee to spill
argument registers into, it does. If there's not sufficient space
reserved here, __libc_start_main could clobber space that overlaps
with argv[].

Now, crt1.c makes the call correctly with space reserved for 6
arguments. But prior to the switch to crt1.c and crt_arch.h, there was
separate per-arch asm making the call to __libc_start_main, and some
archs might have omitted the stack space for these slots. So this old
asm needs to be read to determine if there may be binaries calling the
function as if it were a 3-arg one.

I *think* we're okay here. The asm was removed in commit
6fef8cafbd0f6f185897bc87feb1ff66e2e204e1, and at that time (2015), all
the remaining asm versions seemed to still be passing the extra 3
args, despite __libc_start_main having dropped use of them much
earlier (2013, commit 7586360badcae6e73f04eb1b8189ce630281c4b2). But I
would like to review it further before making a change here.

Rich

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.