kern/122047: [ext2fs] incorrect handling of UF_IMMUTABLE / UF_APPEND flag on EXT2FS (maybe others)

Ighighi ighighi at gmail.com
Thu May 29 07:37:07 UTC 2008


See attached patch.  Gmail sucks at sending patches to GNATS =(
-------------- next part --------------
#
# (!c) 2008 by Ighighi
#
# See http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/122047
#
# This patch adds a "vfs.e2fs.userflags" sysctl to permit regular users
# to set/clear the APPEND/IMMUTABLE filesystem flags on EXT2 filesystems.
# As a bonus, it also sets st_birthtime to zero.
#
# Built and tested on FreeBSD 6.3-STABLE (RELENG_6).
# Known to patch on -CURRENT
#
# To install, run as root:
#   /sbin/umount -v -t ext2fs -a
#   /sbin/kldunload -v ext2fs
#   /usr/bin/patch -d /usr < /path/to/ext2fs.patch
#   cd /sys/modules/ext2fs/
#   make clean obj depend && make && make install
#   /sbin/kldload -v ext2fs
#   /sbin/sysctl vfs.e2fs.userflags=1  # 0 is default
#   /sbin/mount -v -t ext2fs -a
#

--- src/sys/gnu/fs/ext2fs/ext2_inode_cnv.c.orig	2005-06-14 22:36:10.000000000 -0400
+++ src/sys/gnu/fs/ext2fs/ext2_inode_cnv.c	2008-05-28 15:15:27.527318854 -0430
@@ -30,11 +30,19 @@
 #include <sys/lock.h>
 #include <sys/stat.h>
 #include <sys/vnode.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
 
 #include <gnu/fs/ext2fs/inode.h>
 #include <gnu/fs/ext2fs/ext2_fs.h>
 #include <gnu/fs/ext2fs/ext2_extern.h>
 
+SYSCTL_DECL(_vfs_e2fs);
+
+static int userflags = 0;
+SYSCTL_INT(_vfs_e2fs, OID_AUTO, userflags, CTLFLAG_RW,
+    &userflags, 0, "Users may set/clear filesystem flags");
+
 void
 ext2_print_inode( in )
 	struct inode *in;
@@ -83,8 +91,17 @@ ext2_ei2i(ei, ip)
 	ip->i_mtime = ei->i_mtime;
 	ip->i_ctime = ei->i_ctime;
 	ip->i_flags = 0;
-	ip->i_flags |= (ei->i_flags & EXT2_APPEND_FL) ? APPEND : 0;
-	ip->i_flags |= (ei->i_flags & EXT2_IMMUTABLE_FL) ? IMMUTABLE : 0;
+	if (userflags) {
+		if (ei->i_flags & EXT2_APPEND_FL)
+			ip->i_flags |= UF_APPEND;
+		if (ei->i_flags & EXT2_IMMUTABLE_FL)
+			ip->i_flags |= UF_IMMUTABLE;
+	} else {
+		if (ei->i_flags & EXT2_APPEND_FL)
+			ip->i_flags |= APPEND;
+		if (ei->i_flags & EXT2_IMMUTABLE_FL)
+			ip->i_flags |= IMMUTABLE;
+	}
 	ip->i_blocks = ei->i_blocks;
 	ip->i_gen = ei->i_generation;
 	ip->i_uid = ei->i_uid;
--- src/sys/gnu/fs/ext2fs/ext2_lookup.c.orig	2006-01-04 15:32:00.000000000 -0400
+++ src/sys/gnu/fs/ext2fs/ext2_lookup.c	2008-05-28 13:35:16.841349269 -0430
@@ -66,7 +66,7 @@ static int dirchk = 1;
 static int dirchk = 0;
 #endif
 
-static SYSCTL_NODE(_vfs, OID_AUTO, e2fs, CTLFLAG_RD, 0, "EXT2FS filesystem");
+SYSCTL_NODE(_vfs, OID_AUTO, e2fs, CTLFLAG_RW, 0, "EXT2FS filesystem");
 SYSCTL_INT(_vfs_e2fs, OID_AUTO, dircheck, CTLFLAG_RW, &dirchk, 0, "");
 
 /*
--- src/sys/gnu/fs/ext2fs/ext2_vnops.c.orig	2006-02-19 20:53:14.000000000 -0400
+++ src/sys/gnu/fs/ext2fs/ext2_vnops.c	2008-05-28 07:58:02.189157441 -0430
@@ -358,6 +358,8 @@ ext2_getattr(ap)
 	vap->va_mtime.tv_nsec = ip->i_mtimensec;
 	vap->va_ctime.tv_sec = ip->i_ctime;
 	vap->va_ctime.tv_nsec = ip->i_ctimensec;
+	vap->va_birthtime.tv_sec = 0;
+	vap->va_birthtime.tv_nsec = 0;
 	vap->va_flags = ip->i_flags;
 	vap->va_gen = ip->i_gen;
 	vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;


More information about the freebsd-fs mailing list