Skip to content

Commit 99b817c

Browse files
WOnder93pcmoore
authored andcommitted
lsm: fix the logic in security_inode_getsecctx()
The inode_getsecctx LSM hook has previously been corrected to have -EOPNOTSUPP instead of 0 as the default return value to fix BPF LSM behavior. However, the call_int_hook()-generated loop in security_inode_getsecctx() was left treating 0 as the neutral value, so after an LSM returns 0, the loop continues to try other LSMs, and if one of them returns a non-zero value, the function immediately returns with said value. So in a situation where SELinux and the BPF LSMs registered this hook, -EOPNOTSUPP would be incorrectly returned whenever SELinux returned 0. Fix this by open-coding the call_int_hook() loop and making it use the correct LSM_RET_DEFAULT() value as the neutral one, similar to what other hooks do. Cc: [email protected] Reported-by: Stephen Smalley <[email protected]> Link: https://lore.kernel.org/selinux/CAEjxPJ4ev-pasUwGx48fDhnmjBnq_Wh90jYPwRQRAqXxmOKD4Q@mail.gmail.com/ Link: https://bugzilla.redhat.com/show_bug.cgi?id=2257983 Fixes: b36995b ("lsm: fix default return value for inode_getsecctx") Signed-off-by: Ondrej Mosnacek <[email protected]> Reviewed-by: Casey Schaufler <[email protected]> [PM: subject line tweak] Signed-off-by: Paul Moore <[email protected]>
1 parent 6613476 commit 99b817c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

security/security.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4255,7 +4255,19 @@ EXPORT_SYMBOL(security_inode_setsecctx);
42554255
*/
42564256
int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
42574257
{
4258-
return call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, ctx, ctxlen);
4258+
struct security_hook_list *hp;
4259+
int rc;
4260+
4261+
/*
4262+
* Only one module will provide a security context.
4263+
*/
4264+
hlist_for_each_entry(hp, &security_hook_heads.inode_getsecctx, list) {
4265+
rc = hp->hook.inode_getsecctx(inode, ctx, ctxlen);
4266+
if (rc != LSM_RET_DEFAULT(inode_getsecctx))
4267+
return rc;
4268+
}
4269+
4270+
return LSM_RET_DEFAULT(inode_getsecctx);
42594271
}
42604272
EXPORT_SYMBOL(security_inode_getsecctx);
42614273

0 commit comments

Comments
 (0)