Skip to contentSkip to conversation

autofs sparse fixes

PATCH In review [email protected] 2 participants 2 messages Sep 28, 2003 – Sep 29, 2003 Kernel automounter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 autofs sparse fixes

fs/autofs/root.c +4 -4
diff -u --recursive --new-file -X /linux/dontdiff a/fs/autofs/root.c b/fs/autofs/root.c
@@ -468,7 +468,7 @@
 
 /* Get/set timeout ioctl() operation */
 static inline int autofs_get_set_timeout(struct autofs_sb_info *sbi,
-					 unsigned long *p)
+					 unsigned long __user *p)
 {
 	unsigned long ntimeout;
 
@@ -494,7 +494,7 @@
 static inline int autofs_expire_run(struct super_block *sb,
 				    struct autofs_sb_info *sbi,
 				    struct vfsmount *mnt,
-				    struct autofs_packet_expire *pkt_p)
+				    struct autofs_packet_expire __user *pkt_p)
 {
 	struct autofs_dir_ent *ent;
 	struct autofs_packet_expire pkt;
@@ -547,10 +547,10 @@
 	case AUTOFS_IOC_PROTOVER: /* Get protocol version */
 		return autofs_get_protover((int *)arg);
 	case AUTOFS_IOC_SETTIMEOUT:
-		return autofs_get_set_timeout(sbi,(unsigned long *)arg);
+		return autofs_get_set_timeout(sbi,(unsigned long __user *)arg);
 	case AUTOFS_IOC_EXPIRE:
 		return autofs_expire_run(inode->i_sb, sbi, filp->f_vfsmnt,
-					 (struct autofs_packet_expire *)arg);
+				 (struct autofs_packet_expire __user *)arg);
 	default:
 		return -ENOSYS;
 	}
fs/autofs/symlink.c +2 -1
diff -u --recursive --new-file -X /linux/dontdiff a/fs/autofs/symlink.c b/fs/autofs/symlink.c
@@ -12,7 +12,8 @@
 
 #include "autofs_i.h"
 
-static int autofs_readlink(struct dentry *dentry, char *buffer, int buflen)
+static int
+autofs_readlink(struct dentry *dentry, char __user *buffer, int buflen)
 {
 	char *s=((struct autofs_symlink *)dentry->d_inode->u.generic_ip)->data;
 	return vfs_readlink(dentry, buffer, buflen, s);
fs/autofs/waitq.c +9 -1
diff -u --recursive --new-file -X /linux/dontdiff a/fs/autofs/waitq.c b/fs/autofs/waitq.c
@@ -44,12 +44,16 @@
 	autofs_hash_dputall(&sbi->dirhash); /* Remove all dentry pointers */
 }
 
+/*
+ * Note: addr not in user space
+ */
 static int autofs_write(struct file *file, const void *addr, int bytes)
 {
 	unsigned long sigpipe, flags;
 	mm_segment_t fs;
 	const char *data = (const char *)addr;
 	ssize_t wr = 0;
+	ssize_t (*write)(struct file *, const char *, size_t, loff_t *);
 
 	/** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
 
@@ -59,8 +63,12 @@
 	fs = get_fs();
 	set_fs(KERNEL_DS);
 
+	/* Our write does not write to user space */
+	write = (ssize_t (*)(struct file *, const char *, size_t, loff_t *))
+		file->f_op->write;
+
 	while (bytes &&
-	       (wr = file->f_op->write(file,data,bytes,&file->f_pos)) > 0) {
+	       (wr = write(file,data,bytes,&file->f_pos)) > 0) {
 		data += wr;
 		bytes -= wr;
 	}
#1 lore raw

For cases like this, where we use a kernel pointer and do the "set_fs(KERNEL_DS)" thing to mak ea user-pointer routing write to kernel space, I suggest casting the pointer instead of the function, along with a comment on the "set_fs()".

Basically, something like this instead:

static int autofs_write(struct file *file, const void *addr, int bytes)

  {
	const void __user *data;
	...

	set_fs(KERNEL_DS);
	/* This cast is legal due to the set_fs()! */
	data = (const void __user *) addr;

	...->write(file, data, bytes);
	set_fs(old_fs);

}

See? That makes the cast more obvious, and it also makes it obvious _why_ the cast from kernel->user pointer is ok in this case.

Linus