Skip to contentSkip to conversation

MS_RDONLY patch (do_remount_sb and cramfs/inode.c)

PATCH Peter Kundrat 1 participant 3 messages May 15, 2001

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hello,

This patch does:
- set MS_RDONLY flag in cramfs superblock
- doesnt allow -w remount in do_remount_sb
if the filesystem has MS_RDONLY set.

Without it, it is possible to remount r/o
filesystem with -w and truncate files on it.
I hope that doesnt fall into 'dont do that then'
category.
Please apply.

Regards,

pkx

fs/cramfs/inode.c +2 -0
diff -ur -x *~ -x *.o -x .* Linux-2.4.3.orig/fs/cramfs/inode.c Linux-2.4.3.isdn.kgdb/fs/cramfs/inode.c
@@ -192,6 +192,8 @@
 		goto out;
 	}
 
+	sb->s_flags |= MS_RDONLY;
+
 	/* Set it all up.. */
 	sb->s_op	= &cramfs_ops;
 	sb->s_root 	= d_alloc_root(get_cramfs_inode(sb, &super.root));
fs/super.c +1 -1
diff -ur -x *~ -x *.o -x .* Linux-2.4.3.orig/fs/super.c Linux-2.4.3.isdn.kgdb/fs/super.c
@@ -944,7 +944,7 @@
 {
 	int retval;
 	
-	if (!(flags & MS_RDONLY) && sb->s_dev && is_read_only(sb->s_dev))
+	if (!(flags & MS_RDONLY) && ((sb->s_flags & MS_RDONLY) || sb->s_dev && is_read_only(sb->s_dev)))
 		return -EACCES;
 		/*flags |= MS_RDONLY;*/
 	/* If we are remounting RDONLY, make sure there are no rw files open */
Signature · 2 lines
Peter Kundrat
[email protected]
#1 lore raw
Quoted 4 lines · Peter Kundrat

This patch does:
- set MS_RDONLY flag in cramfs superblock
- doesnt allow -w remount in do_remount_sb
if the filesystem has MS_RDONLY set.

Oh, ignore the second part. Seems i'd have to supply remount_fs super op to prevent that.

pkx

Signature · 2 lines
Peter Kundrat
[email protected]
#2 lore raw
In reply to Peter Kundrat
Quoted 8 lines · Peter Kundrat
Quoted 4 lines · Peter Kundrat

This patch does:
- set MS_RDONLY flag in cramfs superblock
- doesnt allow -w remount in do_remount_sb
if the filesystem has MS_RDONLY set.

Oh, ignore the second part. Seems i'd have to supply remount_fs super op to prevent that.

How about this one ? Similar thing could be done to other fs as well.

pkx

fs/cramfs/inode.c +11 -0
diff -ur -x *~ -x *.o -x .* Linux-2.4.3.orig/fs/cramfs/inode.c Linux-2.4.3.isdn.kgdb/fs/cramfs/inode.c
@@ -192,6 +192,8 @@
 		goto out;
 	}
 
+	sb->s_flags |= MS_RDONLY;
+
 	/* Set it all up.. */
 	sb->s_op	= &cramfs_ops;
 	sb->s_root 	= d_alloc_root(get_cramfs_inode(sb, &super.root));
@@ -212,6 +214,14 @@
 	return 0;
 }
 
+static int cramfs_remount (struct super_block * sb, int * flags, char * data)
+{
+	if (*flags & MS_RDONLY) 
+		return 0;
+	else
+		return -EROFS;
+}
+
 /*
  * Read a cramfs directory entry.
  */
@@ -358,6 +368,7 @@
 
 static struct super_operations cramfs_ops = {
 	statfs:		cramfs_statfs,
+	remount_fs:	cramfs_remount,
 };
 
 static DECLARE_FSTYPE_DEV(cramfs_fs_type, "cramfs", cramfs_read_super);
Signature · 2 lines
Peter Kundrat
[email protected]