Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Richard Henderson <richard@atheist.tamu.edu>
Subject: Re: strip 2.6 breaks images
Date: Wed, 15 May 1996 11:13:34 -0500 (CDT)	[thread overview]
Message-ID: <m0uJjCg-0001tlC@atheist.tamu.edu> (raw)
In-Reply-To: <9605150638.AA11132@nova.tat.physik.uni-tuebingen.de>

> > I have never seen this with any version of the binutils, which 
> > makes me wonder if there is some libbfd compatibility problem
> > as with the insmod problem that was reported recently.
> 
> can't you reproduce this with my very small idle program ?

Ack.  You were right.

There was a problem, but in the kernel rather than the binutils.
The kernel was ignoring the file offset information so kindly
provided to it in the ECOFF section headers.

Following is a patch that fixes the problem.

WARNING: I found while testing this patch that my /sbin/getty from
RedHat 2.1 was actually broken, that is, it contained inconsistant
offset information.  The one from 3.0.3 is Righteous.

r~

Index: binfmt_aout.c
===================================================================
RCS file: /home/richard/Repository/linux/linux/fs/binfmt_aout.c,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 binfmt_aout.c
--- binfmt_aout.c	1996/04/28 06:19:06	1.1.1.2
+++ binfmt_aout.c	1996/05/15 15:43:12
@@ -261,8 +261,9 @@
 	int fd;
 	unsigned long error;
 	unsigned long p = bprm->p;
-	unsigned long fd_offset;
 	unsigned long rlim;
+	unsigned long text_offset, text_addr;
+	unsigned long data_offset, data_addr, bss_addr;
 
 	ex = *((struct exec *) bprm->buf);		/* exec-header */
 	if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != OMAGIC && 
@@ -273,20 +274,62 @@
 	}
 
 	current->personality = PER_LINUX;
-	fd_offset = N_TXTOFF(ex);
+
+#ifdef __alpha__
+	text_addr = N_TXTADDR(ex);
+	data_addr = N_DATADDR(ex);
+	bss_addr = N_BSSADDR(ex);
+
+	/* Read the ECOFF section headers to find the actual file 
+	   positions of the text and data segments.  */
+	{
+		struct scnhdr scns[ex.fh.f_nscns];
+		unsigned long i;
+
+		read_exec(bprm->inode, sizeof ex, (char*)scns, sizeof scns, 1);
+
+		text_offset = data_offset = ~0UL;
+
+#define SEC(a,b,c,d,e) a|(b<<8)|(c<<16)|(d<<24)|((unsigned long)e<<32)
+		for (i = 0; i < ex.fh.f_nscns; ++i)
+			switch (*(unsigned long *)scns[i].s_name)
+			{
+			    case SEC('.','t','e','x','t'):
+				text_offset = (scns[i].s_scnptr -
+					       (scns[i].s_vaddr & 0xfff));
+				break;
+			    case SEC('.','d','a','t','a'):
+			        data_offset = (scns[i].s_scnptr -
+					       (scns[i].s_vaddr & 0xfff));
+				break;
+			}
+#undef SEC
+
+		i = bprm->inode->i_size;
+		if (text_offset >= i || text_offset+ex.a_text > i ||
+		    data_offset >= i || data_offset+ex.a_data > i)
+			return -ENOEXEC;
+	}
+#else
+	text_addr = N_TXTADDR(ex);
+	data_addr = N_DATADDR(ex);
+	bss_addr = N_BSSADDR(ex);
+	text_offset = N_TXTOFF(ex);
+	data_offset = text_offset + ex.a_text;
 
 #ifdef __i386__
