Skip to content

Commit 82a3959

Browse files
vapierRiku Voipio
authored and
Riku Voipio
committed
linux-user/FLAT: fix auto-stack sizing
The current auto-stack sizing works like it does on a NOMMU system; the problem is that this only works if the envp/argv arrays are fairly slim. On a desktop system, this is rarely the case, and can easily blow past the stack and into data/text regions as the default stack for FLAT progs is a mere 4KiB. So rather than rely on the NOMMU calculation (which is only there because NOMMU can't easily allocate gobs of contiguous mem), calc the full space actually needed and let the MMU host make space. Signed-off-by: Mike Frysinger <[email protected]> Signed-off-by: Riku Voipio <[email protected]>
1 parent 906c1b8 commit 82a3959

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

linux-user/flatload.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -733,8 +733,15 @@ int load_flt_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
733733
* pedantic and include space for the argv/envp array as it may have
734734
* a lot of entries.
735735
*/
736-
#define TOP_OF_ARGS (TARGET_PAGE_SIZE * MAX_ARG_PAGES - sizeof(void *))
737-
stack_len = TOP_OF_ARGS - bprm->p; /* the strings */
736+
stack_len = 0;
737+
for (i = 0; i < bprm->argc; ++i) {
738+
/* the argv strings */
739+
stack_len += strlen(bprm->argv[i]);
740+
}
741+
for (i = 0; i < bprm->envc; ++i) {
742+
/* the envp strings */
743+
stack_len += strlen(bprm->envp[i]);
744+
}
738745
stack_len += (bprm->argc + 1) * 4; /* the argv array */
739746
stack_len += (bprm->envc + 1) * 4; /* the envp array */
740747

0 commit comments

Comments
 (0)