From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 25932 invoked from network); 30 Jan 2021 21:40:36 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 30 Jan 2021 21:40:36 -0000 Received: (qmail 13823 invoked by uid 550); 30 Jan 2021 21:40:33 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 13800 invoked from network); 30 Jan 2021 21:40:32 -0000 Date: Sat, 30 Jan 2021 16:40:20 -0500 From: Rich Felker To: =?utf-8?B?w4lyaWNv?= Nogueira Cc: musl@lists.openwall.com Message-ID: <20210130214020.GQ23432@brightrain.aerifal.cx> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] 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