Skip to content

Commit

Permalink
Yama: consolidate error reporting
Browse files Browse the repository at this point in the history
Use a common error reporting function for Yama violation reports, and give
more detail into the process command lines.

Signed-off-by: Kees Cook <[email protected]>
Signed-off-by: James Morris <[email protected]>
  • Loading branch information
kees authored and James Morris committed Apr 21, 2016
1 parent 2198531 commit 8a56038
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions security/yama/yama_lsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <linux/prctl.h>
#include <linux/ratelimit.h>
#include <linux/workqueue.h>
#include <linux/string_helpers.h>

#define YAMA_SCOPE_DISABLED 0
#define YAMA_SCOPE_RELATIONAL 1
Expand All @@ -41,6 +42,22 @@ static DEFINE_SPINLOCK(ptracer_relations_lock);
static void yama_relation_cleanup(struct work_struct *work);
static DECLARE_WORK(yama_relation_work, yama_relation_cleanup);

static void report_access(const char *access, struct task_struct *target,
struct task_struct *agent)
{
char *target_cmd, *agent_cmd;

target_cmd = kstrdup_quotable_cmdline(target, GFP_KERNEL);
agent_cmd = kstrdup_quotable_cmdline(agent, GFP_KERNEL);

pr_notice_ratelimited(
"ptrace %s of \"%s\"[%d] was attempted by \"%s\"[%d]\n",
access, target_cmd, target->pid, agent_cmd, agent->pid);

kfree(agent_cmd);
kfree(target_cmd);
}

/**
* yama_relation_cleanup - remove invalid entries from the relation list
*
Expand Down Expand Up @@ -307,11 +324,8 @@ static int yama_ptrace_access_check(struct task_struct *child,
}
}

if (rc && (mode & PTRACE_MODE_NOAUDIT) == 0) {
printk_ratelimited(KERN_NOTICE
"ptrace of pid %d was attempted by: %s (pid %d)\n",
child->pid, current->comm, current->pid);
}
if (rc && (mode & PTRACE_MODE_NOAUDIT) == 0)
report_access("attach", child, current);

return rc;
}
Expand All @@ -337,11 +351,8 @@ int yama_ptrace_traceme(struct task_struct *parent)
break;
}

if (rc) {
printk_ratelimited(KERN_NOTICE
"ptraceme of pid %d was attempted by: %s (pid %d)\n",
current->pid, parent->comm, parent->pid);
}
if (rc)
report_access("traceme", current, parent);

return rc;
}
Expand Down

0 comments on commit 8a56038

Please sign in to comment.