Re: [PATCH 16/27] r-o-bind-mounts-elevate-write-count-for-some-ioctls

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Andrew Morton
Date: Monday, November 5, 2007 - 4:23 pm

On Thu, 01 Nov 2007 16:08:47 -0700
Dave Hansen <haveblue@us.ibm.com> wrote:


See, when we combine this patch with Jan's
forbid-user-to-change-file-flags-on-quota-files.patch we silently add bugs
to five filesystems.  Lessons:

- never ever ever do `return' from deep in the guts of a function.  This
  is a *classic* instance of the maintainability risks which this practice
  introduces.

- this whole elevate-the-write-count-in-a-zillion-places stuff is quite
  fragile.



diff -puN fs/ext2/ioctl.c~r-o-bind-mounts-elevate-write-count-for-some-ioctls-vs-forbid-user-to-change-file-flags-on-quota-files fs/ext2/ioctl.c
--- a/fs/ext2/ioctl.c~r-o-bind-mounts-elevate-write-count-for-some-ioctls-vs-forbid-user-to-change-file-flags-on-quota-files
+++ a/fs/ext2/ioctl.c
@@ -57,7 +57,8 @@ int ext2_ioctl (struct inode * inode, st
 		/* Is it quota file? Do not allow user to mess with it */
 		if (IS_NOQUOTA(inode)) {
 			mutex_unlock(&inode->i_mutex);
-			return -EPERM;
+			ret = -EPERM;
+			goto setflags_out;
 		}
 		oldflags = ei->i_flags;
 
diff -puN fs/ext3/ioctl.c~r-o-bind-mounts-elevate-write-count-for-some-ioctls-vs-forbid-user-to-change-file-flags-on-quota-files fs/ext3/ioctl.c
--- a/fs/ext3/ioctl.c~r-o-bind-mounts-elevate-write-count-for-some-ioctls-vs-forbid-user-to-change-file-flags-on-quota-files
+++ a/fs/ext3/ioctl.c
@@ -60,7 +60,8 @@ int ext3_ioctl (struct inode * inode, st
 		/* Is it quota file? Do not allow user to mess with it */
 		if (IS_NOQUOTA(inode)) {
 			mutex_unlock(&inode->i_mutex);
-			return -EPERM;
+			err = -EPERM;
+			goto flags_out;
 		}
 		oldflags = ei->i_flags;
 
diff -puN fs/ext4/ioctl.c~r-o-bind-mounts-elevate-write-count-for-some-ioctls-vs-forbid-user-to-change-file-flags-on-quota-files fs/ext4/ioctl.c
--- a/fs/ext4/ioctl.c~r-o-bind-mounts-elevate-write-count-for-some-ioctls-vs-forbid-user-to-change-file-flags-on-quota-files
+++ a/fs/ext4/ioctl.c
@@ -59,7 +59,8 @@ int ext4_ioctl (struct inode * inode, st
 		/* Is it quota file? Do not allow user to mess with it */
 		if (IS_NOQUOTA(inode)) {
 			mutex_unlock(&inode->i_mutex);
-			return -EPERM;
+			err = -EPERM;
+			goto flags_out;
 		}
 		oldflags = ei->i_flags;
 
diff -puN fs/jfs/ioctl.c~r-o-bind-mounts-elevate-write-count-for-some-ioctls-vs-forbid-user-to-change-file-flags-on-quota-files fs/jfs/ioctl.c
--- a/fs/jfs/ioctl.c~r-o-bind-mounts-elevate-write-count-for-some-ioctls-vs-forbid-user-to-change-file-flags-on-quota-files
+++ a/fs/jfs/ioctl.c
@@ -85,8 +85,10 @@ int jfs_ioctl(struct inode * inode, stru
 			flags &= ~JFS_DIRSYNC_FL;
 
 		/* Is it quota file? Do not allow user to mess with it */
-		if (IS_NOQUOTA(inode))
-			return -EPERM;
+		if (IS_NOQUOTA(inode)) {
+			err = -EPERM;
+			goto setflags_out;
+		}
 		jfs_get_inode_flags(jfs_inode);
 		oldflags = jfs_inode->mode2;
 
diff -puN fs/reiserfs/ioctl.c~r-o-bind-mounts-elevate-write-count-for-some-ioctls-vs-forbid-user-to-change-file-flags-on-quota-files fs/reiserfs/ioctl.c
_

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/27] Read-only bind mounts (-mm resend), Dave Hansen, (Thu Nov 1, 4:08 pm)
[PATCH 02/27] make open_namei() return a filp, Dave Hansen, (Thu Nov 1, 4:08 pm)
[PATCH 03/27] kill do_filp_open(), Dave Hansen, (Thu Nov 1, 4:08 pm)
[PATCH 04/27] kill filp_open(), Dave Hansen, (Thu Nov 1, 4:08 pm)
[PATCH 05/27] rename open_namei() to open_pathname(), Dave Hansen, (Thu Nov 1, 4:08 pm)
[PATCH 06/27] r-o-bind-mounts-stub-functions, Dave Hansen, (Thu Nov 1, 4:08 pm)
Re: [PATCH 16/27] r-o-bind-mounts-elevate-write-count-for- ..., Andrew Morton, (Mon Nov 5, 4:23 pm)
Re: [PATCH 05/27] rename open_namei() to open_pathname(), Christoph Hellwig, (Mon Nov 26, 7:33 am)
Re: [PATCH 04/27] kill filp_open(), Andrew Morton, (Wed Jan 16, 1:52 am)
Re: [PATCH 04/27] kill filp_open(), Dave Hansen, (Wed Jan 16, 10:04 am)
Re: [PATCH 04/27] kill filp_open(), Christoph Hellwig, (Wed Jan 16, 10:10 am)
Re: [PATCH 04/27] kill filp_open(), Bryn M. Reeves, (Wed Jan 16, 10:12 am)
Re: [PATCH 04/27] kill filp_open(), Dave Hansen, (Wed Jan 16, 10:41 am)
Re: [PATCH 04/27] kill filp_open(), Christoph Hellwig, (Wed Jan 16, 10:47 am)