From: Pavel Machek <pavel@ucw.cz>
To: kernel list <linux-kernel@vger.kernel.org>,
torvalds@transmeta.com,
"Marcelo W. Tosatti" <marcelo@conectiva.com.br>
Subject: execve() fails to report errors
Date: Wed, 6 Mar 2002 00:34:37 +0100 [thread overview]
Message-ID: <20020305233437.GA130@elf.ucw.cz> (raw)
Hi!
Take this trivial .c program. Obviously correct.
struct foo {
char fill[1*1024*1024*1024];
};
struct foo a;
void
main(void)
{
}
Compile. Run. Segfault.
Whose fault? Kernels; it fails to corectly report not enough address
space.
Now, I do not know if this is the right fix (binfmt_elf looks
spaghetty to me) but its certainly better than it was.
Pavel
--- clean/fs/binfmt_elf.c Tue Mar 5 21:52:44 2002
+++ linux/fs/binfmt_elf.c Wed Mar 6 00:14:31 2002
@@ -79,13 +79,19 @@
#define BAD_ADDR(x) ((unsigned long)(x) > TASK_SIZE)
-static void set_brk(unsigned long start, unsigned long end)
+static int set_brk(unsigned long start, unsigned long end)
{
+ int error;
start = ELF_PAGEALIGN(start);
end = ELF_PAGEALIGN(end);
if (end <= start)
- return;
- do_brk(start, end - start);
+ return 0;
+
+ error = do_brk(start, end - start);
+ if (error!=start) {
+ return error;
+ }
+ return 0;
}
@@ -606,7 +613,9 @@
/* There was a PT_LOAD segment with p_memsz > p_filesz
before this one. Map anonymous pages, if needed,
and clear the area. */
- set_brk (elf_bss + load_bias, elf_brk + load_bias);
+ retval = set_brk (elf_bss + load_bias, elf_brk + load_bias);
+ if (retval)
+ goto out_free_dentry;
nbyte = ELF_PAGEOFFSET(elf_bss);
if (nbyte) {
nbyte = ELF_MIN_ALIGN - nbyte;
@@ -721,8 +730,7 @@
/* Calling set_brk effectively mmaps the pages that we need
* for the bss and break sections
*/
- set_brk(elf_bss, elf_brk);
-
+ retval = set_brk(elf_bss, elf_brk);
padzero(elf_bss);
#if 0
@@ -745,6 +753,7 @@
error = do_mmap(NULL, 0, 4096, PROT_READ | PROT_EXEC,
MAP_FIXED | MAP_PRIVATE, 0);
up_write(¤t->mm->mmap_sem);
+ /* FIXME: Check return from mmap! */
}
#ifdef ELF_PLAT_INIT
@@ -760,8 +769,7 @@
start_thread(regs, elf_entry, bprm->p);
if (current->ptrace & PT_PTRACED)
send_sig(SIGTRAP, current, 0);
- retval = 0;
out:
return retval;
/* error cleanup */
@@ -842,9 +852,9 @@
len = ELF_PAGESTART(elf_phdata->p_filesz + elf_phdata->p_vaddr + ELF_MIN_ALIGN - 1);
bss = elf_phdata->p_memsz + elf_phdata->p_vaddr;
- if (bss > len)
- do_brk(len, bss - len);
error = 0;
+ if (bss > len)
+ error = do_brk(len, bss - len);
out_free_ph:
kfree(elf_phdata);
--
(about SSSCA) "I don't say this lightly. However, I really think that the U.S.
no longer is classifiable as a democracy, but rather as a plutocracy." --hpa
next reply other threads:[~2002-03-06 13:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-03-05 23:34 Pavel Machek [this message]
2002-03-06 14:08 ` Richard B. Johnson
2002-03-06 15:21 ` Pavel Machek
2002-03-15 13:01 ` Russell King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020305233437.GA130@elf.ucw.cz \
--to=pavel@ucw.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo@conectiva.com.br \
--cc=torvalds@transmeta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®