linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [V5 Patch 0/2] fix file truncations when both suid and write permissions set
@ 2009-08-19  4:44 Amerigo Wang
  2009-08-19  4:44 ` [Patch 1/2] selinux: adjust rules for ATTR_FORCE Amerigo Wang
  2009-08-19  4:44 ` [Patch 2/2] vfs: allow file truncations when both suid and write permissions set Amerigo Wang
  0 siblings, 2 replies; 3+ messages in thread
From: Amerigo Wang @ 2009-08-19  4:44 UTC (permalink / raw)
  To: linux-kernel
  Cc: esandeen, eteo, eparis, Amerigo Wang, linux-fsdevel, akpm, sds,
	hirofumi, viro


Andrew, these two patches can replace the -mm patch
"vfs-allow-file-truncations-when-both-suid-and-write-permissions-set.patch".


When suid is set and the non-owner user has write permission,
any writing into this file should be allowed and suid should be
removed after that.

However, current kernel only allows writing without truncations,
when we do truncations on that file, we get EPERM. This is a bug.

Steps to reproduce this bug:

% ls -l rootdir/file1
-rwsrwsrwx 1 root root 3 Jun 25 15:42 rootdir/file1
% echo h > rootdir/file1
zsh: operation not permitted: rootdir/file1
% ls -l rootdir/file1
-rwsrwsrwx 1 root root 3 Jun 25 15:42 rootdir/file1
% echo h >> rootdir/file1
% ls -l rootdir/file1
-rwxrwxrwx 1 root root 5 Jun 25 16:34 rootdir/file1

This patch fixes it.

Signed-off-by: WANG Cong <amwang@redhat.com>

Thanks!



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Patch 1/2] selinux: adjust rules for ATTR_FORCE
  2009-08-19  4:44 [V5 Patch 0/2] fix file truncations when both suid and write permissions set Amerigo Wang
@ 2009-08-19  4:44 ` Amerigo Wang
  2009-08-19  4:44 ` [Patch 2/2] vfs: allow file truncations when both suid and write permissions set Amerigo Wang
  1 sibling, 0 replies; 3+ messages in thread
From: Amerigo Wang @ 2009-08-19  4:44 UTC (permalink / raw)
  To: linux-kernel
  Cc: esandeen, eteo, eparis, Amerigo Wang, linux-fsdevel, akpm, sds,
	hirofumi, viro


[PATCH] selinux: adjust rules for ATTR_FORCE

From: Amerigo Wang <amwang@redhat.com>

As suggested by OGAWA Hirofumi in thread: http://lkml.org/lkml/2009/8/7/132,
we should let selinux_inode_setattr() to match our ATTR_* rules.
ATTR_FORCE should not force things like ATTR_SIZE.

Cc: Eric Paris <eparis@redhat.com>
Signed-off-by: WANG Cong <amwang@redhat.com>
[tweaked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> ]
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>

---
 security/selinux/hooks.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff -puN security/selinux/hooks.c~selinux-truncate-fix security/selinux/hooks.c
--- linux-2.6/security/selinux/hooks.c~selinux-truncate-fix	2009-08-18 06:27:58.000000000 +0900
+++ linux-2.6-hirofumi/security/selinux/hooks.c	2009-08-18 16:10:50.000000000 +0900
@@ -2711,12 +2711,18 @@ static int selinux_inode_permission(stru
 static int selinux_inode_setattr(struct dentry *dentry, struct iattr *iattr)
 {
 	const struct cred *cred = current_cred();
+	unsigned int ia_valid = iattr->ia_valid;
 
-	if (iattr->ia_valid & ATTR_FORCE)
-		return 0;
+	/* ATTR_FORCE is just used for ATTR_KILL_S[UG]ID. */
+	if (ia_valid & ATTR_FORCE) {
+		ia_valid &= ~(ATTR_KILL_SUID | ATTR_KILL_SGID | ATTR_MODE |
+			      ATTR_FORCE);
+		if (!ia_valid)
+			return 0;
+	}
 
-	if (iattr->ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
-			       ATTR_ATIME_SET | ATTR_MTIME_SET))
+	if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
+			ATTR_ATIME_SET | ATTR_MTIME_SET | ATTR_TIMES_SET))
 		return dentry_has_perm(cred, NULL, dentry, FILE__SETATTR);
 
 	return dentry_has_perm(cred, NULL, dentry, FILE__WRITE);
_

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Patch 2/2] vfs: allow file truncations when both suid and write permissions set
  2009-08-19  4:44 [V5 Patch 0/2] fix file truncations when both suid and write permissions set Amerigo Wang
  2009-08-19  4:44 ` [Patch 1/2] selinux: adjust rules for ATTR_FORCE Amerigo Wang
@ 2009-08-19  4:44 ` Amerigo Wang
  1 sibling, 0 replies; 3+ messages in thread
From: Amerigo Wang @ 2009-08-19  4:44 UTC (permalink / raw)
  To: linux-kernel
  Cc: esandeen, eteo, eparis, Amerigo Wang, linux-fsdevel, akpm, sds,
	hirofumi, viro


With patch 1/2 applied, now we can just simply add ATTR_FORCE flag, to
remove suid on truncation.

Signed-off-by: WANG Cong <amwang@redhat.com>
Cc: Eric Sandeen <esandeen@redhat.com>
Cc: Eric Paris <eparis@redhat.com>
Cc: Eugene Teo <eteo@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>

---
diff --git a/fs/open.c b/fs/open.c
index dd98e80..40d1fa2 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -199,7 +199,7 @@ out:
 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
 	struct file *filp)
 {
-	int err;
+	int ret;
 	struct iattr newattrs;
 
 	/* Not pretty: "inode->i_size" shouldn't really be signed. But it is. */
@@ -214,12 +214,14 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
 	}
 
 	/* Remove suid/sgid on truncate too */
-	newattrs.ia_valid |= should_remove_suid(dentry);
+	ret = should_remove_suid(dentry);
+	if (ret)
+		newattrs.ia_valid |= ret | ATTR_FORCE;
 
 	mutex_lock(&dentry->d_inode->i_mutex);
-	err = notify_change(dentry, &newattrs);
+	ret = notify_change(dentry, &newattrs);
 	mutex_unlock(&dentry->d_inode->i_mutex);
-	return err;
+	return ret;
 }
 
 static long do_sys_truncate(const char __user *pathname, loff_t length)

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-08-19  4:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-19  4:44 [V5 Patch 0/2] fix file truncations when both suid and write permissions set Amerigo Wang
2009-08-19  4:44 ` [Patch 1/2] selinux: adjust rules for ATTR_FORCE Amerigo Wang
2009-08-19  4:44 ` [Patch 2/2] vfs: allow file truncations when both suid and write permissions set Amerigo Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).