-	if (N_MAGIC(ex) == ZMAGIC && fd_offset != BLOCK_SIZE) {
+	if (N_MAGIC(ex) == ZMAGIC && text_offset != BLOCK_SIZE) {
 		printk(KERN_NOTICE "N_TXTOFF != BLOCK_SIZE. See a.out.h.\n");
 		return -ENOEXEC;
 	}
 
 	if (N_MAGIC(ex) == ZMAGIC && ex.a_text &&
-	    (fd_offset < bprm->inode->i_sb->s_blocksize)) {
+	    (text_offset < bprm->inode->i_sb->s_blocksize)) {
 		printk(KERN_NOTICE "N_TXTOFF < BLOCK_SIZE. Please convert binary.\n");
 		return -ENOEXEC;
 	}
-#endif
+#endif /* i386 */
+#endif /* alpha */
 
 	/* Check initial limits. This avoids letting people circumvent
 	 * size limits imposed on them by creating programs with large
@@ -302,11 +345,11 @@
 	flush_old_exec(bprm);
 
 	current->mm->end_code = ex.a_text +
-		(current->mm->start_code = N_TXTADDR(ex));
+		(current->mm->start_code = text_addr);
 	current->mm->end_data = ex.a_data +
-		(current->mm->start_data = N_DATADDR(ex));
+		(current->mm->start_data = data_addr);
 	current->mm->brk = ex.a_bss +
-		(current->mm->start_brk = N_BSSADDR(ex));
+		(current->mm->start_brk = bss_addr);
 
 	current->mm->rss = 0;
 	current->mm->mmap = NULL;
@@ -314,13 +357,16 @@
 	current->sgid = current->egid = current->fsgid = bprm->e_gid;
  	current->flags &= ~PF_FORKNOEXEC;
 	if (N_MAGIC(ex) == OMAGIC) {
+load_unmapped:
 #ifdef __alpha__
-		do_mmap(NULL, N_TXTADDR(ex) & PAGE_MASK,
-			ex.a_text+ex.a_data + PAGE_SIZE - 1,
+		do_mmap(NULL, text_addr & PAGE_MASK,
+			data_addr+ex.a_data - (text_addr & PAGE_MASK),
 			PROT_READ|PROT_WRITE|PROT_EXEC,
 			MAP_FIXED|MAP_PRIVATE, 0);
-		read_exec(bprm->inode, fd_offset, (char *) N_TXTADDR(ex),
-			  ex.a_text+ex.a_data, 0);
+		read_exec(bprm->inode, text_offset, (char *)text_addr,
+			  ex.a_text, 0);
+		read_exec(bprm->inode, data_offset, (char *)data_addr,
+			  ex.a_data, 0);
 #else
 		do_mmap(NULL, 0, ex.a_text+ex.a_data,
 			PROT_READ|PROT_WRITE|PROT_EXEC,
@@ -338,36 +384,31 @@
 		file = current->files->fd[fd];
 		if (!file->f_op || !file->f_op->mmap) {
 			sys_close(fd);
-			do_mmap(NULL, 0, ex.a_text+ex.a_data,
-				PROT_READ|PROT_WRITE|PROT_EXEC,
-				MAP_FIXED|MAP_PRIVATE, 0);
-			read_exec(bprm->inode, fd_offset,
-				  (char *) N_TXTADDR(ex), ex.a_text+ex.a_data, 0);
-			goto beyond_if;
+			goto load_unmapped;
 		}
 
-		error = do_mmap(file, N_TXTADDR(ex), ex.a_text,
+		error = do_mmap(file, text_addr, ex.a_text,
 			PROT_READ | PROT_EXEC,
 			MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
-			fd_offset);
+			text_offset);
 
-		if (error != N_TXTADDR(ex)) {
+		if (error != text_addr) {
 			sys_close(fd);
 			send_sig(SIGKILL, current, 0);
 			return error;
 		}
 		
- 		error = do_mmap(file, N_DATADDR(ex), ex.a_data,
+ 		error = do_mmap(file, data_addr, ex.a_data,
 				PROT_READ | PROT_WRITE | PROT_EXEC,
 				MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
-				fd_offset + ex.a_text);
+				data_offset);
 		sys_close(fd);
-		if (error != N_DATADDR(ex)) {
+		if (error != data_addr) {
 			send_sig(SIGKILL, current, 0);
 			return error;
 		}
 	}
-beyond_if:
+
 	if (current->exec_domain && current->exec_domain->use_count)
 		(*current->exec_domain->use_count)--;
 	if (current->binfmt && current->binfmt->use_count)

  reply	other threads:[~1996-05-15 16:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-05-14 17:10 strip 2.6 breaks images Harald Koenig
1996-05-14 21:59 ` Richard Henderson
1996-05-14 23:21   ` Harald Koenig
1996-05-15 16:13     ` Richard Henderson [this message]
1996-05-17 23:31       ` Harald Koenig
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox