@@ -32,8 +32,8 @@ static struct mutex ecryptfs_msg_ctx_lists_mux;
3232static struct hlist_head * ecryptfs_daemon_hash ;
3333struct mutex ecryptfs_daemon_hash_mux ;
3434static int ecryptfs_hash_bits ;
35- #define ecryptfs_uid_hash (uid ) \
36- hash_long((unsigned long)uid , ecryptfs_hash_bits)
35+ #define ecryptfs_current_euid_hash (uid ) \
36+ hash_long((unsigned long)current_euid() , ecryptfs_hash_bits)
3737
3838static u32 ecryptfs_msg_counter ;
3939static struct ecryptfs_msg_ctx * ecryptfs_msg_ctx_arr ;
@@ -105,26 +105,24 @@ void ecryptfs_msg_ctx_alloc_to_free(struct ecryptfs_msg_ctx *msg_ctx)
105105
106106/**
107107 * ecryptfs_find_daemon_by_euid
108- * @euid: The effective user id which maps to the desired daemon id
109- * @user_ns: The namespace in which @euid applies
110108 * @daemon: If return value is zero, points to the desired daemon pointer
111109 *
112110 * Must be called with ecryptfs_daemon_hash_mux held.
113111 *
114- * Search the hash list for the given user id.
112+ * Search the hash list for the current effective user id.
115113 *
116114 * Returns zero if the user id exists in the list; non-zero otherwise.
117115 */
118- int ecryptfs_find_daemon_by_euid (struct ecryptfs_daemon * * daemon , uid_t euid ,
119- struct user_namespace * user_ns )
116+ int ecryptfs_find_daemon_by_euid (struct ecryptfs_daemon * * daemon )
120117{
121118 struct hlist_node * elem ;
122119 int rc ;
123120
124121 hlist_for_each_entry (* daemon , elem ,
125- & ecryptfs_daemon_hash [ecryptfs_uid_hash (euid )],
126- euid_chain ) {
127- if ((* daemon )-> euid == euid && (* daemon )-> user_ns == user_ns ) {
122+ & ecryptfs_daemon_hash [ecryptfs_current_euid_hash ()],
123+ euid_chain ) {
124+ if ((* daemon )-> file -> f_cred -> euid == current_euid () &&
125+ (* daemon )-> file -> f_cred -> user_ns == current_user_ns ()) {
128126 rc = 0 ;
129127 goto out ;
130128 }
@@ -137,18 +135,15 @@ int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon, uid_t euid,
137135/**
138136 * ecryptfs_spawn_daemon - Create and initialize a new daemon struct
139137 * @daemon: Pointer to set to newly allocated daemon struct
140- * @euid: Effective user id for the daemon
141- * @user_ns: The namespace in which @euid applies
142- * @pid: Process id for the daemon
138+ * @file: File used when opening /dev/ecryptfs
143139 *
144140 * Must be called ceremoniously while in possession of
145141 * ecryptfs_sacred_daemon_hash_mux
146142 *
147143 * Returns zero on success; non-zero otherwise
148144 */
149145int
150- ecryptfs_spawn_daemon (struct ecryptfs_daemon * * daemon , uid_t euid ,
151- struct user_namespace * user_ns , struct pid * pid )
146+ ecryptfs_spawn_daemon (struct ecryptfs_daemon * * daemon , struct file * file )
152147{
153148 int rc = 0 ;
154149
@@ -159,16 +154,13 @@ ecryptfs_spawn_daemon(struct ecryptfs_daemon **daemon, uid_t euid,
159154 "GFP_KERNEL memory\n" , __func__ , sizeof (* * daemon ));
160155 goto out ;
161156 }
162- (* daemon )-> euid = euid ;
163- (* daemon )-> user_ns = get_user_ns (user_ns );
164- (* daemon )-> pid = get_pid (pid );
165- (* daemon )-> task = current ;
157+ (* daemon )-> file = file ;
166158 mutex_init (& (* daemon )-> mux );
167159 INIT_LIST_HEAD (& (* daemon )-> msg_ctx_out_queue );
168160 init_waitqueue_head (& (* daemon )-> wait );
169161 (* daemon )-> num_queued_msg_ctx = 0 ;
170162 hlist_add_head (& (* daemon )-> euid_chain ,
171- & ecryptfs_daemon_hash [ecryptfs_uid_hash ( euid )]);
163+ & ecryptfs_daemon_hash [ecryptfs_current_euid_hash ( )]);
172164out :
173165 return rc ;
174166}
@@ -188,9 +180,6 @@ int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon)
188180 if ((daemon -> flags & ECRYPTFS_DAEMON_IN_READ )
189181 || (daemon -> flags & ECRYPTFS_DAEMON_IN_POLL )) {
190182 rc = - EBUSY ;
191- printk (KERN_WARNING "%s: Attempt to destroy daemon with pid "
192- "[0x%p], but it is in the midst of a read or a poll\n" ,
193- __func__ , daemon -> pid );
194183 mutex_unlock (& daemon -> mux );
195184 goto out ;
196185 }
@@ -203,12 +192,6 @@ int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon)
203192 ecryptfs_msg_ctx_alloc_to_free (msg_ctx );
204193 }
205194 hlist_del (& daemon -> euid_chain );
206- if (daemon -> task )
207- wake_up_process (daemon -> task );
208- if (daemon -> pid )
209- put_pid (daemon -> pid );
210- if (daemon -> user_ns )
211- put_user_ns (daemon -> user_ns );
212195 mutex_unlock (& daemon -> mux );
213196 kzfree (daemon );
214197out :
@@ -219,8 +202,6 @@ int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon)
219202 * ecryptfs_process_reponse
220203 * @msg: The ecryptfs message received; the caller should sanity check
221204 * msg->data_len and free the memory
222- * @pid: The process ID of the userspace application that sent the
223- * message
224205 * @seq: The sequence number of the message; must match the sequence
225206 * number for the existing message context waiting for this
226207 * response
@@ -239,16 +220,11 @@ int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon)
239220 *
240221 * Returns zero on success; non-zero otherwise
241222 */
242- int ecryptfs_process_response (struct ecryptfs_message * msg , uid_t euid ,
243- struct user_namespace * user_ns , struct pid * pid ,
244- u32 seq )
223+ int ecryptfs_process_response (struct ecryptfs_daemon * daemon ,
224+ struct ecryptfs_message * msg , u32 seq )
245225{
246- struct ecryptfs_daemon * uninitialized_var (daemon );
247226 struct ecryptfs_msg_ctx * msg_ctx ;
248227 size_t msg_size ;
249- struct nsproxy * nsproxy ;
250- struct user_namespace * tsk_user_ns ;
251- uid_t ctx_euid ;
252228 int rc ;
253229
254230 if (msg -> index >= ecryptfs_message_buf_len ) {
@@ -261,51 +237,6 @@ int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t euid,
261237 }
262238 msg_ctx = & ecryptfs_msg_ctx_arr [msg -> index ];
263239 mutex_lock (& msg_ctx -> mux );
264- mutex_lock (& ecryptfs_daemon_hash_mux );
265- rcu_read_lock ();
266- nsproxy = task_nsproxy (msg_ctx -> task );
267- if (nsproxy == NULL ) {
268- rc = - EBADMSG ;
269- printk (KERN_ERR "%s: Receiving process is a zombie. Dropping "
270- "message.\n" , __func__ );
271- rcu_read_unlock ();
272- mutex_unlock (& ecryptfs_daemon_hash_mux );
273- goto wake_up ;
274- }
275- tsk_user_ns = __task_cred (msg_ctx -> task )-> user_ns ;
276- ctx_euid = task_euid (msg_ctx -> task );
277- rc = ecryptfs_find_daemon_by_euid (& daemon , ctx_euid , tsk_user_ns );
278- rcu_read_unlock ();
279- mutex_unlock (& ecryptfs_daemon_hash_mux );
280- if (rc ) {
281- rc = - EBADMSG ;
282- printk (KERN_WARNING "%s: User [%d] received a "
283- "message response from process [0x%p] but does "
284- "not have a registered daemon\n" , __func__ ,
285- ctx_euid , pid );
286- goto wake_up ;
287- }
288- if (ctx_euid != euid ) {
289- rc = - EBADMSG ;
290- printk (KERN_WARNING "%s: Received message from user "
291- "[%d]; expected message from user [%d]\n" , __func__ ,
292- euid , ctx_euid );
293- goto unlock ;
294- }
295- if (tsk_user_ns != user_ns ) {
296- rc = - EBADMSG ;
297- printk (KERN_WARNING "%s: Received message from user_ns "
298- "[0x%p]; expected message from user_ns [0x%p]\n" ,
299- __func__ , user_ns , tsk_user_ns );
300- goto unlock ;
301- }
302- if (daemon -> pid != pid ) {
303- rc = - EBADMSG ;
304- printk (KERN_ERR "%s: User [%d] sent a message response "
305- "from an unrecognized process [0x%p]\n" ,
306- __func__ , ctx_euid , pid );
307- goto unlock ;
308- }
309240 if (msg_ctx -> state != ECRYPTFS_MSG_CTX_STATE_PENDING ) {
310241 rc = - EINVAL ;
311242 printk (KERN_WARNING "%s: Desired context element is not "
@@ -328,9 +259,8 @@ int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t euid,
328259 }
329260 memcpy (msg_ctx -> msg , msg , msg_size );
330261 msg_ctx -> state = ECRYPTFS_MSG_CTX_STATE_DONE ;
331- rc = 0 ;
332- wake_up :
333262 wake_up_process (msg_ctx -> task );
263+ rc = 0 ;
334264unlock :
335265 mutex_unlock (& msg_ctx -> mux );
336266out :
@@ -352,14 +282,11 @@ ecryptfs_send_message_locked(char *data, int data_len, u8 msg_type,
352282 struct ecryptfs_msg_ctx * * msg_ctx )
353283{
354284 struct ecryptfs_daemon * daemon ;
355- uid_t euid = current_euid ();
356285 int rc ;
357286
358- rc = ecryptfs_find_daemon_by_euid (& daemon , euid , current_user_ns () );
287+ rc = ecryptfs_find_daemon_by_euid (& daemon );
359288 if (rc || !daemon ) {
360289 rc = - ENOTCONN ;
361- printk (KERN_ERR "%s: User [%d] does not have a daemon "
362- "registered\n" , __func__ , euid );
363290 goto out ;
364291 }
365292 mutex_lock (& ecryptfs_msg_ctx_lists_mux );
0 commit comments