patch for alpha/kernel/osf_sys.c -- please test

Bill Hawes (whawes@star.net)
Mon, 06 Jul 1998 21:14:05 -0400


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

The attached patch adds wrapper functions for accessing
current->files->fd[] in the arch/alpha directory, and adds error
checking for a few copy_xx_user calls. It should make no change in
functionality.

As I don't have an alpha machine to compile and test it on, I'd
appreciate it if someone could give it a try and verify that everything
still works OK.

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

--- linux-2.1.108/arch/alpha/kernel/osf_sys.c.old Fri Jul 3 10:32:20 1998
+++ linux-2.1.108/arch/alpha/kernel/osf_sys.c Fri Jul 3 19:21:52 1998
@@ -140,10 +140,7 @@
struct osf_dirent_callback buf;

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

@@ -154,17 +151,18 @@

error = -ENOTDIR;
if (!file->f_op || !file->f_op->readdir)
- goto out;
+ goto out_putf;

error = file->f_op->readdir(file, &buf, osf_filldir);
if (error < 0)
- goto out;
+ goto out_putf;

error = buf.error;
- if (count == buf.count)
- goto out;
+ if (count != buf.count)
+ error = count - buf.count;

- error = count - buf.count;
+out_putf:
+ fput(file);
out:
return error;
}
@@ -248,13 +246,17 @@

lock_kernel();
if (flags & (_MAP_HASSEMAPHORE | _MAP_INHERIT | _MAP_UNALIGNED))
- printk("%s: unimplemented OSF mmap flags %04lx\n", current->comm, flags);
+ printk("%s: unimplemented OSF mmap flags %04lx\n",
+ current->comm, flags);
if (!(flags & MAP_ANONYMOUS)) {
- if (fd >= NR_OPEN || !(file = current->files->fd[fd]))
+ file = fget(fd);
+ if (!file)
goto out;
}
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
ret = do_mmap(file, addr, len, prot, flags, off);
+ if (file)
+ fput(file);
out:
unlock_kernel();
return ret;
@@ -340,11 +342,13 @@

lock_kernel();
retval = -EBADF;
- if (fd >= NR_OPEN || !(file = current->files->fd[fd]))
+ file = fget(fd);
+ if (!file)
goto out;
dentry = file->f_dentry;
if (dentry)
retval = do_osf_statfs(dentry, buffer, bufsiz);
+ fput(file);
out:
unlock_kernel();
return retval;
@@ -390,38 +394,41 @@
if (IS_ERR(dentry))
return retval;

+ retval = -ENOTBLK;
inode = dentry->d_inode;
- if (!S_ISBLK(inode->i_mode)) {
- dput(dentry);
- return -ENOTBLK;
- }
- if (IS_NODEV(inode)) {
- dput(dentry);
- return -EACCES;
- }
+ if (!S_ISBLK(inode->i_mode))
+ goto out_dput;
+
+ retval = -EACCES;
+ if (IS_NODEV(inode))
+ goto out_dput;
+
+ retval = -ENXIO;
dev = inode->i_rdev;
- if (MAJOR(dev) >= MAX_BLKDEV) {
- dput(dentry);
- return -ENXIO;
- }
+ if (MAJOR(dev) >= MAX_BLKDEV)
+ goto out_dput;
+
+ retval = -ENODEV;
fops = get_blkfops(MAJOR(dev));
- if (!fops) {
- dput(dentry);
- return -ENODEV;
- }
+ if (!fops)
+ goto out_dput;
if (fops->open) {
struct file dummy;
memset(&dummy, 0, sizeof(dummy));
dummy.f_dentry = dentry;
dummy.f_mode = rdonly ? 1 : 3;
retval = fops->open(inode, &dummy);
- if (retval) {
- dput(dentry);
- return retval;
- }
+ if (retval)
+ goto out_dput;
}
*dp = dentry;
- return 0;
+ retval = 0;
+out:
+ return retval;
+
+out_dput:
+ dput(dentry);
+ goto out;
}

static void putdev(struct dentry *dentry)
@@ -446,15 +453,21 @@

retval = verify_area(VERIFY_READ, args, sizeof(*args));
if (retval)
- return retval;
- copy_from_user(&tmp, args, sizeof(tmp));
+ goto out;
+
+ retval = -EFAULT;
+ if (copy_from_user(&tmp, args, sizeof(tmp)))
+ goto out;
+
retval = getdev(tmp.devname, 0, &dentry);
if (retval)
- return retval;
- retval = do_mount(dentry->d_inode->i_rdev, tmp.devname, dirname, "ext2", flags, NULL);
+ goto out;
+ retval = do_mount(dentry->d_inode->i_rdev, tmp.devname, dirname,
+ "ext2", flags, NULL);
if (retval)
putdev(dentry);
dput(dentry);
+out:
return retval;
}

@@ -466,15 +479,21 @@

retval = verify_area(VERIFY_READ, args, sizeof(*args));
if (retval)
- return retval;
- copy_from_user(&tmp, args, sizeof(tmp));
+ goto out;
+
+ retval = -EFAULT;
+ if (copy_from_user(&tmp, args, sizeof(tmp)))
+ goto out;
+
retval = getdev(tmp.devname, 1, &dentry);
if (retval)
- return retval;
- retval = do_mount(dentry->d_inode->i_rdev, tmp.devname, dirname, "iso9660", flags, NULL);
+ goto out;
+ retval = do_mount(dentry->d_inode->i_rdev, tmp.devname, dirname,
+ "iso9660", flags, NULL);
if (retval)
putdev(dentry);
dput(dentry);
+out:
return retval;
}

--------------F2017F9B78E6C55A88B157A8--

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