Skip to contentSkip to conversation

Yama: access task_struct->comm directly

PATCH In review Kees Cook 2 participants 2 messages Aug 15, 2012 – Aug 16, 2012

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH v2 1/1 Yama: access task_struct->comm directly

The core ptrace access checking routine holds a task lock, and when reporting a failure, Yama takes a separate task lock. To avoid a potential deadlock with two ptracers taking the opposite locks, do not use get_task_comm() and just use ->comm directly since accuracy is not important for the report.

---
v2: update with newly added traceme report.

---
 security/yama/yama_lsm.c |   10 ++--------
 1 files changed, 2 insertions(+), 8 deletions(-)
security/yama/yama_lsm.c +2 -8
index d51b7c7..0cc99a3 100644
@@ -279,12 +279,9 @@ static int yama_ptrace_access_check(struct task_struct *child,
 	}
 
 	if (rc) {
-		char name[sizeof(current->comm)];
 		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;
@@ -319,12 +316,9 @@ static int yama_ptrace_traceme(struct task_struct *parent)
 	}
 
 	if (rc) {
-		char name[sizeof(current->comm)];
 		printk_ratelimited(KERN_NOTICE
 			"ptraceme of pid %d was attempted by: %s (pid %d)\n",
-			current->pid,
-			get_task_comm(name, parent),
-			parent->pid);
+			current->pid, parent->comm, parent->pid);
 	}
 
 	return rc;
Signature · 6 lines
1.7.0.4


-- 
Kees Cook
Chrome OS Security
#1 lore raw
Quoted 2 lines · Kees Cook

v2: update with newly added traceme report.

...

security/yama/yama_lsm.c static int yama_ptrace_traceme(struct task_struct *parent) · line 321

Quoted 11 lines
security/yama/yama_lsm.c +1 -4
@@ -319,12 +316,9 @@ static int yama_ptrace_traceme(struct task_struct *parent)
 	}
 
 	if (rc) {
-		char name[sizeof(current->comm)];
 		printk_ratelimited(KERN_NOTICE
 			"ptraceme of pid %d was attempted by: %s (pid %d)\n",
-			current->pid,
-			get_task_comm(name, parent),
-			parent->pid);
+			current->pid, parent->comm, parent->pid);

Hmm, yes. This change is even more important. This is called under write_lock_irq(tasklist_lock), task_lock() can deadlock if we race with another CPU doing task_lock()->interrupt->read_lock(tasklist).

Oleg.