lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 21 Feb 2012 18:04:54 +0000
From:	David Howells <dhowells@...hat.com>
To:	linux-fsdevel@...r.kernel.org, viro@...IV.linux.org.uk,
	valerie.aurora@...il.com
Cc:	linux-kernel@...r.kernel.org, David Howells <dhowells@...hat.com>
Subject: [PATCH 59/73] unionmount: Override creds when copying up a file to
 correctly set ownership [ver #2]

Override the current creds when creating a file for copy up purposes so that
the ownership of that file is set correctly.

Signed-off-by: David Howells <dhowells@...hat.com>
---

 fs/union.c |   22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/fs/union.c b/fs/union.c
index b8ee42d..264da49 100644
--- a/fs/union.c
+++ b/fs/union.c
@@ -556,28 +556,44 @@ int union_copyup_file(struct nameidata *nd, struct path *lower,
 		      struct dentry *dentry, size_t len)
 {
 	struct path *parent = &nd->path;
+	const struct cred *saved_cred;
+	struct cred *override_cred;
 	int error;
 
 	BUG_ON(!mutex_is_locked(&parent->dentry->d_inode->i_mutex));
 
+	override_cred = prepare_kernel_cred(NULL);
+	if (!override_cred)
+		return -ENOMEM;
+
+	override_cred->fsuid = lower->dentry->d_inode->i_uid;
+	override_cred->fsgid = lower->dentry->d_inode->i_gid;
+
+	saved_cred = override_creds(override_cred);
+
 	if (S_ISREG(lower->dentry->d_inode->i_mode)) {
 		error = union_create_file(nd, lower, dentry);
 		if (error)
-			return error;
+			goto out;
 		error = union_copyup_data(lower, parent->mnt, dentry, len);
 	} else if (S_ISLNK(lower->dentry->d_inode->i_mode)) {
-		return union_create_symlink(nd, lower, dentry);
+		error = union_create_symlink(nd, lower, dentry);
+		goto out;
 	} else {
 		/* Don't currently support copyup of special files, though in
 		 * theory there's no reason we couldn't at least copy up
 		 * blockdev, chrdev and FIFO files
 		 */
-		return -EXDEV;
+		error = -EXDEV;
+		goto out;
 	}
 	if (error)
 		/* Most likely error: ENOSPC */
 		vfs_unlink(parent->dentry->d_inode, dentry);
 
+out:
+	revert_creds(saved_cred);
+	put_cred(override_cred);
 	return error;
 }
 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