patch-1.3.85 linux/fs/open.c

Next file: linux/fs/proc/array.c
Previous file: linux/fs/nfs/rpcsock.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v1.3.84/linux/fs/open.c linux/fs/open.c
@@ -20,8 +20,6 @@
 
 #include <asm/segment.h>
 
-extern void locks_remove_locks(struct task_struct *, struct file *);
-
 asmlinkage int sys_statfs(const char * path, struct statfs * buf)
 {
 	struct inode * inode;
@@ -109,6 +107,11 @@
 		iput(inode);
 		return error;
 	}
+	error = locks_verify(FLOCK_VERIFY_WRITE, inode, NULL,
+			     length < inode->i_size ? length : inode->i_size,
+			     abs(inode->i_size - length));
+	if (error)
+		return error;
 	error = do_truncate(inode, length);
 	put_write_access(inode);
 	iput(inode);
@@ -119,6 +122,7 @@
 {
 	struct inode * inode;
 	struct file * file;
+	int error;
 
 	if (fd >= NR_OPEN || !(file = current->files->fd[fd]))
 		return -EBADF;
@@ -128,6 +132,11 @@
 		return -EACCES;
 	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
 		return -EPERM;
+	error = locks_verify(FLOCK_VERIFY_WRITE, inode, file,
+			     length < inode->i_size ? length : inode->i_size,
+			     abs(inode->i_size - length));
+	if (error)
+		return error;
 	return do_truncate(inode, length);
 }
 
@@ -391,8 +400,12 @@
 	}
 	/*
 	 * If the group has been changed, remove the setgid bit
+	 *
+	 * Don't remove the setgid bit if no group execute bit.
+	 * This is a file marked for mandatory locking.
 	 */
-	if (group != inode->i_gid && (inode->i_mode & S_ISGID)) {
+	if (group != inode->i_gid &&
+	    ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) {
 		newattrs.ia_mode &= ~S_ISGID;
 		newattrs.ia_valid |= ATTR_MODE;
 	}
@@ -443,8 +456,12 @@
 	}
 	/*
 	 * If the group has been changed, remove the setgid bit
+	 *
+	 * Don't remove the setgid bit if no group execute bit.
+	 * This is a file marked for mandatory locking.
 	 */
-	if (group != inode->i_gid && (inode->i_mode & S_ISGID)) {
+	if (group != inode->i_gid &&
+	    ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) {
 		newattrs.ia_mode &= ~S_ISGID;
 		newattrs.ia_valid |= ATTR_MODE;
 	}

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov with Sam's (original) version
of this