Skip to content

Commit 0550cfe

Browse files
sinkapAlexei Starovoitov
authored andcommitted
security: Fix hook iteration for secid_to_secctx
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/[email protected]/#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 <[email protected]> Signed-off-by: KP Singh <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: James Morris <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 20a785a commit 0550cfe

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

security/security.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,8 +1965,20 @@ EXPORT_SYMBOL(security_ismaclabel);
19651965

19661966
int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
19671967
{
1968-
return call_int_hook(secid_to_secctx, -EOPNOTSUPP, secid, secdata,
1969-
seclen);
1968+
struct security_hook_list *hp;
1969+
int rc;
1970+
1971+
/*
1972+
* Currently, only one LSM can implement secid_to_secctx (i.e this
1973+
* LSM hook is not "stackable").
1974+
*/
1975+
hlist_for_each_entry(hp, &security_hook_heads.secid_to_secctx, list) {
1976+
rc = hp->hook.secid_to_secctx(secid, secdata, seclen);
1977+
if (rc != LSM_RET_DEFAULT(secid_to_secctx))
1978+
return rc;
1979+
}
1980+
1981+
return LSM_RET_DEFAULT(secid_to_secctx);
19701982
}
19711983
EXPORT_SYMBOL(security_secid_to_secctx);
19721984

0 commit comments

Comments
 (0)