Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 29282381 authored by Tetsuo Handa's avatar Tetsuo Handa Committed by James Morris
Browse files

TOMOYO: Use mutex_lock_interruptible.



Some of TOMOYO's functions may sleep after mutex_lock(). If OOM-killer selected
a process which is waiting at mutex_lock(), the to-be-killed process can't be
killed. Thus, replace mutex_lock() with mutex_lock_interruptible() so that the
to-be-killed process can immediately return from TOMOYO's functions.

Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: default avatarJames Morris <jmorris@namei.org>
parent 2b9e4688
Loading
Loading
Loading
Loading
+8 −5
Original line number Original line Diff line number Diff line
@@ -874,13 +874,13 @@ bool tomoyo_domain_quota_is_ok(struct tomoyo_domain_info * const domain)
static struct tomoyo_profile *tomoyo_find_or_assign_new_profile(const unsigned
static struct tomoyo_profile *tomoyo_find_or_assign_new_profile(const unsigned
								int profile)
								int profile)
{
{
	static DEFINE_MUTEX(lock);
	struct tomoyo_profile *ptr = NULL;
	struct tomoyo_profile *ptr = NULL;
	int i;
	int i;


	if (profile >= TOMOYO_MAX_PROFILES)
	if (profile >= TOMOYO_MAX_PROFILES)
		return NULL;
		return NULL;
	mutex_lock(&lock);
	if (mutex_lock_interruptible(&tomoyo_policy_lock))
		return NULL;
	ptr = tomoyo_profile_ptr[profile];
	ptr = tomoyo_profile_ptr[profile];
	if (ptr)
	if (ptr)
		goto ok;
		goto ok;
@@ -895,7 +895,7 @@ static struct tomoyo_profile *tomoyo_find_or_assign_new_profile(const unsigned
	mb(); /* Avoid out-of-order execution. */
	mb(); /* Avoid out-of-order execution. */
	tomoyo_profile_ptr[profile] = ptr;
	tomoyo_profile_ptr[profile] = ptr;
 ok:
 ok:
	mutex_unlock(&lock);
	mutex_unlock(&tomoyo_policy_lock);
	return ptr;
	return ptr;
}
}


@@ -1090,7 +1090,8 @@ static int tomoyo_update_manager_entry(const char *manager,
		return -ENOMEM;
		return -ENOMEM;
	if (!is_delete)
	if (!is_delete)
		entry = kmalloc(sizeof(*entry), GFP_NOFS);
		entry = kmalloc(sizeof(*entry), GFP_NOFS);
	mutex_lock(&tomoyo_policy_lock);
	if (mutex_lock_interruptible(&tomoyo_policy_lock))
		goto out;
	list_for_each_entry_rcu(ptr, &tomoyo_policy_manager_list, list) {
	list_for_each_entry_rcu(ptr, &tomoyo_policy_manager_list, list) {
		if (ptr->manager != saved_manager)
		if (ptr->manager != saved_manager)
			continue;
			continue;
@@ -1107,6 +1108,7 @@ static int tomoyo_update_manager_entry(const char *manager,
		error = 0;
		error = 0;
	}
	}
	mutex_unlock(&tomoyo_policy_lock);
	mutex_unlock(&tomoyo_policy_lock);
 out:
	tomoyo_put_name(saved_manager);
	tomoyo_put_name(saved_manager);
	kfree(entry);
	kfree(entry);
	return error;
	return error;
@@ -1287,7 +1289,8 @@ static int tomoyo_delete_domain(char *domainname)


	name.name = domainname;
	name.name = domainname;
	tomoyo_fill_path_info(&name);
	tomoyo_fill_path_info(&name);
	mutex_lock(&tomoyo_policy_lock);
	if (mutex_lock_interruptible(&tomoyo_policy_lock))
		return 0;
	/* Is there an active domain? */
	/* Is there an active domain? */
	list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) {
	list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) {
		/* Never delete tomoyo_kernel_domain */
		/* Never delete tomoyo_kernel_domain */
+0 −1
Original line number Original line Diff line number Diff line
@@ -662,7 +662,6 @@ extern struct list_head tomoyo_pattern_list;
extern struct list_head tomoyo_no_rewrite_list;
extern struct list_head tomoyo_no_rewrite_list;
extern struct list_head tomoyo_policy_manager_list;
extern struct list_head tomoyo_policy_manager_list;
extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
extern struct mutex tomoyo_name_list_lock;


/* Lock for protecting policy. */
/* Lock for protecting policy. */
extern struct mutex tomoyo_policy_lock;
extern struct mutex tomoyo_policy_lock;
+10 −5
Original line number Original line Diff line number Diff line
@@ -154,7 +154,8 @@ static int tomoyo_update_domain_initializer_entry(const char *domainname,
		goto out;
		goto out;
	if (!is_delete)
	if (!is_delete)
		entry = kmalloc(sizeof(*entry), GFP_NOFS);
		entry = kmalloc(sizeof(*entry), GFP_NOFS);
	mutex_lock(&tomoyo_policy_lock);
	if (mutex_lock_interruptible(&tomoyo_policy_lock))
		goto out;
	list_for_each_entry_rcu(ptr, &tomoyo_domain_initializer_list, list) {
	list_for_each_entry_rcu(ptr, &tomoyo_domain_initializer_list, list) {
		if (ptr->is_not != is_not ||
		if (ptr->is_not != is_not ||
		    ptr->domainname != saved_domainname ||
		    ptr->domainname != saved_domainname ||
@@ -374,7 +375,8 @@ static int tomoyo_update_domain_keeper_entry(const char *domainname,
		goto out;
		goto out;
	if (!is_delete)
	if (!is_delete)
		entry = kmalloc(sizeof(*entry), GFP_NOFS);
		entry = kmalloc(sizeof(*entry), GFP_NOFS);
	mutex_lock(&tomoyo_policy_lock);
	if (mutex_lock_interruptible(&tomoyo_policy_lock))
		goto out;
	list_for_each_entry_rcu(ptr, &tomoyo_domain_keeper_list, list) {
	list_for_each_entry_rcu(ptr, &tomoyo_domain_keeper_list, list) {
		if (ptr->is_not != is_not ||
		if (ptr->is_not != is_not ||
		    ptr->domainname != saved_domainname ||
		    ptr->domainname != saved_domainname ||
@@ -566,7 +568,8 @@ static int tomoyo_update_alias_entry(const char *original_name,
		goto out;
		goto out;
	if (!is_delete)
	if (!is_delete)
		entry = kmalloc(sizeof(*entry), GFP_NOFS);
		entry = kmalloc(sizeof(*entry), GFP_NOFS);
	mutex_lock(&tomoyo_policy_lock);
	if (mutex_lock_interruptible(&tomoyo_policy_lock))
		goto out;
	list_for_each_entry_rcu(ptr, &tomoyo_alias_list, list) {
	list_for_each_entry_rcu(ptr, &tomoyo_alias_list, list) {
		if (ptr->original_name != saved_original_name ||
		if (ptr->original_name != saved_original_name ||
		    ptr->aliased_name != saved_aliased_name)
		    ptr->aliased_name != saved_aliased_name)
@@ -656,7 +659,7 @@ struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
							    const u8 profile)
							    const u8 profile)
{
{
	struct tomoyo_domain_info *entry;
	struct tomoyo_domain_info *entry;
	struct tomoyo_domain_info *domain;
	struct tomoyo_domain_info *domain = NULL;
	const struct tomoyo_path_info *saved_domainname;
	const struct tomoyo_path_info *saved_domainname;
	bool found = false;
	bool found = false;


@@ -666,7 +669,8 @@ struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
	if (!saved_domainname)
	if (!saved_domainname)
		return NULL;
		return NULL;
	entry = kzalloc(sizeof(*entry), GFP_NOFS);
	entry = kzalloc(sizeof(*entry), GFP_NOFS);
	mutex_lock(&tomoyo_policy_lock);
	if (mutex_lock_interruptible(&tomoyo_policy_lock))
		goto out;
	list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) {
	list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) {
		if (domain->is_deleted ||
		if (domain->is_deleted ||
		    tomoyo_pathcmp(saved_domainname, domain->domainname))
		    tomoyo_pathcmp(saved_domainname, domain->domainname))
@@ -685,6 +689,7 @@ struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
		found = true;
		found = true;
	}
	}
	mutex_unlock(&tomoyo_policy_lock);
	mutex_unlock(&tomoyo_policy_lock);
 out:
	tomoyo_put_name(saved_domainname);
	tomoyo_put_name(saved_domainname);
	kfree(entry);
	kfree(entry);
	return found ? domain : NULL;
	return found ? domain : NULL;
+13 −5
Original line number Original line Diff line number Diff line
@@ -176,7 +176,8 @@ static int tomoyo_update_globally_readable_entry(const char *filename,
		return -ENOMEM;
		return -ENOMEM;
	if (!is_delete)
	if (!is_delete)
		entry = kmalloc(sizeof(*entry), GFP_NOFS);
		entry = kmalloc(sizeof(*entry), GFP_NOFS);
	mutex_lock(&tomoyo_policy_lock);
	if (mutex_lock_interruptible(&tomoyo_policy_lock))
		goto out;
	list_for_each_entry_rcu(ptr, &tomoyo_globally_readable_list, list) {
	list_for_each_entry_rcu(ptr, &tomoyo_globally_readable_list, list) {
		if (ptr->filename != saved_filename)
		if (ptr->filename != saved_filename)
			continue;
			continue;
@@ -192,6 +193,7 @@ static int tomoyo_update_globally_readable_entry(const char *filename,
		error = 0;
		error = 0;
	}
	}
	mutex_unlock(&tomoyo_policy_lock);
	mutex_unlock(&tomoyo_policy_lock);
 out:
	tomoyo_put_name(saved_filename);
	tomoyo_put_name(saved_filename);
	kfree(entry);
	kfree(entry);
	return error;
	return error;
@@ -323,7 +325,8 @@ static int tomoyo_update_file_pattern_entry(const char *pattern,
		goto out;
		goto out;
	if (!is_delete)
	if (!is_delete)
		entry = kmalloc(sizeof(*entry), GFP_NOFS);
		entry = kmalloc(sizeof(*entry), GFP_NOFS);
	mutex_lock(&tomoyo_policy_lock);
	if (mutex_lock_interruptible(&tomoyo_policy_lock))
		goto out;
	list_for_each_entry_rcu(ptr, &tomoyo_pattern_list, list) {
	list_for_each_entry_rcu(ptr, &tomoyo_pattern_list, list) {
		if (saved_pattern != ptr->pattern)
		if (saved_pattern != ptr->pattern)
			continue;
			continue;
@@ -476,7 +479,8 @@ static int tomoyo_update_no_rewrite_entry(const char *pattern,
		return error;
		return error;
	if (!is_delete)
	if (!is_delete)
		entry = kmalloc(sizeof(*entry), GFP_NOFS);
		entry = kmalloc(sizeof(*entry), GFP_NOFS);
	mutex_lock(&tomoyo_policy_lock);
	if (mutex_lock_interruptible(&tomoyo_policy_lock))
		goto out;
	list_for_each_entry_rcu(ptr, &tomoyo_no_rewrite_list, list) {
	list_for_each_entry_rcu(ptr, &tomoyo_no_rewrite_list, list) {
		if (ptr->pattern != saved_pattern)
		if (ptr->pattern != saved_pattern)
			continue;
			continue;
@@ -492,6 +496,7 @@ static int tomoyo_update_no_rewrite_entry(const char *pattern,
		error = 0;
		error = 0;
	}
	}
	mutex_unlock(&tomoyo_policy_lock);
	mutex_unlock(&tomoyo_policy_lock);
 out:
	tomoyo_put_name(saved_pattern);
	tomoyo_put_name(saved_pattern);
	kfree(entry);
	kfree(entry);
	return error;
	return error;
@@ -822,7 +827,8 @@ static int tomoyo_update_path_acl(const u8 type, const char *filename,
		return -ENOMEM;
		return -ENOMEM;
	if (!is_delete)
	if (!is_delete)
		entry = kmalloc(sizeof(*entry), GFP_NOFS);
		entry = kmalloc(sizeof(*entry), GFP_NOFS);
	mutex_lock(&tomoyo_policy_lock);
	if (mutex_lock_interruptible(&tomoyo_policy_lock))
		goto out;
	list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
	list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
		struct tomoyo_path_acl *acl =
		struct tomoyo_path_acl *acl =
			container_of(ptr, struct tomoyo_path_acl, head);
			container_of(ptr, struct tomoyo_path_acl, head);
@@ -867,6 +873,7 @@ static int tomoyo_update_path_acl(const u8 type, const char *filename,
		error = 0;
		error = 0;
	}
	}
	mutex_unlock(&tomoyo_policy_lock);
	mutex_unlock(&tomoyo_policy_lock);
 out:
	kfree(entry);
	kfree(entry);
	tomoyo_put_name(saved_filename);
	tomoyo_put_name(saved_filename);
	return error;
	return error;
@@ -908,7 +915,8 @@ static int tomoyo_update_path2_acl(const u8 type, const char *filename1,
		goto out;
		goto out;
	if (!is_delete)
	if (!is_delete)
		entry = kmalloc(sizeof(*entry), GFP_NOFS);
		entry = kmalloc(sizeof(*entry), GFP_NOFS);
	mutex_lock(&tomoyo_policy_lock);
	if (mutex_lock_interruptible(&tomoyo_policy_lock))
		goto out;
	list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
	list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
		struct tomoyo_path2_acl *acl =
		struct tomoyo_path2_acl *acl =
			container_of(ptr, struct tomoyo_path2_acl, head);
			container_of(ptr, struct tomoyo_path2_acl, head);
+3 −4
Original line number Original line Diff line number Diff line
@@ -151,7 +151,8 @@ static void tomoyo_del_name(const struct tomoyo_name_entry *ptr)


static void tomoyo_collect_entry(void)
static void tomoyo_collect_entry(void)
{
{
	mutex_lock(&tomoyo_policy_lock);
	if (mutex_lock_interruptible(&tomoyo_policy_lock))
		return;
	{
	{
		struct tomoyo_globally_readable_file_entry *ptr;
		struct tomoyo_globally_readable_file_entry *ptr;
		list_for_each_entry_rcu(ptr, &tomoyo_globally_readable_list,
		list_for_each_entry_rcu(ptr, &tomoyo_globally_readable_list,
@@ -275,8 +276,6 @@ static void tomoyo_collect_entry(void)
				break;
				break;
		}
		}
	}
	}
	mutex_unlock(&tomoyo_policy_lock);
	mutex_lock(&tomoyo_name_list_lock);
	{
	{
		int i;
		int i;
		for (i = 0; i < TOMOYO_MAX_HASH; i++) {
		for (i = 0; i < TOMOYO_MAX_HASH; i++) {
@@ -294,7 +293,7 @@ static void tomoyo_collect_entry(void)
			}
			}
		}
		}
	}
	}
	mutex_unlock(&tomoyo_name_list_lock);
	mutex_unlock(&tomoyo_policy_lock);
}
}


static void tomoyo_kfree_entry(void)
static void tomoyo_kfree_entry(void)
Loading