Skip to content

Commit

Permalink
security: Fix hook iteration for secid_to_secctx
Browse files Browse the repository at this point in the history
secid_to_secctx is not stackable, and since the BPF LSM registers this
hook by default, the call_int_hook logic is not suitable which
"bails-on-fail" and casues issues when other LSMs register this hook and
eventually breaks Audit.

In order to fix this, directly iterate over the security hooks instead
of using call_int_hook as suggested in:

https: //lore.kernel.org/bpf/9d0eb6c6-803a-ff3a-5603-9ad6d9edfc00@schaufler-ca.com/#t

Fixes: 98e828a ("security: Refactor declaration of LSM hooks")
Fixes: 625236b ("security: Fix the default value of secid_to_secctx hook")
Reported-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: KP Singh <kpsingh@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: James Morris <jamorris@linux.microsoft.com>
Link: https://lore.kernel.org/bpf/20200520125616.193765-1-kpsingh@chromium.org
  • Loading branch information
KP Singh authored and Alexei Starovoitov committed May 21, 2020
1 parent 20a785a commit 0550cfe
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions security/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -1965,8 +1965,20 @@ EXPORT_SYMBOL(security_ismaclabel);

int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
{
return call_int_hook(secid_to_secctx, -EOPNOTSUPP, secid, secdata,
seclen);
struct security_hook_list *hp;
int rc;

/*
* Currently, only one LSM can implement secid_to_secctx (i.e this
* LSM hook is not "stackable").
*/
hlist_for_each_entry(hp, &security_hook_heads.secid_to_secctx, list) {
rc = hp->hook.secid_to_secctx(secid, secdata, seclen);
if (rc != LSM_RET_DEFAULT(secid_to_secctx))
return rc;
}

return LSM_RET_DEFAULT(secid_to_secctx);
}
EXPORT_SYMBOL(security_secid_to_secctx);

Expand Down

0 comments on commit 0550cfe

Please sign in to comment.