Skip to content

Commit

Permalink
Smack: Abstract use of ipc security blobs
Browse files Browse the repository at this point in the history
Don't use the ipc->security pointer directly.
Don't use the msg_msg->security pointer directly.
Provide helper functions that provides the security blob pointers.

Signed-off-by: Casey Schaufler <[email protected]>
Reviewed-by: Kees Cook <[email protected]>
Signed-off-by: Kees Cook <[email protected]>
  • Loading branch information
cschaufler authored and kees committed Jan 8, 2019
1 parent 7c65382 commit 019bcca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
11 changes: 11 additions & 0 deletions security/smack/smack.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <linux/list.h>
#include <linux/rculist.h>
#include <linux/lsm_audit.h>
#include <linux/msg.h>

/*
* Use IPv6 port labeling if IPv6 is enabled and secmarks
Expand Down Expand Up @@ -373,6 +374,16 @@ static inline struct inode_smack *smack_inode(const struct inode *inode)
return inode->i_security + smack_blob_sizes.lbs_inode;
}

static inline struct smack_known **smack_msg_msg(const struct msg_msg *msg)
{
return (struct smack_known **)&msg->security;
}

static inline struct smack_known **smack_ipc(const struct kern_ipc_perm *ipc)
{
return (struct smack_known **)&ipc->security;
}

/*
* Is the directory transmuting?
*/
Expand Down
14 changes: 9 additions & 5 deletions security/smack/smack_lsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2834,7 +2834,9 @@ static void smack_msg_msg_free_security(struct msg_msg *msg)
*/
static struct smack_known *smack_of_ipc(struct kern_ipc_perm *isp)
{
return (struct smack_known *)isp->security;
struct smack_known **blob = smack_ipc(isp);

return *blob;
}

/**
Expand All @@ -2845,9 +2847,9 @@ static struct smack_known *smack_of_ipc(struct kern_ipc_perm *isp)
*/
static int smack_ipc_alloc_security(struct kern_ipc_perm *isp)
{
struct smack_known *skp = smk_of_current();
struct smack_known **blob = smack_ipc(isp);

isp->security = skp;
*blob = smk_of_current();
return 0;
}

Expand Down Expand Up @@ -3159,7 +3161,8 @@ static int smack_msg_queue_msgrcv(struct kern_ipc_perm *isp, struct msg_msg *msg
*/
static int smack_ipc_permission(struct kern_ipc_perm *ipp, short flag)
{
struct smack_known *iskp = ipp->security;
struct smack_known **blob = smack_ipc(ipp);
struct smack_known *iskp = *blob;
int may = smack_flags_to_may(flag);
struct smk_audit_info ad;
int rc;
Expand All @@ -3180,7 +3183,8 @@ static int smack_ipc_permission(struct kern_ipc_perm *ipp, short flag)
*/
static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, u32 *secid)
{
struct smack_known *iskp = ipp->security;
struct smack_known **blob = smack_ipc(ipp);
struct smack_known *iskp = *blob;

*secid = iskp->smk_secid;
}
Expand Down

0 comments on commit 019bcca

Please sign in to comment.