From: Jake Moilanen <moilanen@austin.ibm.com>
To: Paul Mackerras <paulus@samba.org>
Cc: akpm@osdl.org, linuxppc64-dev@ozlabs.org,
linux-kernel@vger.kernel.org, anton@samba.org,
olof@austin.ibm.com, benh@kernel.crashing.org,
amodra@bigpond.net.au
Subject: Re: [PATCH 1/2] No-exec support for ppc64
Date: Wed, 16 Mar 2005 15:45:58 -0600 [thread overview]
Message-ID: <20050316154558.7c634a23.moilanen@austin.ibm.com> (raw)
In-Reply-To: <16951.52721.139394.592636@cargo.ozlabs.ibm.com>
On Wed, 16 Mar 2005 17:10:57 +1100
Paul Mackerras <paulus@samba.org> wrote:
> Jake Moilanen writes:
>
> > It does not work w/o the sys_mprotect. It will hang in one of the first
> > few binaries.
>
> Hmmm, what distro is this with? I just tried a kernel with the patch
> below on a SLES9 install and a Debian install and it came up and ran
> just fine in both cases.
I'm not sure that the patch you sent is actually doing protection
correctly.
To test I commented out this line:
> +#define elf_read_implies_exec(ex, have_pt_gnu_stack) (!(have_pt_gnu_stack))
and then ran a non-pt_gnu_stack binary which should have executed on a non-exec
segment, it did not segfault.
> + *
> + * Note due to the way vm flags are laid out, the bits are XWR
> */
> #define __P000 PAGE_NONE
> -#define __P001 PAGE_READONLY_X
> +#define __P001 PAGE_READONLY
> #define __P010 PAGE_COPY
> #define __P011 PAGE_COPY_X
> #define __P100 PAGE_READONLY
> #define __P101 PAGE_READONLY_X
> -#define __P110 PAGE_COPY
> +#define __P110 PAGE_COPY_X
> #define __P111 PAGE_COPY_X
I think the problem was this hunk. __P011 should be PAGE_COPY and
__P100 should be PAGE_READONLY_X.
Here is a patch ontop of the last patch you sent to fix this problem and
take another crack at doing the sys_mprotect less hackish.
Signed-off-by: Jake Moilanen <moilanen@austin.ibm.com>
---
linux-2.6.11.4-paulus-moilanen/fs/binfmt_elf.c | 18 +++++++++----
linux-2.6.11.4-paulus-moilanen/include/asm-ppc64/pgtable.h | 4 +-
2 files changed, 15 insertions(+), 7 deletions(-)
diff -puN fs/binfmt_elf.c~more-nx fs/binfmt_elf.c
--- linux-2.6.11.4-paulus/fs/binfmt_elf.c~more-nx 2005-03-16 09:35:28 -06:00
+++ linux-2.6.11.4-paulus-moilanen/fs/binfmt_elf.c 2005-03-16 11:03:15 -06:00
@@ -88,7 +88,7 @@ static struct linux_binfmt elf_format =
#define BAD_ADDR(x) ((unsigned long)(x) > TASK_SIZE)
-static int set_brk(unsigned long start, unsigned long end)
+static int set_brk(unsigned long start, unsigned long end, int prot)
{
start = ELF_PAGEALIGN(start);
end = ELF_PAGEALIGN(end);
@@ -99,6 +99,9 @@ static int set_brk(unsigned long start,
up_write(¤t->mm->mmap_sem);
if (BAD_ADDR(addr))
return addr;
+
+ sys_mprotect(start, end-start, prot);
+
}
current->mm->start_brk = current->mm->brk = end;
return 0;
@@ -529,6 +532,7 @@ static int load_elf_binary(struct linux_
struct files_struct *files;
int have_pt_gnu_stack, executable_stack = EXSTACK_DEFAULT;
unsigned long def_flags = 0;
+ int bss_prot = 0;
struct {
struct elfhdr elf_ex;
struct elfhdr interp_elf_ex;
@@ -811,7 +815,7 @@ static int load_elf_binary(struct linux_
before this one. Map anonymous pages, if needed,
and clear the area. */
retval = set_brk (elf_bss + load_bias,
- elf_brk + load_bias);
+ elf_brk + load_bias, bss_prot);
if (retval) {
send_sig(SIGKILL, current, 0);
goto out_free_dentry;
@@ -883,15 +887,19 @@ static int load_elf_binary(struct linux_
k = elf_ppnt->p_vaddr + elf_ppnt->p_filesz;
- if (k > elf_bss)
+ if (k > elf_bss) {
elf_bss = k;
+ bss_prot = elf_prot;
+ }
if ((elf_ppnt->p_flags & PF_X) && end_code < k)
end_code = k;
if (end_data < k)
end_data = k;
k = elf_ppnt->p_vaddr + elf_ppnt->p_memsz;
- if (k > elf_brk)
+ if (k > elf_brk) {
elf_brk = k;
+ bss_prot = elf_prot;
+ }
}
loc->elf_ex.e_entry += load_bias;
@@ -907,7 +915,7 @@ static int load_elf_binary(struct linux_
* mapping in the interpreter, to make sure it doesn't wind
* up getting placed where the bss needs to go.
*/
- retval = set_brk(elf_bss, elf_brk);
+ retval = set_brk(elf_bss, elf_brk, bss_prot);
if (retval) {
send_sig(SIGKILL, current, 0);
goto out_free_dentry;
diff -puN include/asm-ppc64/pgtable.h~more-nx include/asm-ppc64/pgtable.h
--- linux-2.6.11.4-paulus/include/asm-ppc64/pgtable.h~more-nx 2005-03-16 09:35:44 -06:00
+++ linux-2.6.11.4-paulus-moilanen/include/asm-ppc64/pgtable.h 2005-03-16 09:35:53 -06:00
@@ -137,8 +137,8 @@
#define __P000 PAGE_NONE
#define __P001 PAGE_READONLY
#define __P010 PAGE_COPY
-#define __P011 PAGE_COPY_X
-#define __P100 PAGE_READONLY
+#define __P011 PAGE_COPY
+#define __P100 PAGE_READONLY_X
#define __P101 PAGE_READONLY_X
#define __P110 PAGE_COPY_X
#define __P111 PAGE_COPY_X
_
next prev parent reply other threads:[~2005-03-16 21:59 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-03-08 22:59 [PATCH 0/2] " Jake Moilanen
2005-03-08 23:08 ` [PATCH 1/2] " Jake Moilanen
2005-03-10 3:22 ` Olof Johansson
2005-03-10 22:25 ` Jake Moilanen
2005-03-14 10:13 ` Paul Mackerras
2005-03-14 21:51 ` Jake Moilanen
2005-03-14 22:18 ` Paul Mackerras
2005-03-15 21:51 ` Jake Moilanen
2005-03-15 22:48 ` Alan Modra
2005-03-15 23:17 ` Jake Moilanen
2005-03-16 6:10 ` Paul Mackerras
2005-03-16 21:45 ` Jake Moilanen [this message]
2005-03-08 23:13 ` [PATCH 2/2] " Jake Moilanen
2005-03-09 3:02 ` Benjamin Herrenschmidt
2005-03-10 3:25 ` Olof Johansson
2005-03-10 7:15 ` Benjamin Herrenschmidt
2005-03-10 22:27 ` Jake Moilanen
2005-03-10 22:44 ` Benjamin Herrenschmidt
2005-03-11 14:01 ` Jake Moilanen
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=20050316154558.7c634a23.moilanen@austin.ibm.com \
--to=moilanen@austin.ibm.com \
--cc=akpm@osdl.org \
--cc=amodra@bigpond.net.au \
--cc=anton@samba.org \
--cc=benh@kernel.crashing.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc64-dev@ozlabs.org \
--cc=olof@austin.ibm.com \
--cc=paulus@samba.org \
/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®