Skip to content

Commit

Permalink
selinux: fix misuse of mutex_is_locked()
Browse files Browse the repository at this point in the history
commit ce2fc71 upstream.

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).

Cc: stable@vger.kernel.org
Fixes: 2554a48 ("selinux: measure state and policy capabilities")
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
WOnder93 authored and gregkh committed Mar 2, 2022
1 parent 0d773aa commit af091cc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions security/selinux/ima.c
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit af091cc

Please sign in to comment.