Skip to content

Commit

Permalink
LSM: Fix for security_inode_getsecurity and -EOPNOTSUPP
Browse files Browse the repository at this point in the history
Serge Hallyn pointed out that the current implementation of
security_inode_getsecurity() works if there is only one hook
provided for it, but will fail if there is more than one and
the attribute requested isn't supplied by the first module.
This isn't a problem today, since only SELinux and Smack
provide this hook and there is (currently) no way to enable
both of those modules at the same time. Serge, however, wants
to introduce a capability attribute and an inode_getsecurity
hook in the capability security module to handle it. This
addresses that upcoming problem, will be required for "extreme
stacking" and is just a better implementation.

Signed-off-by: Casey Schaufler <[email protected]>
Acked-by: Serge Hallyn <[email protected]>
Signed-off-by: James Morris <[email protected]>
  • Loading branch information
cschaufler authored and James Morris committed Jun 6, 2016
1 parent 39baa7e commit 2885c1e
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions security/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,18 +700,39 @@ int security_inode_killpriv(struct dentry *dentry)

int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc)
{
struct security_hook_list *hp;
int rc;

if (unlikely(IS_PRIVATE(inode)))
return -EOPNOTSUPP;
return call_int_hook(inode_getsecurity, -EOPNOTSUPP, inode, name,
buffer, alloc);
/*
* Only one module will provide an attribute with a given name.
*/
list_for_each_entry(hp, &security_hook_heads.inode_getsecurity, list) {
rc = hp->hook.inode_getsecurity(inode, name, buffer, alloc);
if (rc != -EOPNOTSUPP)
return rc;
}
return -EOPNOTSUPP;
}

int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
{
struct security_hook_list *hp;
int rc;

if (unlikely(IS_PRIVATE(inode)))
return -EOPNOTSUPP;
return call_int_hook(inode_setsecurity, -EOPNOTSUPP, inode, name,
value, size, flags);
/*
* Only one module will provide an attribute with a given name.
*/
list_for_each_entry(hp, &security_hook_heads.inode_setsecurity, list) {
rc = hp->hook.inode_setsecurity(inode, name, value, size,
flags);
if (rc != -EOPNOTSUPP)
return rc;
}
return -EOPNOTSUPP;
}

int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
Expand Down

0 comments on commit 2885c1e

Please sign in to comment.