mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: linux-security-module@vger.kernel.org,
	David Howells <dhowells@redhat.com>,
	Serge Hallyn <serue@us.ibm.com>,
	Mike Halcrow <mhalcrow@us.ibm.com>,
	Phillip Hellewell <phillip@hellewell.homeip.net>,
	ecryptfs-devel@lists.sourceforge.net
Subject: [PATCH 22/59] CRED: Wrap task credential accesses in the eCryptFS filesystem
Date: Wed, 27 Aug 2008 14:47:35 +0100	[thread overview]
Message-ID: <20080827134735.19980.88570.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20080827134541.19980.61042.stgit@warthog.procyon.org.uk>

Wrap access to task credentials so that they can be separated more easily from
the task_struct during the introduction of COW creds.

Change most current->(|e|s|fs)[ug]id to current_(|e|s|fs)[ug]id().

Change some task->e?[ug]id to task_e?[ug]id().  In some places it makes more
sense to use RCU directly rather than a convenient wrapper; these will be
addressed by later patches.

Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: James Morris <jmorris@namei.org>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Cc: Mike Halcrow <mhalcrow@us.ibm.com>
Cc: Phillip Hellewell <phillip@hellewell.homeip.net>
Cc: ecryptfs-devel@lists.sourceforge.net
---

 fs/ecryptfs/messaging.c |   18 ++++++++++--------
 fs/ecryptfs/miscdev.c   |   20 ++++++++++++--------
 2 files changed, 22 insertions(+), 16 deletions(-)


diff --git a/fs/ecryptfs/messaging.c b/fs/ecryptfs/messaging.c
index 1b5c200..92bf606 100644
--- a/fs/ecryptfs/messaging.c
+++ b/fs/ecryptfs/messaging.c
@@ -377,6 +377,7 @@ int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t euid,
 	size_t msg_size;
 	struct nsproxy *nsproxy;
 	struct user_namespace *current_user_ns;
+	uid_t ctx_euid;
 	int rc;
 
 	if (msg->index >= ecryptfs_message_buf_len) {
@@ -401,8 +402,8 @@ int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t euid,
 		goto wake_up;
 	}
 	current_user_ns = nsproxy->user_ns;
-	rc = ecryptfs_find_daemon_by_euid(&daemon, msg_ctx->task->euid,
-					  current_user_ns);
+	ctx_euid = task_euid(msg_ctx->task);
+	rc = ecryptfs_find_daemon_by_euid(&daemon, ctx_euid, current_user_ns);
 	rcu_read_unlock();
 	mutex_unlock(&ecryptfs_daemon_hash_mux);
 	if (rc) {
@@ -410,14 +411,14 @@ int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t euid,
 		printk(KERN_WARNING "%s: User [%d] received a "
 		       "message response from process [0x%p] but does "
 		       "not have a registered daemon\n", __func__,
-		       msg_ctx->task->euid, pid);
+		       ctx_euid, pid);
 		goto wake_up;
 	}
