Skip to contentSkip to conversation

arch/ia64/ia32/binfmt_elf32.c: elf32_map() broken ia64 build

DISCUSSION Paul Jackson 4 participants 11 messages Apr 27, 2004 – May 3, 2004

Subsystems (8)
Memory management VFS MIPS MM core +4 more subsystems
lore
Share & tools
lore
#0 lore raw

Not sure how (no lkml thread that I can see), but it seems from Andrew's broken out patch "bssprot.patch" in 2.6.6-rc2-mm2 that John Reiser and/or others on the To list above conspired to break the build of arch/ia64/ia32/binfmt_elf32.c: elf32_map().

They added a patch that amongst other things, did:

- elf_map(): new parameter total_size allows for holes between PT_LOAD; in fs/binfmt_elf.c, arch/x86_64/ia32/ia32_binfmt.c, arch/s390/kernel/ binfmt_elf32.c.

but they didn't change (note elf32_map is just elf_map, via a #define) this:

===== arch/ia64/ia32/binfmt_elf32.c 1.22 vs edited =====
223c223
< elf32_map (struct file *filep, unsigned long addr, struct elf_phdr *eppnt, int prot, int type)
---

Quoted 1 line

elf32_map (struct file *filep, unsigned long addr, struct elf_phdr const *eppnt, int prot, int type, unsigned long total_size)

If I make the above function signature change, I can at least recompile arch ia64 with CONFIG_IA32_SUPPORT enabled. But I doubt that this is ideal - as it is making no use of the new 'total_size' parameter.

Would someone care to recommend a proper fix?

Signature · 3 lines
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <[email protected]> 1.650.933.1373
#1 lore raw
Quoted 4 lines · Paul Jackson

Not sure how (no lkml thread that I can see), but it seems from Andrew's broken out patch "bssprot.patch" in 2.6.6-rc2-mm2 that John Reiser and/or others on the To list above conspired to break the build of arch/ia64/ia32/binfmt_elf32.c: elf32_map().

There was no conspiracy. The patch was compiled and linked on three archs, and ia64 was not one of them. The #define of elf32_map contributed to the obfuscation.

Quoted 1 line

Would someone care to recommend a proper fix?

A proper fix might require help from an ia64 maintainer to define macros IA32_ELF_PAGESTART, IA32_ELF_PAGEALIGN, IA32_ELF_PAGEOFFSET and will require ia32_do_munmap(). Below is partial progress, "completing the parallelogram" from fs/binfmt_elf.c via arch/x86_64/ia32/ia32_binfmt.c and arch/s390/kernel/binfmt_elf32.c. This patch requires an ia32_do_munmap(). Until then, Paul's change is sufficient, and loses no functionality except when PT_LOADs from the same file designate non-adjacent regions, which was part of the reason for the bssprot* patch(es) anyway.

When applied after 2.6.6-rc2-mm2, this compiles with warning (no prototype for ia32_do_munmap), does not link (ia32_do_munmap is undefined), and has not been executed.

arch/ia64/ia32/binfmt_elf32.c renamed from arch/ia64/ia32/binfmt_elf32.c.orig +27 -4
@@ -220,10 +220,33 @@
 }
 
 static unsigned long
-elf32_map (struct file *filep, unsigned long addr, struct elf_phdr *eppnt, int prot, int type)
+elf32_map (struct file *filep, unsigned long addr, struct elf_phdr const *eppnt,
+	 int prot, int type, unsigned long total_size)
 {
-	unsigned long pgoff = (eppnt->p_vaddr) & ~IA32_PAGE_MASK;
+		/* IA32_ELF_PAGEOFFSET ? */
+	unsigned long const pgoff = eppnt->p_vaddr & ~IA32_PAGE_MASK;
 
-	return ia32_do_mmap(filep, (addr & IA32_PAGE_MASK), eppnt->p_filesz + pgoff, prot, type,
-			    eppnt->p_offset - pgoff);
+	unsigned long size = eppnt->p_filesz + pgoff;
+	unsigned long off  = eppnt->p_offset - pgoff;
+
+	addr = addr & IA32_PAGE_MASK;  /* IA32_ELF_PAGESTART ? */
+	size = IA32_PAGE_ALIGN(size);  /* IA32_ELF_PAGEALIGN ? */
+
+	/*
+	 * total_size is the size of the ELF (interpreter) image.
+	 * The _first_ mmap needs to know the full size, otherwise
+	 * randomization might put this image into an overlapping
+	 * position with the ELF binary image. (since size < total_size)
+	 * So we first map the 'big' image - and unmap the remainder at
+	 * the end. (which unmap is needed for ELF images with holes.)
+	 */
+	if (total_size) {
+		unsigned long map_addr;
+		total_size = IA32_PAGE_ALIGN(total_size);  /* IA32_ELF_PAGEALIGN ? */
+		map_addr = ia32_do_mmap(filep, addr, total_size, prot, type, off);
+		if (!BAD_ADDR(map_addr))
+			ia32_do_munmap(current->mm, map_addr+size, total_size-size);
+		return map_addr;
+	} else
+		return ia32_do_mmap(filep, addr, size, prot, type, off);
 }
