Skip to contentSkip to conversation

ptrace: tracehook_unsafe_exec: remove the stale comment

PATCH In review Oleg Nesterov 4 participants 12 messages Apr 23, 2009 – Apr 27, 2009

Subsystems (2)
lore
Share & tools
lore

Oleg Nesterov

author maintainer
#0 lore raw

PATCH 1/1 ptrace: tracehook_unsafe_exec: remove the stale comment

tracehook_unsafe_exec() doesn't need task_lock(), remove the old comment.

include/linux/tracehook.h renamed from include/linux/tracehook.h~ +0 -2
@@ -142,8 +142,6 @@ static inline void tracehook_report_sysc
  * @task:		current task doing exec
  *
  * Return %LSM_UNSAFE_* bits applied to an exec because of tracing.
- *
- * Called with task_lock() held on @task.
  */
 static inline int tracehook_unsafe_exec(struct task_struct *task)
 {
#1 lore raw
Quoted 1 line

tracehook_unsafe_exec() doesn't need task_lock(), remove the old comment.

Please make it instead say that cred_exec_mutex is held by the caller through the exec. That locking takes the place of what task_lock() was doing before (e.g. interlock with PTRACE_ATTACH).

Thanks,
Roland

author maintainer
#2 lore raw

ptrace && cred_exec_mutex (Was: [PATCH] ptrace: tracehook_unsafe_exec: remove the stale comment)

(change subject, add more CCs)

Quoted 5 lines · Roland McGrath
Quoted 2 lines

tracehook_unsafe_exec() doesn't need task_lock(), remove the old comment.

Please make it instead say that cred_exec_mutex is held by the caller through the exec.

Yes. Except it looks like ->cred_exec_mutex is never used in fact.

ptrace_attach() takes current->cred_exec_mutex ? iow, ptrace and exec use different locks ?

Oleg.

#3 lore raw

Re: ptrace && cred_exec_mutex (Was: [PATCH] ptrace: tracehook_unsafe_exec: remove the stale comment)

Quoted 6 lines

(change subject, add more CCs)

Quoted 3 lines · Roland McGrath
Quoted 2 lines

tracehook_unsafe_exec() doesn't need task_lock(), remove the old comment.

Quoted 7 lines
Quoted 2 lines

Please make it instead say that cred_exec_mutex is held by the caller through the exec.

Yes. Except it looks like ->cred_exec_mutex is never used in fact.

ptrace_attach() takes current->cred_exec_mutex ? iow, ptrace and exec use different locks ?

Good point! That sure looks broken to me. David?

Either that should be task->cred_exec_mutex, or Oleg and I are completely confused about what cred_exec_mutex is meant for.

Thanks,
Roland

#4 lore raw

Re: ptrace && cred_exec_mutex (Was: [PATCH] ptrace: tracehook_unsafe_exec: remove the stale comment)

In reply to Oleg Nesterov
Quoted 1 line · Oleg Nesterov

Yes. Except it looks like ->cred_exec_mutex is never used in fact.

I must to be missing something... I see that:

	int ptrace_attach(struct task_struct *task)
	{
	...
		/* Protect exec's credential calculations against our interference;
		 * SUID, SGID and LSM creds get determined differently under ptrace.
		 */
		retval = mutex_lock_interruptible(&current->cred_exec_mutex);
	...
	}

And:

	int do_execve(...)
	{
	...
		retval = mutex_lock_interruptible(&current->cred_exec_mutex);
		if (retval < 0)
			goto out_free;
	...
	}

So how is it not used?

David

author maintainer
#5 lore raw

Re: ptrace && cred_exec_mutex (Was: [PATCH] ptrace: tracehook_unsafe_exec: remove the stale comment)

Quoted 19 lines · David Howells
Quoted 1 line · Oleg Nesterov

Yes. Except it looks like ->cred_exec_mutex is never used in fact.

I must to be missing something... I see that:

	int ptrace_attach(struct task_struct *task)
	{
	...
		/* Protect exec's credential calculations against our interference;
		 * SUID, SGID and LSM creds get determined differently under ptrace.
		 */
		retval = mutex_lock_interruptible(&current->cred_exec_mutex);
	...
	}

And:

Quoted 8 lines
	int do_execve(...)
	{
	...
		retval = mutex_lock_interruptible(&current->cred_exec_mutex);
		if (retval < 0)
			goto out_free;
	...
	}

Sorry David, I was very unclear.

These 2 current's are different tasks, and hence we take to unrelated locks.

We can never block taking current->cred_exec_mutex because nobody else touches this mutex, we always use current. This means this lock is "nop".

Unless I missed something, ptrace_attach() should take task->cred_exec_mutex.

Oleg.

#6 lore raw

Re: ptrace && cred_exec_mutex (Was: [PATCH] ptrace: tracehook_unsafe_exec: remove the stale comment)

Quoted 1 line · Oleg Nesterov

Unless I missed something, ptrace_attach() should take task->cred_exec_mutex.

Bah! Yes.

David

author maintainer
#7 lore raw

PATCH 1/1 ptrace: ptrace_attach: fix the usage of ->cred_exec_mutex

ptrace_attach() needs task->cred_exec_mutex, not current->cred_exec_mutex.

kernel/ptrace.c renamed from kernel/ptrace.c~ +2 -2
@@ -188,7 +188,7 @@ int ptrace_attach(struct task_struct *ta
 	/* Protect exec's credential calculations against our interference;
 	 * SUID, SGID and LSM creds get determined differently under ptrace.
 	 */
-	retval = mutex_lock_interruptible(&current->cred_exec_mutex);
+	retval = mutex_lock_interruptible(&task->cred_exec_mutex);
 	if (retval  < 0)
 		goto out;
 
@@ -232,7 +232,7 @@ repeat:
 bad:
 	write_unlock_irqrestore(&tasklist_lock, flags);
 	task_unlock(task);
-	mutex_unlock(&current->cred_exec_mutex);
+	mutex_unlock(&task->cred_exec_mutex);
 out:
 	return retval;
 }
#10 lore raw

[GIT] ptrace: ptrace_attach: fix the usage of ->cred_exec_mutex

Here's the patch ready to pull for 2.6.30.

The following changes since commit ce8a7424d23a36f043d0de8484f888971c831119:
Tim Abbott (1):
sparc: convert to use __HEAD and HEAD_TEXT macros.

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6 for-linus

Oleg Nesterov (1):

      ptrace: ptrace_attach: fix the usage of ->cred_exec_mutex
 kernel/ptrace.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
Signature · 2 lines
James Morris
<[email protected]>
author maintainer
#11 lore raw

PATCH 1/1 ptrace-tracehook_unsafe_exec-remove-the-stale-comment-fix

In reply to Roland McGrath

(on top of ptrace-tracehook_unsafe_exec-remove-the-stale-comment.patch)

Quoted 5 lines · Roland McGrath
Quoted 2 lines

tracehook_unsafe_exec() doesn't need task_lock(), remove the old comment.

Please make it instead say that cred_exec_mutex is held by the caller through the exec.

Thanks.

include/linux/tracehook.h renamed from include/linux/tracehook.h~COMMENT_FIX +2 -0
@@ -142,6 +142,8 @@ static inline void tracehook_report_sysc
  * @task:		current task doing exec
  *
  * Return %LSM_UNSAFE_* bits applied to an exec because of tracing.
+ *
+ * task->cred_exec_mutex is held by the caller through the do_execve().
  */
 static inline int tracehook_unsafe_exec(struct task_struct *task)
 {