Skip to contentSkip to conversation

selinux: fix misuse of mutex_is_locked()

PATCH Applied Ondrej Mosnacek 2 participants 2 messages Feb 21, 2022 – Feb 22, 2022 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selinux: fix misuse of mutex_is_locked()

mutex_is_locked() tests whether the mutex is locked *by any task*, while here we want to test if it is held *by the current task*. To avoid false/missed WARNINGs, use lockdep_assert_is_held() and lockdep_assert_is_not_held() instead, which do the right thing (though they are a no-op if CONFIG_LOCKDEP=n).

Fixes 2554a48f4437 ("selinux: measure state and policy capabilities")
---
 security/selinux/ima.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
security/selinux/ima.c +2 -2
index 727c4e43219d..ff7aea6b3774 100644
@@ -77,7 +77,7 @@ void selinux_ima_measure_state_locked(struct selinux_state *state)
 	size_t policy_len;
 	int rc = 0;
 
-	WARN_ON(!mutex_is_locked(&state->policy_mutex));
+	lockdep_assert_held(&state->policy_mutex);
 
 	state_str = selinux_ima_collect_state(state);
 	if (!state_str) {
@@ -117,7 +117,7 @@ void selinux_ima_measure_state_locked(struct selinux_state *state)
  */
 void selinux_ima_measure_state(struct selinux_state *state)
 {
-	WARN_ON(mutex_is_locked(&state->policy_mutex));
+	lockdep_assert_not_held(&state->policy_mutex);
 
 	mutex_lock(&state->policy_mutex);
 	selinux_ima_measure_state_locked(state);
Signature · 1 line
2.35.1
maintainer Applied
#1 lore raw
Quoted 7 lines · Ondrej Mosnacek

mutex_is_locked() tests whether the mutex is locked *by any task*, while here we want to test if it is held *by the current task*. To avoid false/missed WARNINGs, use lockdep_assert_is_held() and lockdep_assert_is_not_held() instead, which do the right thing (though they are a no-op if CONFIG_LOCKDEP=n).

Quoted 5 lines
Fixes 2554a48f4437 ("selinux: measure state and policy capabilities")
---
 security/selinux/ima.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Merged into selinux/stable-5.17, thanks. Assuming no surprises during testing I'll send this up to Linus tomorrow.

Signature · 1 line
paul-moore.com