[patch] zmagic fixes

Andrea Arcangeli (andrea@suse.de)
Sat, 16 Oct 1999 17:03:46 +0200 (CEST)


This patch fixes a bug in a do_brk. It also cleanup the code and it
removes the obsolete checks for the blocksize (as now we load in anonymous
memory if we can't mmap the file). I also rate-limited the printk.

--- 2.3.22/fs/binfmt_aout.c Sat Oct 16 03:34:52 1999
+++ /tmp/binfmt_aout.c Sat Oct 16 16:58:47 1999
@@ -270,7 +270,6 @@
unsigned long fd_offset;
unsigned long rlim;
int retval;
- static unsigned long error_time=0;

ex = *((struct exec *) bprm->buf); /* exec-header */
if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != OMAGIC &&
@@ -282,29 +281,6 @@

fd_offset = N_TXTOFF(ex);

-#ifdef __i386__
- if (N_MAGIC(ex) == ZMAGIC && fd_offset != BLOCK_SIZE) {
- if((jiffies-error_time) >5)
- {
- printk(KERN_NOTICE "N_TXTOFF != BLOCK_SIZE. See a.out.h.\n");
- error_time=jiffies;
- }
- return -ENOEXEC;
- }
-
- if (N_MAGIC(ex) == ZMAGIC && ex.a_text &&
- bprm->dentry->d_inode->i_op &&
- bprm->dentry->d_inode->i_op->get_block &&
- (fd_offset < bprm->dentry->d_inode->i_sb->s_blocksize)) {
- if((jiffies-error_time) >5)
- {
- printk(KERN_NOTICE "N_TXTOFF < BLOCK_SIZE. Please convert binary.\n");
- error_time=jiffies;
- }
- return -ENOEXEC;
- }
-#endif
-
/* Check initial limits. This avoids letting people circumvent
* size limits imposed on them by creating programs with large
* arrays in the data or bss.
@@ -364,26 +340,32 @@
flush_icache_range((unsigned long) 0,
(unsigned long) ex.a_text+ex.a_data);
} else {
+ static unsigned long error_time, error_time2;
if ((ex.a_text & 0xfff || ex.a_data & 0xfff) &&
- (N_MAGIC(ex) != NMAGIC))
+ (N_MAGIC(ex) != NMAGIC) && (jiffies-error_time2) > 5*HZ)
+ {
printk(KERN_NOTICE "executable not page aligned\n");
+ error_time2 = jiffies;
+ }

fd = open_dentry(bprm->dentry, O_RDONLY);
if (fd < 0)
return fd;
file = fget(fd);

- if ((fd_offset & ~PAGE_MASK) != 0) {
+ if ((fd_offset & ~PAGE_MASK) != 0 &&
+ (jiffies-error_time) > 5*HZ)
+ {
printk(KERN_WARNING
"fd_offset is not page aligned. Please convert program: %s\n",
- file->f_dentry->d_name.name
- );
+ file->f_dentry->d_name.name);
+ error_time = jiffies;
}

if (!file->f_op || !file->f_op->mmap || ((fd_offset & ~PAGE_MASK) != 0)) {
fput(file);
sys_close(fd);
- do_brk(0, ex.a_text+ex.a_data);
+ do_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
read_exec(bprm->dentry, fd_offset,
(char *) N_TXTADDR(ex), ex.a_text+ex.a_data, 0);
flush_icache_range((unsigned long) N_TXTADDR(ex),
@@ -493,12 +475,6 @@
goto out_putf;
}

- if (N_MAGIC(ex) == ZMAGIC && N_TXTOFF(ex) &&
- (N_TXTOFF(ex) < inode->i_sb->s_blocksize)) {
- printk("N_TXTOFF < BLOCK_SIZE. Please convert library\n");
- goto out_putf;
- }
-
if (N_FLAGS(ex))
goto out_putf;

@@ -508,14 +484,17 @@
start_addr = ex.a_entry & 0xfffff000;

if ((N_TXTOFF(ex) & ~PAGE_MASK) != 0) {
- printk(KERN_WARNING
- "N_TXTOFF is not page aligned. Please convert library: %s\n",
- file->f_dentry->d_name.name
- );
-
- do_mmap(NULL, start_addr & PAGE_MASK, ex.a_text + ex.a_data + ex.a_bss,
- PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_FIXED| MAP_PRIVATE, 0);
+ static unsigned long error_time;
+
+ if ((jiffies-error_time) > 5*HZ)
+ {
+ printk(KERN_WARNING
+ "N_TXTOFF is not page aligned. Please convert library: %s\n",
+ file->f_dentry->d_name.name);
+ error_time = jiffies;
+ }
+
+ do_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);

read_exec(file->f_dentry, N_TXTOFF(ex),
(char *)start_addr, ex.a_text + ex.a_data, 0);

Andrea

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/