Commit c4a4d603 authored by Eric W. Biederman's avatar Eric W. Biederman
Browse files

userns: Use cred->user_ns instead of cred->user->user_ns



Optimize performance and prepare for the removal of the user_ns reference
from user_struct.  Remove the slow long walk through cred->user->user_ns and
instead go straight to cred->user_ns.

Acked-by: default avatarSerge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
parent 7e6bd8fa
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -303,7 +303,7 @@ int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t euid,
		mutex_unlock(&ecryptfs_daemon_hash_mux);
		goto wake_up;
	}
	tsk_user_ns = __task_cred(msg_ctx->task)->user->user_ns;
	tsk_user_ns = __task_cred(msg_ctx->task)->user_ns;
	ctx_euid = task_euid(msg_ctx->task);
	rc = ecryptfs_find_daemon_by_euid(&daemon, ctx_euid, tsk_user_ns);
	rcu_read_unlock();
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
	ipcns_notify(IPCNS_CREATED);
	register_ipcns_notifier(ns);

	ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
	ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));

	return ns;
}
+2 −2
Original line number Diff line number Diff line
@@ -198,7 +198,7 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
		return 0;
	rcu_read_lock();
	tcred = __task_cred(task);
	if (cred->user->user_ns == tcred->user->user_ns &&
	if (cred->user_ns == tcred->user_ns &&
	    (cred->uid == tcred->euid &&
	     cred->uid == tcred->suid &&
	     cred->uid == tcred->uid  &&
@@ -206,7 +206,7 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
	     cred->gid == tcred->sgid &&
	     cred->gid == tcred->gid))
		goto ok;
	if (ptrace_has_cap(tcred->user->user_ns, mode))
	if (ptrace_has_cap(tcred->user_ns, mode))
		goto ok;
	rcu_read_unlock();
	return -EPERM;
+1 −1
Original line number Diff line number Diff line
@@ -4042,7 +4042,7 @@ static bool check_same_owner(struct task_struct *p)

	rcu_read_lock();
	pcred = __task_cred(p);
	if (cred->user->user_ns == pcred->user->user_ns)
	if (cred->user_ns == pcred->user_ns)
		match = (cred->euid == pcred->euid ||
			 cred->euid == pcred->uid);
	else
+2 −2
Original line number Diff line number Diff line
@@ -767,14 +767,14 @@ static int kill_ok_by_cred(struct task_struct *t)
	const struct cred *cred = current_cred();
	const struct cred *tcred = __task_cred(t);

	if (cred->user->user_ns == tcred->user->user_ns &&
	if (cred->user_ns == tcred->user_ns &&
	    (cred->euid == tcred->suid ||
	     cred->euid == tcred->uid ||
	     cred->uid  == tcred->suid ||
	     cred->uid  == tcred->uid))
		return 1;

	if (ns_capable(tcred->user->user_ns, CAP_KILL))
	if (ns_capable(tcred->user_ns, CAP_KILL))
		return 1;

	return 0;
Loading