From: Willy Tarreau <w@1wt.eu>
To: Ernie Petrides <petrides@redhat.com>
Cc: Solar Designer <solar@openwall.com>,
Chuck Ebbert <76306.1226@compuserve.com>,
Andrew Morton <akpm@osdl.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] binfmt_elf.c : the BAD_ADDR macro again
Date: Mon, 21 Aug 2006 23:11:04 +0200 [thread overview]
Message-ID: <20060821211104.GA7790@1wt.eu> (raw)
In-Reply-To: <200608212035.k7LKZlCQ007334@pasta.boston.redhat.com>
On Mon, Aug 21, 2006 at 04:35:47PM -0400, Ernie Petrides wrote:
> On Sunday, 20-Aug-2006 at 18:23 +0200, Willy Tarreau wrote:
>
> > On Sun, Aug 20, 2006 at 07:51:22PM +0400, Solar Designer wrote:
> > > On Sun, Aug 20, 2006 at 11:15:15AM +0200, Willy Tarreau wrote:
> > > > The proper fix would then be :
> > > [...]
> > > > -#define BAD_ADDR(x) ((unsigned long)(x) > TASK_SIZE)
> > > > +#define BAD_ADDR(x) ((unsigned long)(x) >= TASK_SIZE)
> > > [...]
> > > > - if (k > TASK_SIZE || eppnt->p_filesz > eppnt->p_memsz ||
> > > > + if (BAD_ADDR(k) || eppnt->p_filesz > eppnt->p_memsz ||
> > > [...]
> > > > - if (k > TASK_SIZE || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
> > > > + if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
> > >
> > > Looks OK to me.
>
> These are all correct.
OK.
> > > > And even then, I'm not happy with this test :
> > > >
> > > > TASK_SIZE - elf_ppnt->p_memsz < k
> > > >
> > > > because it means that we only raise the error when
> > > >
> > > > k + elf_ppnt->p_memsz > TASK_SIZE
> > > >
> > > > I really think that we want to check this instead :
> > > >
> > > > k + elf_ppnt->p_memsz >= TASK_SIZE
> > > >
> > > > Otherwise we leave a window where this is undetected :
> > > >
> > > > load_addr + eppnt->p_vaddr == TASK_SIZE - eppnt->p_memsz
>
> The reason I did not propose changing these is because these are
> end-point checks (as opposed to starting address checks). I think
> that the following "equals" condition is conceptually valid:
>
> (starting-address + region-size == TASK_SIZE)
Agreed.
> > > > This will later lead to last_bss getting readjusted to TASK_SIZE, which I
> > > > don't think is expected at all :
> > > >
> > > > k = load_addr + eppnt->p_memsz + eppnt->p_vaddr;
> > > > if (k > last_bss)
> > > > last_bss = k;
>
> This is an interesting case, but I think the error checking works okay.
>
> After the ELF phdr loop, the resulting "last_bss" is used as follows:
>
> /* Map the last of the bss segment */
> if (last_bss > elf_bss) {
> down_write(¤t->mm->mmap_sem);
> error = do_brk(elf_bss, last_bss - elf_bss);
> up_write(¤t->mm->mmap_sem);
> if (BAD_ADDR(error))
> goto out_close;
> }
>
> The variable "last_bss" is used to compute the size argument in the
> call to do_brk(). If the section extends beyond TASK_SIZE, then do_brk()
> will return -EINVAL. If the do_brk() call succeeds but "elf_bss" is itself
> exactly at TASK_SIZE, then the BAD_ADDR() call above will catch it.
OK. Thanks for the explanation.
> > [...] But before this, I'd like to get comments from
> > the people who discussed the subject recently.
>
> Thus, I think that both 2.4.33 and 2.6.<latest> are okay without any
> further changes.
At least 2.4 needs the fix to use the correct BAD_ADDR (which is not
OK in 2.4.33 yet).
> Cheers. -ernie
Thanks Ernie,
Willy
next prev parent reply other threads:[~2006-08-21 21:23 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-20 2:04 [PATCH x7] misc fixes from 2.4.33-ow1 Solar Designer
2006-08-20 9:15 ` [PATCH] binfmt_elf.c : the BAD_ADDR macro again Willy Tarreau
2006-08-20 15:51 ` Solar Designer
2006-08-20 16:23 ` Willy Tarreau
2006-08-21 20:35 ` Ernie Petrides
2006-08-21 21:11 ` Willy Tarreau [this message]
2006-08-21 23:36 ` Ernie Petrides
2006-08-22 3:07 ` printk()s of user-supplied strings (Re: [PATCH] binfmt_elf.c : the BAD_ADDR macro again) Solar Designer
2006-08-22 20:23 ` Ernie Petrides
2006-08-22 20:34 ` printk()s of user-supplied strings Willy Tarreau
2006-08-24 16:44 ` printk()s of user-supplied strings (Re: [PATCH] binfmt_elf.c : the BAD_ADDR macro again) Solar Designer
2006-08-24 16:46 ` Willy Tarreau
2006-08-26 2:29 ` Solar Designer
2006-08-26 8:22 ` Willy Tarreau
2006-08-26 23:13 ` Solar Designer
2006-08-27 20:04 ` printk()s of user-supplied strings Willy Tarreau
2006-08-28 1:52 ` Solar Designer
1970-01-01 0:16 ` Pavel Machek
2006-08-28 8:02 ` Willy Tarreau
2006-08-28 11:17 ` Krzysztof Halasa
2006-08-30 6:15 ` Willy Tarreau
2006-08-28 17:35 ` Valdis.Kletnieks
2006-08-22 4:36 ` [PATCH] binfmt_elf.c : the BAD_ADDR macro again Willy Tarreau
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=20060821211104.GA7790@1wt.eu \
--to=w@1wt.eu \
--cc=76306.1226@compuserve.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=petrides@redhat.com \
--cc=solar@openwall.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.