patch-1.3.42 linux/fs/exec.c

Next file: linux/fs/ext/inode.c
Previous file: linux/fs/dcache.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v1.3.41/linux/fs/exec.c linux/fs/exec.c
@@ -953,12 +953,22 @@
 	file = current->files->fd[fd];
 	inode = file->f_inode;
 	
-	set_fs(KERNEL_DS);
-	if (file->f_op->read(inode, file, (char *) &ex, sizeof(ex)) != sizeof(ex)) {
+	if (!file || !file->f_op)
 		return -EACCES;
-	}
+
+	/* Seek into the file */
+	if (file->f_op->lseek) {
+		if ((error = file->f_op->lseek(inode, file, 0, 0)) != 0)
+			return -ENOEXEC;
+	} else
+		file->f_pos = 0;
+
+	set_fs(KERNEL_DS);
+	error = file->f_op->read(inode, file, (char *) &ex, sizeof(ex));
 	set_fs(USER_DS);
-	
+	if (error != sizeof(ex))
+		return -ENOEXEC;
+
 	/* We come in here for the regular a.out style of shared libraries */
 	if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != QMAGIC) || N_TRSIZE(ex) ||
 	    N_DRSIZE(ex) || ((ex.a_entry & 0xfff) && N_MAGIC(ex) == ZMAGIC) ||

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov with Sam's (original) version
of this