Yama features for 3.8:
- replacing locks with RCU - replacing in-place delete with workqueue -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Kees Cook <kees@outflux.net> iQIcBAABCgAGBQJQq9LvAAoJEIly9N/cbcAmmhYP/2dZP5WzqS7TKqDHIKwgRStc 96KFXdBl8EGkktEKvj/MlsSGoCS8sRBxu3s62kgHd8w0WAvsxLOQiMkgVc2IfkR/ loDRtFKxHkPTR46l9Nfy1KzIrZomaVA6PimMWZRxpySdowZn3fQzSslmWaDUas6P v9G9Dg6ApG+on3IowA2OHgYvW3sg9p0iXycFPWhVJf8SHik5mGgkbcAY5dugDDSN W9+RJYQdT8ccALIKl73rxQ6FEQDQSxUgw7ONCFYbNoXPzmPvu2/7f/ZHGPSCUzxD DxzLqANjn8uRkveSwXDx0pKNqJjVHezRNQ4sZBKsvvL6RnXSOSED2LoSduUNQaqs gdZVXsut/xvVZe/2QV8wSoQF4DhXTSZ/ia14aHtHaLYoRr8ec2i3I70/qcXAPSO1 UUlYxpPr0HgSbiXcYY1egC465v62e1pI5O8cMNK221T8q8IZCi/METvhaCyjc2h2 OBhAFBGeDOSDDzypz5DShVVDW3jHVjCWferlf1Jjh8xxxk6YsAmxS8OnNsNsgJRL vewmRutKgUxt0RKyorfvo4EXSGv/uOhzW36+711XxAAG6cU6BQH5Fpq2antizVD+ LRWi7YEyZyzs8L4g89uhy0Va90aLJ5sedhX00Bm0Vs7mRr5rXdxqZwsUVWj6bEPP pmMJm1t2/8GrRqBqD9qs =dr0Q -----END PGP SIGNATURE----- Merge tag 'yama-3.8' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux into next Yama features for 3.8: - replacing locks with RCU - replacing in-place delete with workqueue Merged per request by Kees Cook.
This commit is contained in:
commit
3f0cc6ae86
1 changed files with 62 additions and 26 deletions
|
@ -17,6 +17,7 @@
|
|||
#include <linux/ptrace.h>
|
||||
#include <linux/prctl.h>
|
||||
#include <linux/ratelimit.h>
|
||||
#include <linux/workqueue.h>
|
||||
|
||||
#define YAMA_SCOPE_DISABLED 0
|
||||
#define YAMA_SCOPE_RELATIONAL 1
|
||||
|
@ -29,12 +30,37 @@ static int ptrace_scope = YAMA_SCOPE_RELATIONAL;
|
|||
struct ptrace_relation {
|
||||
struct task_struct *tracer;
|
||||
struct task_struct *tracee;
|
||||
bool invalid;
|
||||
struct list_head node;
|
||||
struct rcu_head rcu;
|
||||
};
|
||||
|
||||
static LIST_HEAD(ptracer_relations);
|
||||
static DEFINE_SPINLOCK(ptracer_relations_lock);
|
||||
|
||||
static void yama_relation_cleanup(struct work_struct *work);
|
||||
static DECLARE_WORK(yama_relation_work, yama_relation_cleanup);
|
||||
|
||||
/**
|
||||
* yama_relation_cleanup - remove invalid entries from the relation list
|
||||
*
|
||||
*/
|
||||
static void yama_relation_cleanup(struct work_struct *work)
|
||||
{
|
||||
struct ptrace_relation *relation;
|
||||
|
||||
spin_lock(&ptracer_relations_lock);
|
||||
rcu_read_lock();
|
||||
list_for_each_entry_rcu(relation, &ptracer_relations, node) {
|
||||
if (relation->invalid) {
|
||||
list_del_rcu(&relation->node);
|
||||
kfree_rcu(relation, rcu);
|
||||
}
|
||||
}
|
||||
rcu_read_unlock();
|
||||
spin_unlock(&ptracer_relations_lock);
|
||||
}
|
||||
|
||||
/**
|
||||
* yama_ptracer_add - add/replace an exception for this tracer/tracee pair
|
||||
* @tracer: the task_struct of the process doing the ptrace
|
||||
|
@ -48,32 +74,34 @@ static DEFINE_SPINLOCK(ptracer_relations_lock);
|
|||
static int yama_ptracer_add(struct task_struct *tracer,
|
||||
struct task_struct *tracee)
|
||||
{
|
||||
int rc = 0;
|
||||
struct ptrace_relation *added;
|
||||
struct ptrace_relation *entry, *relation = NULL;
|
||||
struct ptrace_relation *relation, *added;
|
||||
|
||||
added = kmalloc(sizeof(*added), GFP_KERNEL);
|
||||
if (!added)
|
||||
return -ENOMEM;
|
||||
|
||||
spin_lock_bh(&ptracer_relations_lock);
|
||||
list_for_each_entry(entry, &ptracer_relations, node)
|
||||
if (entry->tracee == tracee) {
|
||||
relation = entry;
|
||||
break;
|
||||
added->tracee = tracee;
|
||||
added->tracer = tracer;
|
||||
added->invalid = false;
|
||||
|
||||
spin_lock(&ptracer_relations_lock);
|
||||
rcu_read_lock();
|
||||
list_for_each_entry_rcu(relation, &ptracer_relations, node) {
|
||||
if (relation->invalid)
|
||||
continue;
|
||||
if (relation->tracee == tracee) {
|
||||
list_replace_rcu(&relation->node, &added->node);
|
||||
kfree_rcu(relation, rcu);
|
||||
goto out;
|
||||
}
|
||||
if (!relation) {
|
||||
relation = added;
|
||||
relation->tracee = tracee;
|
||||
list_add(&relation->node, &ptracer_relations);
|
||||
}
|
||||
relation->tracer = tracer;
|
||||
|
||||
spin_unlock_bh(&ptracer_relations_lock);
|
||||
if (added != relation)
|
||||
kfree(added);
|
||||
list_add_rcu(&added->node, &ptracer_relations);
|
||||
|
||||
return rc;
|
||||
out:
|
||||
rcu_read_unlock();
|
||||
spin_unlock(&ptracer_relations_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,16 +112,23 @@ static int yama_ptracer_add(struct task_struct *tracer,
|
|||
static void yama_ptracer_del(struct task_struct *tracer,
|
||||
struct task_struct *tracee)
|
||||
{
|
||||
struct ptrace_relation *relation, *safe;
|
||||
struct ptrace_relation *relation;
|
||||
bool marked = false;
|
||||
|
||||
spin_lock_bh(&ptracer_relations_lock);
|
||||
list_for_each_entry_safe(relation, safe, &ptracer_relations, node)
|
||||
rcu_read_lock();
|
||||
list_for_each_entry_rcu(relation, &ptracer_relations, node) {
|
||||
if (relation->invalid)
|
||||
continue;
|
||||
if (relation->tracee == tracee ||
|
||||
(tracer && relation->tracer == tracer)) {
|
||||
list_del(&relation->node);
|
||||
kfree(relation);
|
||||
relation->invalid = true;
|
||||
marked = true;
|
||||
}
|
||||
spin_unlock_bh(&ptracer_relations_lock);
|
||||
}
|
||||
rcu_read_unlock();
|
||||
|
||||
if (marked)
|
||||
schedule_work(&yama_relation_work);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -217,21 +252,22 @@ static int ptracer_exception_found(struct task_struct *tracer,
|
|||
struct task_struct *parent = NULL;
|
||||
bool found = false;
|
||||
|
||||
spin_lock_bh(&ptracer_relations_lock);
|
||||
rcu_read_lock();
|
||||
if (!thread_group_leader(tracee))
|
||||
tracee = rcu_dereference(tracee->group_leader);
|
||||
list_for_each_entry(relation, &ptracer_relations, node)
|
||||
list_for_each_entry_rcu(relation, &ptracer_relations, node) {
|
||||
if (relation->invalid)
|
||||
continue;
|
||||
if (relation->tracee == tracee) {
|
||||
parent = relation->tracer;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found && (parent == NULL || task_is_descendant(parent, tracer)))
|
||||
rc = 1;
|
||||
rcu_read_unlock();
|
||||
spin_unlock_bh(&ptracer_relations_lock);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue