Skip to contentSkip to conversation

security: tomoyo: fix error return code of tomoyo_update_domain()

PATCH In review Jia-Ju Bai 2 participants 2 messages Mar 6, 2021

Subsystems (2)
lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 security: tomoyo: fix error return code of tomoyo_update_domain()

When mutex_lock_interruptible() fails, the error return code of tomoyo_update_domain() is not properly assigned.
To fix this bug, error is assigned with the return value of mutex_lock_interruptible(), and then error is checked.

---
 security/tomoyo/domain.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
security/tomoyo/domain.c +2 -1
index 98d985895ec8..7b9f9664dbe3 100644
@@ -118,7 +118,8 @@ int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
 		      ->perm == 1 << TOMOYO_TYPE_EXECUTE))
 			goto out;
 	}
-	if (mutex_lock_interruptible(&tomoyo_policy_lock))
+	error = mutex_lock_interruptible(&tomoyo_policy_lock);
+	if (error)
 		goto out;
 	list_for_each_entry_rcu(entry, list, list,
 				srcu_read_lock_held(&tomoyo_ss)) {
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 4 lines · Jia-Ju Bai

When mutex_lock_interruptible() fails, the error return code of tomoyo_update_domain() is not properly assigned.
To fix this bug, error is assigned with the return value of mutex_lock_interruptible(), and then error is checked.

Thanks for a patch, but this patch is wrong.
Since the variable "error" is initialized as

  int error = is_delete ? -ENOENT : -ENOMEM;

at the beginning of this function, unconditionally overwriting this variable with the return code of mutex_lock_interruptible() breaks

  if (error && !is_delete) {
  }

block of this function.

And the caller does not check if the return code is -EINTR instead of -ENOENT or -ENOMEM.