[PATCH 11/25] elevate write count during entire ncp_ioctl()

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <akpm@...>
Cc: <linux-kernel@...>, <hch@...>, Dave Hansen <haveblue@...>
Date: Thursday, September 20, 2007 - 3:53 pm

Some ioctls need write access, but others don't.  Make a helper
function to decide when write access is needed, and take it.

Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
---

 lxc-dave/fs/ncpfs/ioctl.c |   54 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 53 insertions(+), 1 deletion(-)

diff -puN fs/ncpfs/ioctl.c~elevate-write-count-during-entire-ncp-ioctl fs/ncpfs/ioctl.c
--- lxc/fs/ncpfs/ioctl.c~elevate-write-count-during-entire-ncp-ioctl	2007-09-20 12:16:15.000000000 -0700
+++ lxc-dave/fs/ncpfs/ioctl.c	2007-09-20 12:16:15.000000000 -0700
@@ -14,6 +14,7 @@
 #include <linux/ioctl.h>
 #include <linux/time.h>
 #include <linux/mm.h>
+#include <linux/mount.h>
 #include <linux/highuid.h>
 #include <linux/smp_lock.h>
 #include <linux/vmalloc.h>
@@ -261,7 +262,7 @@ ncp_get_charsets(struct ncp_server* serv
 }
 #endif /* CONFIG_NCPFS_NLS */
 
-int ncp_ioctl(struct inode *inode, struct file *filp,
+static int __ncp_ioctl(struct inode *inode, struct file *filp,
 	      unsigned int cmd, unsigned long arg)
 {
 	struct ncp_server *server = NCP_SERVER(inode);
@@ -822,6 +823,57 @@ outrel:			
 	return -EINVAL;
 }
 
+static int ncp_ioctl_need_write(unsigned int cmd)
+{
+	switch (cmd) {
+	case NCP_IOC_GET_FS_INFO:
+	case NCP_IOC_GET_FS_INFO_V2:
+	case NCP_IOC_NCPREQUEST:
+	case NCP_IOC_SETDENTRYTTL:
+	case NCP_IOC_SIGN_INIT:
+	case NCP_IOC_LOCKUNLOCK:
+	case NCP_IOC_SET_SIGN_WANTED:
+		return 1;
+	case NCP_IOC_GETOBJECTNAME:
+	case NCP_IOC_SETOBJECTNAME:
+	case NCP_IOC_GETPRIVATEDATA:
+	case NCP_IOC_SETPRIVATEDATA:
+	case NCP_IOC_SETCHARSETS:
+	case NCP_IOC_GETCHARSETS:
+	case NCP_IOC_CONN_LOGGED_IN:
+	case NCP_IOC_GETDENTRYTTL:
+	case NCP_IOC_GETMOUNTUID2:
+	case NCP_IOC_SIGN_WANTED:
+	case NCP_IOC_GETROOT:
+	case NCP_IOC_SETROOT:
+		return 0;
+	default:
+		/* unkown IOCTL command, assume write */
+	}
+	return 1;
+}
+
+int ncp_ioctl(struct inode *inode, struct file *filp,
+	      unsigned int cmd, unsigned long arg)
+{
+	int ret;
+
+	if (ncp_ioctl_need_write(cmd)) {
+		/*
+		 * inside the ioctl(), any failures which
+		 * are because of file_permission() are
+		 * -EACCESS, so it seems consistent to keep
+		 *  that here.
+		 */
+		if (mnt_want_write(filp->f_vfsmnt))
+			return -EACCES;
+	}
+	ret = __ncp_ioctl(inode, filp, cmd, arg);
+	if (ncp_ioctl_need_write(cmd))
+		mnt_drop_write(filp->f_vfsmnt);
+	return ret;
+}
+
 #ifdef CONFIG_COMPAT
 long ncp_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
_
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/25] Read-only bind mounts, Dave Hansen, (Thu Sep 20, 3:52 pm)
Re: [PATCH 24/25] r/o bind mounts: track number of mount wri..., Christoph Hellwig, (Mon Sep 24, 1:54 pm)
Re: [PATCH 24/25] r/o bind mounts: track number of mount wri..., Christoph Hellwig, (Mon Sep 24, 3:24 pm)
Re: [PATCH 24/25] r/o bind mounts: track number of mount wri..., Arjan van de Ven, (Mon Sep 24, 10:34 am)
[PATCH 25/25] honor r/w changes at do_remount() time, Dave Hansen, (Thu Sep 20, 3:53 pm)
[PATCH 23/25] do_rmdir(): elevate write count, Dave Hansen, (Thu Sep 20, 3:53 pm)
[PATCH 06/25] elevate write count open()'d files, Dave Hansen, (Thu Sep 20, 3:52 pm)
Re: [PATCH 06/25] elevate write count open()'d files, Andrew Morton, (Wed Nov 28, 4:41 am)
Re: [PATCH 06/25] elevate write count open()'d files, Dave Hansen, (Wed Nov 28, 1:33 pm)
[PATCH 19/25] elevate write count for do_utimes(), Dave Hansen, (Thu Sep 20, 3:53 pm)
[PATCH 02/25] rearrange may_open() to be r/o friendly, Dave Hansen, (Thu Sep 20, 3:52 pm)
[RFC] detect missed mnt_want_write() calls, Dave Hansen, (Tue Sep 25, 9:34 pm)
[PATCH 11/25] elevate write count during entire ncp_ioctl(), Dave Hansen, (Thu Sep 20, 3:53 pm)
[PATCH 09/25] make access() use mnt check, Dave Hansen, (Thu Sep 20, 3:53 pm)
[PATCH 05/25] r/o bind mounts: stub functions, Dave Hansen, (Thu Sep 20, 3:52 pm)
[PATCH 04/25] create cleanup helper svc_msnfs(), Dave Hansen, (Thu Sep 20, 3:52 pm)
[PATCH 03/25] give may_open() a local 'mnt' variable, Dave Hansen, (Thu Sep 20, 3:52 pm)
Re: [PATCH 03/25] give may_open() a local 'mnt' variable, Christoph Hellwig, (Thu Sep 20, 3:57 pm)