minor permissions patch to mtdchar

Simon Evans spse at secret.org.uk
Sat Jul 13 14:05:09 EDT 2002


Are there any objections to me commiting the following?

It:

1. sets the permission on /dev/mtd/*ro to 444 rather than 666
2. Disallows MEMWRITEOOB & MEMERASE ioctls if the device is not opened with
   write permissions.

cheers
si

Index: mtdchar.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/mtdchar.c,v
retrieving revision 1.44
diff -u -p -r1.44 mtdchar.c
--- mtdchar.c	2 Oct 2001 15:05:11 -0000	1.44
+++ mtdchar.c	13 Jul 2002 17:50:35 -0000
@@ -287,7 +287,12 @@ static int mtd_ioctl(struct inode *inode
 
 	case MEMERASE:
 	{
-		struct erase_info *erase=kmalloc(sizeof(struct erase_info),GFP_KERNEL);
+		struct erase_info *erase;
+
+		if(!(file->f_mode & 2))
+			return -EPERM;
+
+		erase=kmalloc(sizeof(struct erase_info),GFP_KERNEL);
 		if (!erase)
 			ret = -ENOMEM;
 		else {
@@ -338,6 +343,9 @@ static int mtd_ioctl(struct inode *inode
 		void *databuf;
 		ssize_t retlen;
 		
+		if(!(file->f_mode & 2))
+			return -EPERM;
+
 		if (copy_from_user(&buf, (struct mtd_oob_buf *)arg, sizeof(struct mtd_oob_buf)))
 			return -EFAULT;
 		
@@ -474,7 +482,7 @@ static void mtd_notify_add(struct mtd_in
 	sprintf(name, "%dro", mtd->index);
 	devfs_ro_handle[mtd->index] = devfs_register(devfs_dir_handle, name,
 			DEVFS_FL_DEFAULT, MTD_CHAR_MAJOR, mtd->index*2+1,
-			S_IFCHR | S_IRUGO | S_IWUGO,
+			S_IFCHR | S_IRUGO,
 			&mtd_fops, NULL);
 }
 






More information about the linux-mtd mailing list