Skip to content

Commit

Permalink
SELinux: pass a superblock to security_fs_use
Browse files Browse the repository at this point in the history
Rather than passing pointers to memory locations, strings, and other
stuff just give up on the separation and give security_fs_use the
superblock.  It just makes the code easier to read (even if not easier to
reuse on some other OS)

Signed-off-by: Eric Paris <eparis@redhat.com>
  • Loading branch information
Eric Paris committed Jul 25, 2013
1 parent 308ab70 commit a64c54c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ static int selinux_set_mnt_opts(struct super_block *sb,
sbsec->flags |= SE_SBPROC;

/* Determine the labeling behavior to use for this filesystem type. */
rc = security_fs_use(sb->s_type->name, &sbsec->behavior, &sbsec->sid);
rc = security_fs_use(sb);
if (rc) {
printk(KERN_WARNING "%s: security_fs_use(%s) returned %d\n",
__func__, sb->s_type->name, rc);
Expand Down
3 changes: 1 addition & 2 deletions security/selinux/include/security.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ int security_get_allow_unknown(void);
#define SECURITY_FS_USE_NONE 5 /* no labeling support */
#define SECURITY_FS_USE_MNTPOINT 6 /* use mountpoint labeling */

int security_fs_use(const char *fstype, short unsigned int *behavior,
u32 *sid);
int security_fs_use(struct super_block *sb);

int security_genfs_sid(const char *fstype, char *name, u16 sclass,
u32 *sid);
Expand Down
21 changes: 9 additions & 12 deletions security/selinux/ss/services.c
Original file line number Diff line number Diff line change
Expand Up @@ -2323,17 +2323,14 @@ int security_genfs_sid(const char *fstype,

/**
* security_fs_use - Determine how to handle labeling for a filesystem.
* @fstype: filesystem type
* @behavior: labeling behavior
* @sid: SID for filesystem (superblock)
* @sb: superblock in question
*/
int security_fs_use(
const char *fstype,
short unsigned int *behavior,
u32 *sid)
int security_fs_use(struct super_block *sb)
{
int rc = 0;
struct ocontext *c;
struct superblock_security_struct *sbsec = sb->s_security;
const char *fstype = sb->s_type->name;

read_lock(&policy_rwlock);

Expand All @@ -2345,21 +2342,21 @@ int security_fs_use(
}

if (c) {
*behavior = c->v.behavior;
sbsec->behavior = c->v.behavior;
if (!c->sid[0]) {
rc = sidtab_context_to_sid(&sidtab, &c->context[0],
&c->sid[0]);
if (rc)
goto out;
}
*sid = c->sid[0];
sbsec->sid = c->sid[0];
} else {
rc = security_genfs_sid(fstype, "/", SECCLASS_DIR, sid);
rc = security_genfs_sid(fstype, "/", SECCLASS_DIR, &sbsec->sid);
if (rc) {
*behavior = SECURITY_FS_USE_NONE;
sbsec->behavior = SECURITY_FS_USE_NONE;
rc = 0;
} else {
*behavior = SECURITY_FS_USE_GENFS;
sbsec->behavior = SECURITY_FS_USE_GENFS;
}
}

Expand Down

0 comments on commit a64c54c

Please sign in to comment.