Yama: access current->comm directly
Subsystems (2)
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
@@ -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
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 accesscurrent->commdirectly.Reported-by Fengguang Wu <[email protected]>Suggested-by Oleg Nesterov <[email protected]>Signed-off-by Kees Cook <[email protected]>
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@@ -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;
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 accesscurrent->commdirectly.
Quoted 7 lines
Quoted 4 lines
Reported-by Fengguang Wu <[email protected]>Suggested-by Oleg Nesterov <[email protected]>Signed-off-by Kees Cook <[email protected]>yep, looks good
Acked-by John Johansen <[email protected]>
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
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 accesscurrent->commdirectly.Reported-by Fengguang Wu <[email protected]>Suggested-by Oleg Nesterov <[email protected]>Signed-off-by Kees Cook <[email protected]>yep, looks good
Quoted 7 lines
Quoted 1 line
Acked-by John Johansen <[email protected]>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()orget_task_commu_unlocked()which does the job, deals with all the edge cases and contains aWARN_ONcheck 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