-	if (msg_ctx->task->euid != euid) {
+	if (ctx_euid != euid) {
 		rc = -EBADMSG;
 		printk(KERN_WARNING "%s: Received message from user "
 		       "[%d]; expected message from user [%d]\n", __func__,
-		       euid, msg_ctx->task->euid);
+		       euid, ctx_euid);
 		goto unlock;
 	}
 	if (current_user_ns != user_ns) {
@@ -431,7 +432,7 @@ int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t euid,
 		rc = -EBADMSG;
 		printk(KERN_ERR "%s: User [%d] sent a message response "
 		       "from an unrecognized process [0x%p]\n",
-		       __func__, msg_ctx->task->euid, pid);
+		       __func__, ctx_euid, pid);
 		goto unlock;
 	}
 	if (msg_ctx->state != ECRYPTFS_MSG_CTX_STATE_PENDING) {
@@ -482,14 +483,15 @@ ecryptfs_send_message_locked(unsigned int transport, char *data, int data_len,
 			     u8 msg_type, struct ecryptfs_msg_ctx **msg_ctx)
 {
 	struct ecryptfs_daemon *daemon;
+	uid_t euid = current_euid();
 	int rc;
 
-	rc = ecryptfs_find_daemon_by_euid(&daemon, current->euid,
+	rc = ecryptfs_find_daemon_by_euid(&daemon, euid,
 					  current->nsproxy->user_ns);
 	if (rc || !daemon) {
 		rc = -ENOTCONN;
 		printk(KERN_ERR "%s: User [%d] does not have a daemon "
-		       "registered\n", __func__, current->euid);
+		       "registered\n", __func__, euid);
 		goto out;
 	}
 	mutex_lock(&ecryptfs_msg_ctx_lists_mux);
diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
index b484792..047ac60 100644
--- a/fs/ecryptfs/miscdev.c
+++ b/fs/ecryptfs/miscdev.c
@@ -42,11 +42,12 @@ ecryptfs_miscdev_poll(struct file *file, poll_table *pt)
 {
 	struct ecryptfs_daemon *daemon;
 	unsigned int mask = 0;
+	uid_t euid = current_euid();
 	int rc;
 
 	mutex_lock(&ecryptfs_daemon_hash_mux);
 	/* TODO: Just use file->private_data? */
-	rc = ecryptfs_find_daemon_by_euid(&daemon, current->euid,
+	rc = ecryptfs_find_daemon_by_euid(&daemon, euid,
 					  current->nsproxy->user_ns);
 	BUG_ON(rc || !daemon);
 	mutex_lock(&daemon->mux);
@@ -83,6 +84,7 @@ static int
 ecryptfs_miscdev_open(struct inode *inode, struct file *file)
 {
 	struct ecryptfs_daemon *daemon = NULL;
+	uid_t euid = current_euid();
 	int rc;
 
 	mutex_lock(&ecryptfs_daemon_hash_mux);
@@ -93,10 +95,10 @@ ecryptfs_miscdev_open(struct inode *inode, struct file *file)
 		       "count; rc = [%d]\n", __func__, rc);
 		goto out_unlock_daemon_list;
 	}
-	rc = ecryptfs_find_daemon_by_euid(&daemon, current->euid,
+	rc = ecryptfs_find_daemon_by_euid(&daemon, euid,
 					  current->nsproxy->user_ns);
 	if (rc || !daemon) {
-		rc = ecryptfs_spawn_daemon(&daemon, current->euid,
+		rc = ecryptfs_spawn_daemon(&daemon, euid,
 					   current->nsproxy->user_ns,
 					   task_pid(current));
 		if (rc) {
@@ -147,10 +149,11 @@ static int
 ecryptfs_miscdev_release(struct inode *inode, struct file *file)
 {
 	struct ecryptfs_daemon *daemon = NULL;
+	uid_t euid = current_euid();
 	int rc;
 
 	mutex_lock(&ecryptfs_daemon_hash_mux);
-	rc = ecryptfs_find_daemon_by_euid(&daemon, current->euid,
+	rc = ecryptfs_find_daemon_by_euid(&daemon, euid,
 					  current->nsproxy->user_ns);
 	BUG_ON(rc || !daemon);
 	mutex_lock(&daemon->mux);
@@ -246,11 +249,12 @@ ecryptfs_miscdev_read(struct file *file, char __user *buf, size_t count,
 	char packet_length[3];
 	size_t i;
 	size_t total_length;
+	uid_t euid = current_euid();
 	int rc;
 
 	mutex_lock(&ecryptfs_daemon_hash_mux);
 	/* TODO: Just use file->private_data? */
-	rc = ecryptfs_find_daemon_by_euid(&daemon, current->euid,
+	rc = ecryptfs_find_daemon_by_euid(&daemon, euid,
 					  current->nsproxy->user_ns);
 	BUG_ON(rc || !daemon);
 	mutex_lock(&daemon->mux);
@@ -290,7 +294,7 @@ check_list:
 		 * message from the queue; try again */
 		goto check_list;
 	}
-	BUG_ON(current->euid != daemon->euid);
+	BUG_ON(euid != daemon->euid);
 	BUG_ON(current->nsproxy->user_ns != daemon->user_ns);
 	BUG_ON(task_pid(current) != daemon->pid);
 	msg_ctx = list_first_entry(&daemon->msg_ctx_out_queue,
@@ -414,6 +418,7 @@ ecryptfs_miscdev_write(struct file *file, const char __user *buf,
 	size_t packet_size, packet_size_length, i;
 	ssize_t sz = 0;
 	char *data;
+	uid_t euid = current_euid();
 	int rc;
 
 	if (count == 0)
@@ -463,8 +468,7 @@ ecryptfs_miscdev_write(struct file *file, const char __user *buf,
 			goto out_free;
 		}
 		rc = ecryptfs_miscdev_response(&data[i], packet_size,
-					       current->euid,
-					       current->nsproxy->user_ns,
+					       euid, current->nsproxy->user_ns,
 					       task_pid(current), seq);
 		if (rc)
 			printk(KERN_WARNING "%s: Failed to deliver miscdev "


  parent reply	other threads:[~2008-08-27 13:50 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-27 13:45 [PATCH 00/59] Introduce credentials David Howells
2008-08-27 13:33 ` Alan Cox
2008-08-27 13:45 ` [PATCH 01/59] CRED: Wrap task credential accesses in the IA64 arch David Howells
2008-08-27 14:55   ` Artem Bityutskiy
2008-08-27 15:24   ` David Howells
2008-08-27 23:21     ` Stephen Rothwell
2008-08-27 13:45 ` [PATCH 02/59] CRED: Wrap task credential accesses in the MIPS arch David Howells
2008-08-27 13:45 ` [PATCH 03/59] CRED: Wrap task credential accesses in the PA-RISC arch David Howells
2008-08-27 22:19   ` Kyle McMartin
2008-08-27 13:46 ` [PATCH 04/59] CRED: Wrap task credential accesses in the PowerPC arch David Howells
2008-08-27 23:45   ` Benjamin Herrenschmidt
2008-08-27 13:46 ` [PATCH 05/59] CRED: Wrap task credential accesses in the S390 arch David Howells
2008-08-27 13:46 ` [PATCH 06/59] CRED: Wrap task credential accesses in the x86 arch David Howells
2008-08-27 13:46 ` [PATCH 07/59] CRED: Wrap task credential accesses in the block loopback driver David Howells
2008-08-27 13:46 ` [PATCH 08/59] CRED: Wrap task credential accesses in the tty driver David Howells
2008-08-27 13:46 ` [PATCH 09/59] CRED: Wrap task credential accesses in the DRM driver David Howells
2008-09-02  1:03   ` Dave Airlie
2008-08-27 13:46 ` [PATCH 10/59] CRED: Wrap task credential accesses in the ISDN drivers David Howells
2008-08-27 17:51   ` Karsten Keil
2008-08-27 13:46 ` [PATCH 11/59] CRED: Wrap task credential accesses in video input drivers David Howells
2008-08-29 22:32   ` Mauro Carvalho Chehab
2008-08-27 13:46 ` [PATCH 12/59] CRED: Wrap task credential accesses in the network device drivers David Howells
2008-08-27 13:46 ` [PATCH 13/59] CRED: Wrap task credential accesses in the USB driver David Howells
2008-08-27 13:46 ` [PATCH 14/59] CRED: Wrap task credential accesses in 9P2000 filesystem David Howells
2008-08-28 17:59   ` Eric Van Hensbergen
2008-08-27 13:46 ` [PATCH 15/59] CRED: Wrap task credential accesses in the AFFS filesystem David Howells
2008-08-27 13:47 ` [PATCH 16/59] CRED: Wrap task credential accesses in the autofs filesystem David Howells
2008-08-27 13:47 ` [PATCH 17/59] CRED: Wrap task credential accesses in the autofs4 filesystem David Howells
2008-08-27 13:47 ` [PATCH 18/59] CRED: Wrap task credential accesses in the BFS filesystem David Howells
2008-08-27 13:47 ` [PATCH 19/59] CRED: Wrap task credential accesses in the CIFS filesystem David Howells
2008-08-27 13:47 ` [PATCH 20/59] CRED: Wrap task credential accesses in the Coda filesystem David Howells
2008-08-27 13:47 ` [PATCH 21/59] CRED: Wrap task credential accesses in the devpts filesystem David Howells
2008-08-27 13:47 ` David Howells [this message]
2008-08-27 13:47 ` [PATCH 23/59] CRED: Wrap task credential accesses in the Ext2 filesystem David Howells
2008-08-27 13:47 ` [PATCH 24/59] CRED: Wrap task credential accesses in the Ext3 filesystem David Howells
2008-08-27 13:47 ` [PATCH 25/59] CRED: Wrap task credential accesses in the Ext4 filesystem David Howells
2008-08-27 13:47 ` [PATCH 26/59] CRED: Wrap task credential accesses in the FAT filesystem David Howells
2008-08-27 14:12   ` OGAWA Hirofumi
2008-08-27 13:48 ` [PATCH 27/59] CRED: Wrap task credential accesses in the FUSE filesystem David Howells
2008-08-27 13:48 ` [PATCH 28/59] CRED: Wrap task credential accesses in the GFS2 filesystem David Howells
2008-08-27 13:48 ` [PATCH 29/59] CRED: Wrap task credential accesses in the HFS filesystem David Howells
2008-08-27 13:48 ` [PATCH 30/59] CRED: Wrap task credential accesses in the HFSplus filesystem David Howells
2008-08-27 13:48 ` [PATCH 31/59] CRED: Wrap task credential accesses in the HPFS filesystem David Howells
2008-08-27 13:48 ` [PATCH 32/59] CRED: Wrap task credential accesses in the hugetlbfs filesystem David Howells
2008-08-27 13:48 ` [PATCH 33/59] CRED: Wrap task credential accesses in the JFFS2 filesystem David Howells
2008-08-27 13:48 ` [PATCH 34/59] CRED: Wrap task credential accesses in the JFS filesystem David Howells
2008-08-27 14:31   ` Dave Kleikamp
2008-08-27 13:48 ` [PATCH 35/59] CRED: Wrap task credential accesses in the Minix filesystem David Howells
2008-08-27 13:48 ` [PATCH 36/59] CRED: Wrap task credential accesses in the NCPFS filesystem David Howells
2008-08-27 13:48 ` [PATCH 37/59] CRED: Wrap task credential accesses in the NFS daemon David Howells
2008-08-27 13:48 ` [PATCH 38/59] CRED: Wrap task credential accesses in the OCFS2 filesystem David Howells
2008-08-27 23:04   ` Mark Fasheh
2008-08-27 13:49 ` [PATCH 39/59] CRED: Wrap task credential accesses in the OMFS filesystem David Howells
2008-08-27 13:49 ` [PATCH 40/59] CRED: Wrap task credential accesses in the RAMFS filesystem David Howells
2008-08-27 13:49 ` [PATCH 41/59] CRED: Wrap task credential accesses in the ReiserFS filesystem David Howells
2008-08-27 13:49 ` [PATCH 42/59] CRED: Wrap task credential accesses in the SMBFS filesystem David Howells
2008-08-27 13:49 ` [PATCH 43/59] CRED: Wrap task credential accesses in the SYSV filesystem David Howells
2008-08-27 13:49 ` [PATCH 44/59] CRED: Wrap task credential accesses in the UBIFS filesystem David Howells
2008-08-27 13:49 ` [PATCH 45/59] CRED: Wrap task credential accesses in the UDF filesystem David Howells
2008-08-27 14:44   ` Jan Kara
2008-08-27 13:49 ` [PATCH 46/59] CRED: Wrap task credential accesses in the UFS filesystem David Howells
2008-08-27 13:49 ` [PATCH 47/59] CRED: Wrap task credential accesses in the XFS filesystem David Howells
2008-08-27 13:49 ` [PATCH 48/59] CRED: Wrap task credential accesses in the filesystem subsystem David Howells
2008-08-27 13:49 ` [PATCH 49/59] CRED: Wrap task credential accesses in the SYSV IPC subsystem David Howells
2008-08-27 13:50 ` [PATCH 50/59] CRED: Wrap task credential accesses in the AX25 protocol David Howells
2008-08-27 13:50 ` [PATCH 51/59] CRED: Wrap task credential accesses in the IPv6 protocol David Howells
2008-08-27 13:50 ` [PATCH 52/59] CRED: Wrap task credential accesses in the netrom protocol David Howells
2008-08-27 13:50 ` [PATCH 53/59] CRED: Wrap task credential accesses in the ROSE protocol David Howells
2008-08-27 13:50 ` [PATCH 54/59] CRED: Wrap task credential accesses in the SunRPC protocol David Howells
2008-08-27 13:50 ` [PATCH 55/59] CRED: Wrap task credential accesses in the UNIX socket protocol David Howells
2008-08-27 13:50 ` [PATCH 56/59] CRED: Wrap task credential accesses in the networking subsystem David Howells
2008-08-27 13:50 ` [PATCH 57/59] CRED: Wrap task credential accesses in the key management code David Howells
2008-08-27 13:50 ` [PATCH 58/59] CRED: Wrap task credential accesses in the capabilities code David Howells
2008-08-27 13:50 ` [PATCH 59/59] CRED: Wrap task credential accesses in the core kernel David Howells
2008-08-27 14:24 ` [PATCH 00/59] Introduce credentials David Howells
2008-08-27 16:39   ` Alan Cox
2008-08-28  9:19   ` David Howells
2008-08-28  9:45     ` Alan Cox
2008-08-28 20:28       ` Paul E. McKenney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080827134735.19980.88570.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=ecryptfs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mhalcrow@us.ibm.com \
    --cc=phillip@hellewell.homeip.net \
    --cc=serue@us.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®