#2 lore raw

Thanks for the progress, John.

(Yes - I realize there was no conspiracy - I was speaking tongue in cheek ;).

Signature · 3 lines
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <[email protected]> 1.650.933.1373
#3 lore raw

Re: arch/ia64/ia32/binfmt_elf32.c: elf32_map() broken ia64 build _and_ boot

In reply to Paul Jackson

It's worse than I realized when I started this lkml thread (now adding linux-ia64 to cc list because I likely need ia64 maintainers assistance).

Not only don't the bssprot patches in Andrew's 2.6.6-rc2-mm2 not build, they don't boot on SGI's SN2 ia64 with sn2_defconfig. If I remove these 4 bssprot patches, then 2.6.6-rc2-mm2 builds (with the easy build fixes already understood earlier this week) and boots on SN2 ia64 with sn2_defconfig.

The 4 patches in question are named in Andrews 2.6.6-rc2-mm2 series file:

bssprot.patch
bssprot-sparc-fix.patch
bssprot-cleanup.patch
bssprot-more-fixes.patch

If I apply the cheap bssprot fix, changing the signature of the function elf32_map() in arch/ia64/ia32/binfmt_elf32.c as noted earlier in this lkml thread, then yes I can build it, including these patches, for sn2_defconfig.

But trying to boot the resulting kernel on an SGI SN2 system fails. The boot successfully prints out:

Freeing unused kernel memory: 336kB freed

but freezes prior to displaying the next line expected:

INIT: version 2.85 booting

I have to reset instead at this point.

On this system the program /sbin/init is the following type:

/sbin/init: ELF 64-bit LSB executable, IA-64, version 1 (SYSV), for GNU/Linux 2.4.0, dynamically linked (uses shared libs), stripped

JFReiser posted a few days ago on this lkml thread a partial analysis of what would be required to complete this bssprot patch for ia64.

