another patch for 2.1.88 files access

Bill Hawes (whawes@star.net)
Fri, 27 Feb 1998 15:54:09 -0500


This is a multi-part message in MIME format.
--------------D0760D5AAA92B242689E8AF9
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

The attached patch protects a few more of the references to files in the fd
array, in fs/buffer.c and arch/i386/kernel/sys_i386.c.

Regards,
Bill
--------------D0760D5AAA92B242689E8AF9
Content-Type: text/plain; charset=us-ascii; name="fd_more88-patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="fd_more88-patch"

--- linux-2.1.88/fs/buffer.c.old Sat Feb 21 09:24:59 1998
+++ linux-2.1.88/fs/buffer.c Thu Feb 26 10:30:31 1998
@@ -332,31 +335,29 @@

lock_kernel();
err = -EBADF;
-
- if (fd >= NR_OPEN)
- goto out;
-
- file = current->files->fd[fd];
+ file = fget(fd);
if (!file)
goto out;

dentry = file->f_dentry;
if (!dentry)
- goto out;
+ goto out_putf;

inode = dentry->d_inode;
if (!inode)
- goto out;
+ goto out_putf;

err = -EINVAL;
if (!file->f_op || !file->f_op->fsync)
- goto out;
+ goto out_putf;

/* We need to protect against concurrent writers.. */
down(&inode->i_sem);
- err = file->f_op->fsync(file, file->f_dentry);
+ err = file->f_op->fsync(file, dentry);
up(&inode->i_sem);

+out_putf:
+ fput(file);
out:
unlock_kernel();
return err;
@@ -371,29 +372,27 @@

lock_kernel();
err = -EBADF;
-
- if (fd >= NR_OPEN)
- goto out;
-
- file = current->files->fd[fd];
+ file = fget(fd);
if (!file)
goto out;

dentry = file->f_dentry;
if (!dentry)
- goto out;
+ goto out_putf;

inode = dentry->d_inode;
if (!inode)
- goto out;
+ goto out_putf;

err = -EINVAL;
if (!file->f_op || !file->f_op->fsync)
- goto out;
+ goto out_putf;

/* this needs further work, at the moment it is identical to fsync() */
- err = file->f_op->fsync(file, file->f_dentry);
+ err = file->f_op->fsync(file, dentry);

+out_putf:
+ fput(file);
out:
unlock_kernel();
return err;
--- linux-2.1.88/arch/i386/kernel/sys_i386.c.old Wed Dec 10 00:12:12 1997
+++ linux-2.1.88/arch/i386/kernel/sys_i386.c Thu Feb 26 14:19:43 1998
@@ -65,14 +65,17 @@

lock_kernel();
if (copy_from_user(&a, arg, sizeof(a)))
- goto out;
+ goto out;
if (!(a.flags & MAP_ANONYMOUS)) {
error = -EBADF;
- if (a.fd >= NR_OPEN || !(file = current->files->fd[a.fd]))
+ file = fget(a.fd);
+ if (!file)
goto out;
}
a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
error = do_mmap(file, a.addr, a.len, a.prot, a.flags, a.offset);
+ if (file)
+ fput(file);
out:
unlock_kernel();
return error;

--------------D0760D5AAA92B242689E8AF9--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu