Skip to contentSkip to conversation

Yama: access current->comm directly

PATCH Superseded Kees Cook 3 participants 4 messages Jul 30, 2012

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 Yama: access current->comm directly

The core ptrace access checking routine already holds the task lock, so there is no need to use get_task_comm() which just tries to take the lock again. Drop its use and access current->comm directly.

---
 security/yama/yama_lsm.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
security/yama/yama_lsm.c +2 -4
index 83554ee..20a68ca 100644
@@ -279,12 +279,10 @@ static int yama_ptrace_access_check(struct task_struct *child,
 	}
 
 	if (rc) {
-		char name[sizeof(current->comm)];
+		/* task_lock is held by the caller, so use comm directly. */
 		printk_ratelimited(KERN_NOTICE
 			"ptrace of pid %d was attempted by: %s (pid %d)\n",
-			child->pid,
-			get_task_comm(name, current),
-			current->pid);
+			child->pid, current->comm, current->pid);
 	}
 
 	return rc;
Signature · 6 lines
1.7.0.4


-- 
Kees Cook
Chrome OS Security
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Kees Cook

The core ptrace access checking routine already holds the task lock, so there is no need to use get_task_comm() which just tries to take the lock again. Drop its use and access current->comm directly.

yep, looks good

Quoted 24 lines
---
 security/yama/yama_lsm.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
security/yama/yama_lsm.c +2 -4
index 83554ee..20a68ca 100644
@@ -279,12 +279,10 @@ static int yama_ptrace_access_check(struct task_struct *child,
 	}
 
 	if (rc) {
-		char name[sizeof(current->comm)];
+		/* task_lock is held by the caller, so use comm directly. */
 		printk_ratelimited(KERN_NOTICE
 			"ptrace of pid %d was attempted by: %s (pid %d)\n",
-			child->pid,
-			get_task_comm(name, current),
-			current->pid);
+			child->pid, current->comm, current->pid);
 	}
 
 	return rc;
#2 lore raw
Quoted 5 lines · On Mon, 30 Jul 2012 14:21:33 -0700 John Johansen <[email protected]>…
Quoted 4 lines · Kees Cook

The core ptrace access checking routine already holds the task lock, so there is no need to use get_task_comm() which just tries to take the lock again. Drop its use and access current->comm directly.

Quoted 7 lines
Quoted 4 lines

yep, looks good

Code looks correct but having a weird cornercase direct reference is asking for an accident later. For maintainability I'd rather see that as __get_task_comm() or get_task_commu_unlocked() which does the job, deals with all the edge cases and contains a WARN_ON check on the lock.

Alan

author
#3 lore raw

Hi,

Quoted 14 lines · Alan Cox
Quoted 11 lines · On Mon, 30 Jul 2012 14:21:33 -0700 John Johansen <[email protected]>…
Quoted 8 lines · Kees Cook

The core ptrace access checking routine already holds the task lock, so there is no need to use get_task_comm() which just tries to take the lock again. Drop its use and access current->comm directly.

yep, looks good

Quoted 7 lines
Quoted 1 line

Code looks correct but having a weird cornercase direct reference is asking for an accident later. For maintainability I'd rather see that as __get_task_comm() or get_task_commu_unlocked() which does the job, deals with all the edge cases and contains a WARN_ON check on the lock.

I'd be happy to refactor this area, sure. What's the best way to check for this lock. I see in staging:

#define ASSERT_SPINLOCK(_l) WARN_ON(!spin_is_locked(_l))

but in other areas, I see things using the raw_ prefix:

                WARN_ON(raw_spin_is_locked(&kvm_lock));

Which is preferred for task_lock?

-Kees

Signature · 2 lines
Kees Cook
Chrome OS Security