Now the job is a little bigger - not only complete the patch (required to fix some bss protections that matter at least to Wine, but also get it to boot again, on SN2 hardware, probably on white box ia64 hardware as well.

This is not something I can do in a reasonable time, and I do not have the liberty of taking an unreasonable time for this.

... seeking asistance ... who might be able to assist further here?

Signature · 3 lines
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <[email protected]> 1.650.933.1373
#4 lore raw

Re: arch/ia64/ia32/binfmt_elf32.c: elf32_map() broken ia64 build _and_ boot

Quoted 5 lines · Paul Jackson

Not only don't the bssprot patches in Andrew's 2.6.6-rc2-mm2 not build, they don't boot on SGI's SN2 ia64 with sn2_defconfig. If I remove these 4 bssprot patches, then 2.6.6-rc2-mm2 builds (with the easy build fixes already understood earlier this week) and boots on SN2 ia64 with sn2_defconfig.

[snip]

Quoted 7 lines

But trying to boot the resulting kernel on an SGI SN2 system fails. The boot successfully prints out:

Freeing unused kernel memory: 336kB freed

but freezes prior to displaying the next line expected:

Quoted 8 lines

INIT: version 2.85 booting

I have to reset instead at this point.

On this system the program /sbin/init is the following type:

/sbin/init: ELF 64-bit LSB executable, IA-64, version 1 (SYSV), for GNU/Linux 2.4.0, dynamically linked (uses shared libs), stripped

This indicates a problem with the very first execve() and/or its shared libraries. It is likely that printk() of the arguments and results to elf_map() and load_elf_interp(), both in fs/binfmt_elf.c, will aid in finding the problem. This I would do, if I had hardware.

Are there any reports, either success or failure, for any other 64-bit architecture?

#5 lore raw

Re: arch/ia64/ia32/binfmt_elf32.c: elf32_map() broken ia64 build _and_ boot

Quoted 11 lines · John Reiser
Quoted 3 lines

/sbin/init: ELF 64-bit LSB executable, IA-64, version 1 (SYSV), for GNU/Linux 2.4.0, dynamically linked (uses shared libs), stripped

This indicates a problem with the very first execve() and/or its shared libraries. It is likely that printk() of the arguments and results to elf_map() and load_elf_interp(), both in fs/binfmt_elf.c, will aid in finding the problem. This I would do, if I had hardware.

Are there any reports, either success or failure, for any other 64-bit architecture?

It worked OK on ppc64 but I also was having ia64 problems so I dropped the patch. The final version is below.

It could do with a rethink. Is there not some simpler way of doing this?

From: John Reiser <[email protected]>

The problem:

Mike Hearn <[email protected]> reports:

Ihere is a problem in fs/binfmt_elf.c, around line 700.

When mapping a nobits PT_LOAD segment with a memsize > filesize, the kernel calls set_brk (which in turns calls do_brk) to map and clear the area, but this discards access permissons on the mapping leading to rwx protection. This causes a load failure on systems where the VM cannot reserve swap space for the segment, unless overcommit is active (on many systems it's not on by default).

It seems that this discarding of access permissions on the unlikely codepath is incorrect.

The ability to define a new (large) ELF section which isn't backed by swap space nor disk space and that will be mapped to a specific VMA range is needed by Wine to reserve the PE load area.

Currently the fact that the section is always mapped rwx despite being marked read-only in the binary prevents us from using this as a solution to the problems caused by exec-shield/prelink, meaning the only solution is to bootstrap the ELF interpreter ourselves from a statically linked binary. Clearly we'd rather not do that.

Thanks to [email protected] for bringing the matter to my attention.

[1] http://bugzilla.kernel.org/show_bug.cgi?id"55

The patch:

- do_brk(): new parameter vm_inhibit turns off permissions from VM_DATA_DEFAULT_FLAGS; default to 0. defined in mm/mmap.c, mm/nommu.c; header include/linux/mm.h; used in fs/binfmt_aout.c, fs/binfmt_elf.c. Propagate through set_brk() in fs/binfmt_aout.c and fs/binfmt_elf.c.

- total_mapping_size(): new routine computes length of minimal single interval that covers all the PT_LOAD, for ease and safety in placement when there are holes between PT_LOAD. Defined in fs/binfmt_elf.c; used there and arch/x86_64/ia32/ia32_binfmt.c, arch/s390/kernel/binfmt_elf32.c. Copied or derived from Fedora Core 2 kernel-2.6.5-1.308.src.rpm and later, whose license is GPLv2 or later.

- do_bss_pages(): do not set current->mm->brk, to allow for use by multiple .bss (local to each PT_LOAD), and by both main ELF program and ELF program interpreter; in fs/binfmt_elf.c.

- padzero(): return number of bytes that were written; in fs/binfmt_elf.c.

- calc_bss_inhibit(): new routine computes VM_* bits for .bss; fs/binfmt_elf.c.

- elf_map(): new parameter total_size allows for holes between PT_LOAD; in fs/binfmt_elf.c, arch/x86_64/ia32/ia32_binfmt.c, arch/s390/kernel/ binfmt_elf32.c.

- load_elf_binary(): create a local .bss for each PT_LOAD when .p_memsz > .p_filesz, and honor the protection in .p_flags, using new parameter to do_brk(). Set current->mm->brk. In fs/binfmt_elf.c.

- load_elf_interp(): handle local .bss similar to load_elf_binary(). In fs/binfmt_elf.c.

---

 25-akpm/arch/ia64/ia32/binfmt_elf32.c       |    3 
 25-akpm/arch/ia64/kernel/sys_ia64.c         |    2 
 25-akpm/arch/mips/kernel/irixelf.c          |    8 -
 25-akpm/arch/mips/kernel/sysirix.c          |    2 
 25-akpm/arch/s390/kernel/binfmt_elf32.c     |   21 ++
 25-akpm/arch/sparc/kernel/sys_sunos.c       |    2 
 25-akpm/arch/sparc64/kernel/binfmt_aout32.c |   14 +
 25-akpm/arch/sparc64/kernel/sys_sunos32.c   |    2 
 25-akpm/arch/x86_64/ia32/ia32_aout.c        |   14 +
 25-akpm/arch/x86_64/ia32/ia32_binfmt.c      |   20 +-
 25-akpm/fs/binfmt_aout.c                    |   23 +-
 25-akpm/fs/binfmt_elf.c                     |  224 +++++++++++++++-------------
 25-akpm/include/linux/mm.h                  |    2 
 25-akpm/mm/mmap.c                           |    7 
 25-akpm/mm/nommu.c                          |    2 
 15 files changed, 201 insertions(+), 145 deletions(-)
arch/s390/kernel/binfmt_elf32.c renamed from arch/s390/kernel/binfmt_elf32.c~bssprot +16 -5
diff -puN arch/s390/kernel/binfmt_elf32.c~bssprot arch/s390/kernel/binfmt_elf32.c
@@ -189,18 +189,29 @@ jiffies_to_compat_timeval(unsigned long 
 #include "../../../fs/binfmt_elf.c"
 
 static unsigned long
-elf_map32 (struct file *filep, unsigned long addr, struct elf_phdr *eppnt, int prot, int type)
+elf_map32 (struct file *filep, unsigned long addr, struct elf_phdr const *eppnt, int prot, int type, unsigned long total_size)
 {
 	unsigned long map_addr;
+	unsigned long size = eppnt->p_filesz + ELF_PAGEOFFSET(eppnt->p_vaddr);
+	unsigned long off = eppnt->p_offset - ELF_PAGEOFFSET(eppnt->p_vaddr);
+
+	addr = ELF_PAGESTART(addr);
+	size = ELF_PAGEALIGN(size);
 
 	if (!addr) 
 		addr = TASK_UNMAPPED_BASE;
 
 	down_write(&current->mm->mmap_sem);
-	map_addr = do_mmap(filep, ELF_PAGESTART(addr),
-			   eppnt->p_filesz + ELF_PAGEOFFSET(eppnt->p_vaddr),
-			   prot, type,
-			   eppnt->p_offset - ELF_PAGEOFFSET(eppnt->p_vaddr));
+
+	/* total_size allows for holes between PT_LOAD */
+	if (total_size) {
+		total_size = ELF_PAGEALIGN(total_size);
+		map_addr = do_mmap(filep, addr, total_size, prot, type, off);
+		if (!BAD_ADDR(map_addr))
+			do_munmap(current->mm, map_addr+size, total_size-size);
+	} else
+		map_addr = do_mmap(filep, addr, size, prot, type, off);
+
 	up_write(&current->mm->mmap_sem);
 	return(map_addr);
 }
arch/x86_64/ia32/ia32_aout.c renamed from arch/x86_64/ia32/ia32_aout.c~bssprot +9 -5
diff -puN arch/x86_64/ia32/ia32_aout.c~bssprot arch/x86_64/ia32/ia32_aout.c
@@ -113,7 +113,7 @@ static void set_brk(unsigned long start,
 	end = PAGE_ALIGN(end);
 	if (end <= start)
 		return;
-	do_brk(start, end - start);
+	do_brk(start, end - start, VM_DATA_DEFAULT_FLAGS);
 }
 
 #if CORE_DUMP
@@ -322,7 +322,8 @@ static int load_aout_binary(struct linux
 		pos = 32;
 		map_size = ex.a_text+ex.a_data;
 
-		error = do_brk(text_addr & PAGE_MASK, map_size);
+		error = do_brk(text_addr&PAGE_MASK, map_size,
+					VM_DATA_DEFAULT_FLAGS);
 		if (error != (text_addr & PAGE_MASK)) {
 			send_sig(SIGKILL, current, 0);
 			return error;
@@ -358,7 +359,8 @@ static int load_aout_binary(struct linux
 
 		if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) {
 			loff_t pos = fd_offset;
-			do_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
+			do_brk(N_TXTADDR(ex), ex.a_text+ex.a_data,
+					VM_DATA_DEFAULT_FLAGS);
 			bprm->file->f_op->read(bprm->file,(char *)N_TXTADDR(ex),
 					ex.a_text+ex.a_data, &pos);
 			flush_icache_range((unsigned long) N_TXTADDR(ex),
@@ -467,7 +469,8 @@ static int load_aout_library(struct file
 		}
 #endif
 
-		do_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
+		do_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss,
+				VM_DATA_DEFAULT_FLAGS);
 		
 		file->f_op->read(file, (char *)start_addr,
 			ex.a_text + ex.a_data, &pos);
@@ -491,7 +494,8 @@ static int load_aout_library(struct file
 	len = PAGE_ALIGN(ex.a_text + ex.a_data);
 	bss = ex.a_text + ex.a_data + ex.a_bss;
 	if (bss > len) {
-		error = do_brk(start_addr + len, bss - len);
+		error = do_brk(start_addr + len, bss - len,
+					VM_DATA_DEFAULT_FLAGS);
 		retval = error;
 		if (error != start_addr + len)
 			goto out;
arch/x86_64/ia32/ia32_binfmt.c renamed from arch/x86_64/ia32/ia32_binfmt.c~bssprot +15 -5
diff -puN arch/x86_64/ia32/ia32_binfmt.c~bssprot arch/x86_64/ia32/ia32_binfmt.c
@@ -385,19 +385,29 @@ int setup_arg_pages(struct linux_binprm 
 }
 
 static unsigned long
-elf32_map (struct file *filep, unsigned long addr, struct elf_phdr *eppnt, int prot, int type)
+elf32_map (struct file *filep, unsigned long addr, struct elf_phdr const *eppnt, int prot, int type, unsigned long total_size)
 {
 	unsigned long map_addr;
 	struct task_struct *me = current; 
+	unsigned long size = eppnt->p_filesz + ELF_PAGEOFFSET(eppnt->p_vaddr);
+	unsigned long off = eppnt->p_offset - ELF_PAGEOFFSET(eppnt->p_vaddr);
 
 	if (prot & PROT_READ) 
 		prot |= vm_force_exec32;
 
+	addr = ELF_PAGESTART(addr);
+	size = ELF_PAGEALIGN(size);
+
 	down_write(&me->mm->mmap_sem);
-	map_addr = do_mmap(filep, ELF_PAGESTART(addr),
-			   eppnt->p_filesz + ELF_PAGEOFFSET(eppnt->p_vaddr), prot, 
-			   type,
-			   eppnt->p_offset - ELF_PAGEOFFSET(eppnt->p_vaddr));
+
+	/* total_size allows for holes between PT_LOAD */
+	if (total_size) {
+		total_size = ELF_PAGEALIGN(total_size);
+		map_addr = do_mmap(filep, addr, total_size, prot, type, off);
+		if (!BAD_ADDR(map_addr))
+			do_munmap(me->mm, map_addr+size, total_size-size);
+	} else
+		map_addr = do_mmap(filep, addr, size, prot, type, off);
 	up_write(&me->mm->mmap_sem);
 	return(map_addr);
 }
fs/binfmt_aout.c renamed from fs/binfmt_aout.c~bssprot +14 -9
diff -puN fs/binfmt_aout.c~bssprot fs/binfmt_aout.c
@@ -43,13 +43,13 @@ static struct linux_binfmt aout_format  	.min_coredump	= PAGE_SIZE
 };
 
-static void set_brk(unsigned long start, unsigned long end)
+static void set_brk(unsigned long start, unsigned long end, unsigned flags)
 {
 	start = PAGE_ALIGN(start);
 	end = PAGE_ALIGN(end);
 	if (end <= start)
 		return;
-	do_brk(start, end - start);
+	do_brk(start, end - start, flags);
 }
 
 /*
@@ -317,10 +317,10 @@ static int load_aout_binary(struct linux
 		loff_t pos = fd_offset;
 		/* Fuck me plenty... */
 		/* <AOL></AOL> */
-		error = do_brk(N_TXTADDR(ex), ex.a_text);
+		error = do_brk(N_TXTADDR(ex), ex.a_text, VM_DATA_DEFAULT_FLAGS);
 		bprm->file->f_op->read(bprm->file, (char *) N_TXTADDR(ex),
 			  ex.a_text, &pos);
-		error = do_brk(N_DATADDR(ex), ex.a_data);
+		error = do_brk(N_DATADDR(ex), ex.a_data, VM_DATA_DEFAULT_FLAGS);
 		bprm->file->f_op->read(bprm->file, (char *) N_DATADDR(ex),
 			  ex.a_data, &pos);
 		goto beyond_if;
@@ -341,7 +341,8 @@ static int load_aout_binary(struct linux
 		map_size = ex.a_text+ex.a_data;
 #endif
 
-		error = do_brk(text_addr & PAGE_MASK, map_size);
+		error = do_brk(text_addr & PAGE_MASK, map_size,
+					VM_DATA_DEFAULT_FLAGS);
 		if (error != (text_addr & PAGE_MASK)) {
 			send_sig(SIGKILL, current, 0);
 			return error;
@@ -375,7 +376,8 @@ static int load_aout_binary(struct linux
 
 		if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) {
 			loff_t pos = fd_offset;
-			do_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
+			do_brk(N_TXTADDR(ex), ex.a_text+ex.a_data,
+						VM_DATA_DEFAULT_FLAGS);
 			bprm->file->f_op->read(bprm->file,(char *)N_TXTADDR(ex),
 					ex.a_text+ex.a_data, &pos);
 			flush_icache_range((unsigned long) N_TXTADDR(ex),
@@ -410,7 +412,8 @@ static int load_aout_binary(struct linux
 beyond_if:
 	set_binfmt(&aout_format);
 
-	set_brk(current->mm->start_brk, current->mm->brk);
+	set_brk(current->mm->start_brk, current->mm->brk,
+			VM_DATA_DEFAULT_FLAGS);
 
 	retval = setup_arg_pages(bprm, EXSTACK_DEFAULT);
 	if (retval < 0) { 
@@ -476,7 +479,8 @@ static int load_aout_library(struct file
 			error_time = jiffies;
 		}
 
-		do_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
+		do_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss,
+				VM_DATA_DEFAULT_FLAGS);
 		
 		file->f_op->read(file, (char *)start_addr,
 			ex.a_text + ex.a_data, &pos);
@@ -500,7 +504,8 @@ static int load_aout_library(struct file
 	len = PAGE_ALIGN(ex.a_text + ex.a_data);
 	bss = ex.a_text + ex.a_data + ex.a_bss;
 	if (bss > len) {
-		error = do_brk(start_addr + len, bss - len);
+		error = do_brk(start_addr + len, bss - len,
+				VM_DATA_DEFAULT_FLAGS);
 		retval = error;
 		if (error != start_addr + len)
 			goto out;
fs/binfmt_elf.c renamed from fs/binfmt_elf.c~bssprot +124 -100

391 lines not on this page · raw message

include/linux/mm.h renamed from include/linux/mm.h~bssprot +1 -1
diff -puN include/linux/mm.h~bssprot include/linux/mm.h
@@ -599,7 +599,7 @@ out:
 
 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
 
-extern unsigned long do_brk(unsigned long, unsigned long);
+extern unsigned long do_brk(unsigned long, unsigned long, unsigned int);
 
 static inline void
 __vma_unlink(struct mm_struct *mm, struct vm_area_struct *vma,
mm/mmap.c renamed from mm/mmap.c~bssprot +3 -4
diff -puN mm/mmap.c~bssprot mm/mmap.c
@@ -132,7 +132,7 @@ asmlinkage unsigned long sys_brk(unsigne
 		goto out;
 
 	/* Ok, looks good - let it rip. */
-	if (do_brk(oldbrk, newbrk-oldbrk) != oldbrk)
+	if (do_brk(oldbrk, newbrk-oldbrk, VM_DATA_DEFAULT_FLAGS) != oldbrk)
 		goto out;
 set_brk:
 	mm->brk = brk;
@@ -1378,7 +1378,7 @@ asmlinkage long sys_munmap(unsigned long
  *  anonymous maps.  eventually we may be able to do some
  *  brk-specific accounting here.
  */
-unsigned long do_brk(unsigned long addr, unsigned long len)
+unsigned long do_brk(unsigned long addr, unsigned long len, unsigned _flags)
 {
 	struct mm_struct * mm = current->mm;
 	struct vm_area_struct * vma, * prev;
@@ -1424,7 +1424,7 @@ unsigned long do_brk(unsigned long addr,
 	if (security_vm_enough_memory(len >> PAGE_SHIFT))
 		return -ENOMEM;
 
-	flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
+	flags = _flags | VM_ACCOUNT | mm->def_flags;
 
 	/* Can we just expand an old anonymous mapping? */
 	if (rb_parent && vma_merge(mm, prev, rb_parent, addr, addr + len,
@@ -1459,7 +1459,6 @@ out:
 	}
 	return addr;
 }
-
 EXPORT_SYMBOL(do_brk);
 
 /* Release all mmaps. */
mm/nommu.c renamed from mm/nommu.c~bssprot +1 -1
diff -puN mm/nommu.c~bssprot mm/nommu.c
@@ -535,7 +535,7 @@ asmlinkage long sys_munmap(unsigned long
 	return ret;
 }
 
-unsigned long do_brk(unsigned long addr, unsigned long len)
+unsigned long do_brk(unsigned long addr, unsigned long len, unsigned flags)
 {
 	return -ENOMEM;
 }
arch/sparc64/kernel/sys_sunos32.c renamed from arch/sparc64/kernel/sys_sunos32.c~bssprot +1 -1
diff -puN arch/sparc64/kernel/sys_sunos32.c~bssprot arch/sparc64/kernel/sys_sunos32.c
@@ -173,7 +173,7 @@ asmlinkage int sunos_brk(u32 baddr)
 		goto out;
 	/* Ok, we have probably got enough memory - let it rip. */
 	current->mm->brk = brk;
-	do_brk(oldbrk, newbrk-oldbrk);
+	do_brk(oldbrk, newbrk-oldbrk, VM_DATA_DEFAULT_FLAGS);
 	retval = 0;
 out:
 	up_write(&current->mm->mmap_sem);
arch/ia64/ia32/binfmt_elf32.c renamed from arch/ia64/ia32/binfmt_elf32.c~bssprot +2 -1
diff -puN arch/ia64/ia32/binfmt_elf32.c~bssprot arch/ia64/ia32/binfmt_elf32.c
@@ -220,7 +220,8 @@ elf32_set_personality (void)
 }
 
 static unsigned long
-elf32_map (struct file *filep, unsigned long addr, struct elf_phdr *eppnt, int prot, int type)
+elf32_map (struct file *filep, unsigned long addr, struct elf_phdr const *eppnt,
+		int prot, int type, unsigned long total_size)
 {
 	unsigned long pgoff = (eppnt->p_vaddr) & ~IA32_PAGE_MASK;
 
arch/ia64/kernel/sys_ia64.c renamed from arch/ia64/kernel/sys_ia64.c~bssprot +1 -1
diff -puN arch/ia64/kernel/sys_ia64.c~bssprot arch/ia64/kernel/sys_ia64.c
@@ -147,7 +147,7 @@ ia64_brk (unsigned long brk)
 		goto out;
 
 	/* Ok, looks good - let it rip. */
-	if (do_brk(oldbrk, newbrk-oldbrk) != oldbrk)
+	if (do_brk(oldbrk, newbrk-oldbrk, VM_DATA_DEFAULT_FLAGS) != oldbrk)
 		goto out;
 set_brk:
 	mm->brk = brk;
arch/mips/kernel/irixelf.c renamed from arch/mips/kernel/irixelf.c~bssprot +4 -4
diff -puN arch/mips/kernel/irixelf.c~bssprot arch/mips/kernel/irixelf.c
@@ -127,7 +127,7 @@ static void set_brk(unsigned long start,
 	end = PAGE_ALIGN(end);
 	if (end <= start)
 		return;
-	do_brk(start, end - start);
+	do_brk(start, end - start, VM_DATA_DEFAULT_FLAGS);
 }
 
 
@@ -376,7 +376,7 @@ static unsigned int load_irix_interp(str
 
 	/* Map the last of the bss segment */
 	if (last_bss > len) {
-		do_brk(len, (last_bss - len));
+		do_brk(len, (last_bss - len), VM_DATA_DEFAULT_FLAGS);
 	}
 	kfree(elf_phdata);
 
@@ -564,7 +564,7 @@ void irix_map_prda_page (void)
 	unsigned long v;
 	struct prda *pp;
 
-	v =  do_brk (PRDA_ADDRESS, PAGE_SIZE);
+	v =  do_brk(PRDA_ADDRESS, PAGE_SIZE, VM_DATA_DEFAULT_FLAGS);
 
 	if (v < 0)
 		return;
@@ -856,7 +856,7 @@ static int load_irix_library(struct file
 	len = (elf_phdata->p_filesz + elf_phdata->p_vaddr+ 0xfff) & 0xfffff000;
 	bss = elf_phdata->p_memsz + elf_phdata->p_vaddr;
 	if (bss > len)
-	  do_brk(len, bss-len);
+		do_brk(len, bss-len, VM_DATA_DEFAULT_FLAGS);
 	kfree(elf_phdata);
 	return 0;
 }
arch/mips/kernel/sysirix.c renamed from arch/mips/kernel/sysirix.c~bssprot +1 -1
diff -puN arch/mips/kernel/sysirix.c~bssprot arch/mips/kernel/sysirix.c
@@ -586,7 +586,7 @@ asmlinkage int irix_brk(unsigned long br
 	 * Ok, looks good - let it rip.
 	 */
 	mm->brk = brk;
-	do_brk(oldbrk, newbrk-oldbrk);
+	do_brk(oldbrk, newbrk-oldbrk, VM_DATA_DEFAULT_FLAGS);
 	ret = 0;
 
 out:
arch/sparc64/kernel/binfmt_aout32.c renamed from arch/sparc64/kernel/binfmt_aout32.c~bssprot +8 -6
diff -puN arch/sparc64/kernel/binfmt_aout32.c~bssprot arch/sparc64/kernel/binfmt_aout32.c
@@ -49,7 +49,7 @@ static void set_brk(unsigned long start,
 	end = PAGE_ALIGN(end);
 	if (end <= start)
 		return;
-	do_brk(start, end - start);
+	do_brk(start, end - start, VM_DATA_DEFAULT_FLAGS);
 }
 
 /*
@@ -246,10 +246,10 @@ static int load_aout32_binary(struct lin
 	if (N_MAGIC(ex) = NMAGIC) {
 		loff_t pos = fd_offset;
 		/* Fuck me plenty... */
-		error = do_brk(N_TXTADDR(ex), ex.a_text);
+		error = do_brk(N_TXTADDR(ex), ex.a_text, VM_DATA_DEFAULT_FLAGS);
 		bprm->file->f_op->read(bprm->file, (char *) N_TXTADDR(ex),
 			  ex.a_text, &pos);
-		error = do_brk(N_DATADDR(ex), ex.a_data);
+		error = do_brk(N_DATADDR(ex), ex.a_data, VM_DATA_DEFAULT_FLAGS);
 		bprm->file->f_op->read(bprm->file, (char *) N_DATADDR(ex),
 			  ex.a_data, &pos);
 		goto beyond_if;
@@ -258,7 +258,8 @@ static int load_aout32_binary(struct lin
 	if (N_MAGIC(ex) = OMAGIC) {
 		loff_t pos = fd_offset;
 		do_brk(N_TXTADDR(ex) & PAGE_MASK,
-			ex.a_text+ex.a_data + PAGE_SIZE - 1);
+			ex.a_text+ex.a_data + PAGE_SIZE - 1,
+			VM_DATA_DEFAULT_FLAGS);
 		bprm->file->f_op->read(bprm->file, (char *) N_TXTADDR(ex),
 			  ex.a_text+ex.a_data, &pos);
 	} else {
@@ -272,7 +273,7 @@ static int load_aout32_binary(struct lin
 
 		if (!bprm->file->f_op->mmap) {
 			loff_t pos = fd_offset;
-			do_brk(0, ex.a_text+ex.a_data);
+			do_brk(0, ex.a_text+ex.a_data, VM_DATA_DEFAULT_FLAGS);
 			bprm->file->f_op->read(bprm->file,(char *)N_TXTADDR(ex),
 				  ex.a_text+ex.a_data, &pos);
 			goto beyond_if;
@@ -388,7 +389,8 @@ static int load_aout32_library(struct fi
 	len = PAGE_ALIGN(ex.a_text + ex.a_data);
 	bss = ex.a_text + ex.a_data + ex.a_bss;
 	if (bss > len) {
-		error = do_brk(start_addr + len, bss - len);
+		error = do_brk(start_addr + len, bss - len,
+				VM_DATA_DEFAULT_FLAGS);
 		retval = error;
 		if (error != start_addr + len)
 			goto out;
arch/sparc/kernel/sys_sunos.c renamed from arch/sparc/kernel/sys_sunos.c~bssprot +1 -1
diff -puN arch/sparc/kernel/sys_sunos.c~bssprot arch/sparc/kernel/sys_sunos.c
@@ -207,7 +207,7 @@ asmlinkage int sunos_brk(unsigned long b
 	 * Ok, we have probably got enough memory - let it rip.
 	 */
 	current->mm->brk = brk;
-	do_brk(oldbrk, newbrk-oldbrk);
+	do_brk(oldbrk, newbrk-oldbrk, VM_DATA_DEFAULT_FLAGS);
 	retval = 0;
 out:
 	up_write(&current->mm->mmap_sem);

_

#6 lore raw

Re: arch/ia64/ia32/binfmt_elf32.c: elf32_map() broken ia64 build _and_ boot

In reply to John Reiser
Quoted 4 lines

This indicates a problem with the very first execve() and/or its shared libraries. It is likely that printk() of the arguments and results to elf_map() and load_elf_interp(), both in fs/binfmt_elf.c, will aid in finding the problem. This I would do, if I had hardware.

Since I see Andrew dropped the patch for the moment, I'm thinking that the ball is back in you guys court. If you end up with some patch to a well-known base (Linus rc or Andrew mm, say) that you'd like me to try out, let me know. You might want to include the printk's of args/results that you describe above, right in the patch, so I can provide more rapid and useful feedback, should whatever be this execve/sharedlib problem still persist.

Yes - I have the hardware - but I must ration my time on this patch.

Will this work for you?

Signature · 3 lines
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <[email protected]> 1.650.933.1373
#7 lore raw

Re: arch/ia64/ia32/binfmt_elf32.c: elf32_map() broken ia64 build _and_ boot

Quoted 2 lines · Paul Jackson

Since I see Andrew dropped the patch for the moment, I'm thinking that the ball is back in you guys court.

We've been able to develop a (complex) workaround for the VM layout problems in userspace by inserting a shim between the dynamic linker and the kernel. It sets up the address space correctly before the linker runs so, for now, Wine will be alright without the patch - assuming we can get the shim merged with Wine CVS of course :)

It would be nice to get the bssprot patch in though, if only because a GNU linker script would be about 100x smaller and less scary than the shim code.

thanks -mike

Signature · 2 lines
Mike Hearn <[email protected]>
Codeweavers, Inc
#8 lore raw

Re: arch/ia64/ia32/binfmt_elf32.c: elf32_map() broken ia64 build _and_ boot

Quoted 1 line

It would be nice to get the bssprot patch in though, ...

Once you've digested Andrew's query as to whether there is a simpler way to do this, and know whether it's this patch or some other that you want to push, then if you send me a patch, ideally including the printk's in fs/binfmt_elf.c that Reiser thought might facilitate debugging, then I'd be willing to apply the patch and try booting it on my ia64 SN2 hardware.

Signature · 3 lines
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <[email protected]> 1.650.933.1373
#9 lore raw

Re: arch/ia64/ia32/binfmt_elf32.c: elf32_map() broken ia64 build _and_ boot

Quoted 2 lines · Paul Jackson

Once you've digested Andrew's query as to whether there is a simpler way to do this,

I already digested it, I just don't know the answer. I'm not familiar with this part of the kernel, nor exactly what the patch is doing - just the broad strokes.

Quoted 2 lines

and know whether it's this patch or some other that you want to push,

The permissions problem is a kernel bug which should be fixed. I have no thoughts on the other changes in the patch, I didn't ask for them and don't really know what they do.

Quoted 3 lines

then if you send me a patch, ideally including the printk's in fs/binfmt_elf.c that Reiser thought might facilitate debugging, then I'd be willing to apply the patch and try booting it on my ia64 SN2 hardware.

Thanks, but I'll leave this in Johns hands. I just wanted to let you guys know that it's no longer a major problem for us as it was before, so if you have higher priorities don't worry about Wine.

thanks -mike

#10 lore raw

Re: arch/ia64/ia32/binfmt_elf32.c: elf32_map() broken ia64 build _and_ boot

Quoted 1 line

so if you have higher priorities don't worry about Wine.

Excellent - I think I can easily follow your suggestion ;).

Signature · 3 lines
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <[email protected]> 1.650.933.1373