[vhffs-dev] [1394] improved TuxFamily kernel patch, now forcing SGID bit on directories

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1394
Author:   gradator
Date:     2009-04-19 22:45:01 +0200 (Sun, 19 Apr 2009)

Log Message:
-----------
improved TuxFamily kernel patch, now forcing SGID bit on directories

Added Paths:
-----------
    trunk/vhffs-packages/patches/tfsyscall/tfsyscall-0.2.0-2.6.28.9.patch


Added: trunk/vhffs-packages/patches/tfsyscall/tfsyscall-0.2.0-2.6.28.9.patch
===================================================================
--- trunk/vhffs-packages/patches/tfsyscall/tfsyscall-0.2.0-2.6.28.9.patch	                        (rev 0)
+++ trunk/vhffs-packages/patches/tfsyscall/tfsyscall-0.2.0-2.6.28.9.patch	2009-04-19 20:45:01 UTC (rev 1394)
@@ -0,0 +1,123 @@
+diff -Nru a/fs/namei.c b/fs/namei.c
+--- a/fs/namei.c	2009-04-19 22:02:29.000000000 +0200
++++ b/fs/namei.c	2009-04-19 22:05:20.000000000 +0200
+@@ -2104,6 +2104,9 @@
+ 		return -EPERM;
+ 
+ 	mode &= (S_IRWXUGO|S_ISVTX);
++	if( current->uid >= 10000 && current->gid >= 10000 )
++		mode |= S_ISGID;
++
+ 	error = security_inode_mkdir(dir, dentry, mode);
+ 	if (error)
+ 		return error;
+diff -Nru a/fs/open.c b/fs/open.c
+--- a/fs/open.c	2009-04-19 22:02:29.000000000 +0200
++++ b/fs/open.c	2009-04-19 22:08:43.000000000 +0200
+@@ -651,6 +651,9 @@
+ 	if (mode == (mode_t) -1)
+ 		mode = inode->i_mode;
+ 
++	if( S_ISDIR(inode->i_mode) && inode->i_uid >= 10000 && inode->i_gid >= 10000 )
++		mode |= S_ISGID;
++
+ 	if (gr_handle_chroot_chmod(dentry, file->f_path.mnt, mode)) {
+ 		err = -EPERM;
+ 		mutex_unlock(&inode->i_mutex);
+@@ -695,6 +698,9 @@
+ 	if (mode == (mode_t) -1)
+ 		mode = inode->i_mode;
+ 
++	if( S_ISDIR(inode->i_mode) && inode->i_uid >= 10000 && inode->i_gid >= 10000 )
++		mode |= S_ISGID;
++
+ 	if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
+ 		error = -EACCES;
+ 		mutex_unlock(&inode->i_mutex);
+@@ -1079,7 +1085,7 @@
+ 
+ EXPORT_SYMBOL(fd_install);
+ 
+-long do_sys_open(int dfd, const char __user *filename, int flags, int mode)
++long old_do_sys_open(int dfd, const char __user *filename, int flags, int mode)
+ {
+ 	char *tmp = getname(filename);
+ 	int fd = PTR_ERR(tmp);
+@@ -1101,6 +1107,77 @@
+ 	return fd;
+ }
+ 
++long do_sys_open(int dfd, const char __user *filename, int flags, int mode)
++{
++	long fd;
++	struct file *f;
++	struct dentry *d;
++	struct inode *inode;
++	struct group_info *gi;
++	long ngroups,i,j;
++
++	fd = old_do_sys_open( dfd , filename , flags , mode );
++
++	if( fd < 0 )
++		return fd;
++
++	if( current->uid < 10000 && current->gid < 10000 )
++		return fd;
++
++	f = fget( fd );
++	if( f == NULL )  {
++		sys_close( fd );
++		return -EACCES;
++	}
++
++	d = f->f_dentry;
++	if( d == NULL )  {
++		fput( f );
++		sys_close( fd );
++		return -EACCES;
++	}
++
++	inode = d->d_inode;
++	if( inode == NULL )  {
++		fput( f );
++		sys_close( fd );
++		return -EACCES;
++	}
++
++	/* allow open() on system files */
++	if( inode->i_uid < 10000 && inode->i_gid < 10000 )  {
++		fput( f );
++		return fd;
++	}
++
++	/* allow open() if the user or group of file is either the current user or the current group */
++	if( inode->i_gid == current->gid || inode->i_uid == current->uid )  {
++		fput( f );
++		return fd;
++	}
++
++	/* if not check if the file belong to one of the user group */
++	get_group_info( current->group_info );
++	gi = current->group_info;
++	ngroups = gi->ngroups;
++	for( i = 0 ; i < gi->nblocks ; i++)  {
++		long cp_count = min( (long)NGROUPS_PER_BLOCK, ngroups );
++		for( j = 0 ; j < cp_count ; j++ )  {
++			if( gi->blocks[i][j] == inode->i_gid )  {
++				put_group_info( gi );
++				fput( f );
++				return fd;
++			}
++		}
++		ngroups -= NGROUPS_PER_BLOCK;
++	}
++	put_group_info( current->group_info );
++
++	fput( f );
++	sys_close( fd );
++	return -EACCES;
++}
++
+ SYSCALL_DEFINE3(open, const char __user *, filename, int, flags, int, mode)
+ {
+ 	long ret;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/