Commit fb4021b6 authored by Casey Schaufler's avatar Casey Schaufler Committed by Kees Cook

Smack: Abstract use of inode security blob

Don't use the inode->i_security pointer directly.
Provide a helper function that provides the security blob pointer.
Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
parent 80788c22
...@@ -368,12 +368,17 @@ static inline struct smack_known **smack_file(const struct file *file) ...@@ -368,12 +368,17 @@ static inline struct smack_known **smack_file(const struct file *file)
smack_blob_sizes.lbs_file); smack_blob_sizes.lbs_file);
} }
static inline struct inode_smack *smack_inode(const struct inode *inode)
{
return inode->i_security;
}
/* /*
* Is the directory transmuting? * Is the directory transmuting?
*/ */
static inline int smk_inode_transmutable(const struct inode *isp) static inline int smk_inode_transmutable(const struct inode *isp)
{ {
struct inode_smack *sip = isp->i_security; struct inode_smack *sip = smack_inode(isp);
return (sip->smk_flags & SMK_INODE_TRANSMUTE) != 0; return (sip->smk_flags & SMK_INODE_TRANSMUTE) != 0;
} }
...@@ -382,7 +387,7 @@ static inline int smk_inode_transmutable(const struct inode *isp) ...@@ -382,7 +387,7 @@ static inline int smk_inode_transmutable(const struct inode *isp)
*/ */
static inline struct smack_known *smk_of_inode(const struct inode *isp) static inline struct smack_known *smk_of_inode(const struct inode *isp)
{ {
struct inode_smack *sip = isp->i_security; struct inode_smack *sip = smack_inode(isp);
return sip->smk_inode; return sip->smk_inode;
} }
......
...@@ -183,7 +183,7 @@ static int smk_bu_task(struct task_struct *otp, int mode, int rc) ...@@ -183,7 +183,7 @@ static int smk_bu_task(struct task_struct *otp, int mode, int rc)
static int smk_bu_inode(struct inode *inode, int mode, int rc) static int smk_bu_inode(struct inode *inode, int mode, int rc)
{ {
struct task_smack *tsp = smack_cred(current_cred()); struct task_smack *tsp = smack_cred(current_cred());
struct inode_smack *isp = inode->i_security; struct inode_smack *isp = smack_inode(inode);
char acc[SMK_NUM_ACCESS_TYPE + 1]; char acc[SMK_NUM_ACCESS_TYPE + 1];
if (isp->smk_flags & SMK_INODE_IMPURE) if (isp->smk_flags & SMK_INODE_IMPURE)
...@@ -215,7 +215,7 @@ static int smk_bu_file(struct file *file, int mode, int rc) ...@@ -215,7 +215,7 @@ static int smk_bu_file(struct file *file, int mode, int rc)
struct task_smack *tsp = smack_cred(current_cred()); struct task_smack *tsp = smack_cred(current_cred());
struct smack_known *sskp = tsp->smk_task; struct smack_known *sskp = tsp->smk_task;
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
struct inode_smack *isp = inode->i_security; struct inode_smack *isp = smack_inode(inode);
char acc[SMK_NUM_ACCESS_TYPE + 1]; char acc[SMK_NUM_ACCESS_TYPE + 1];
if (isp->smk_flags & SMK_INODE_IMPURE) if (isp->smk_flags & SMK_INODE_IMPURE)
...@@ -245,7 +245,7 @@ static int smk_bu_credfile(const struct cred *cred, struct file *file, ...@@ -245,7 +245,7 @@ static int smk_bu_credfile(const struct cred *cred, struct file *file,
struct task_smack *tsp = smack_cred(cred); struct task_smack *tsp = smack_cred(cred);
struct smack_known *sskp = tsp->smk_task; struct smack_known *sskp = tsp->smk_task;
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
struct inode_smack *isp = inode->i_security; struct inode_smack *isp = smack_inode(inode);
char acc[SMK_NUM_ACCESS_TYPE + 1]; char acc[SMK_NUM_ACCESS_TYPE + 1];
if (isp->smk_flags & SMK_INODE_IMPURE) if (isp->smk_flags & SMK_INODE_IMPURE)
...@@ -773,7 +773,7 @@ static int smack_set_mnt_opts(struct super_block *sb, ...@@ -773,7 +773,7 @@ static int smack_set_mnt_opts(struct super_block *sb,
/* /*
* Initialize the root inode. * Initialize the root inode.
*/ */
isp = inode->i_security; isp = smack_inode(inode);
if (isp == NULL) { if (isp == NULL) {
isp = new_inode_smack(sp->smk_root); isp = new_inode_smack(sp->smk_root);
if (isp == NULL) if (isp == NULL)
...@@ -830,7 +830,7 @@ static int smack_bprm_set_creds(struct linux_binprm *bprm) ...@@ -830,7 +830,7 @@ static int smack_bprm_set_creds(struct linux_binprm *bprm)
if (bprm->called_set_creds) if (bprm->called_set_creds)
return 0; return 0;
isp = inode->i_security; isp = smack_inode(inode);
if (isp->smk_task == NULL || isp->smk_task == bsp->smk_task) if (isp->smk_task == NULL || isp->smk_task == bsp->smk_task)
return 0; return 0;
...@@ -910,7 +910,7 @@ static void smack_inode_free_rcu(struct rcu_head *head) ...@@ -910,7 +910,7 @@ static void smack_inode_free_rcu(struct rcu_head *head)
*/ */
static void smack_inode_free_security(struct inode *inode) static void smack_inode_free_security(struct inode *inode)
{ {
struct inode_smack *issp = inode->i_security; struct inode_smack *issp = smack_inode(inode);
/* /*
* The inode may still be referenced in a path walk and * The inode may still be referenced in a path walk and
...@@ -938,7 +938,7 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir, ...@@ -938,7 +938,7 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir,
const struct qstr *qstr, const char **name, const struct qstr *qstr, const char **name,
void **value, size_t *len) void **value, size_t *len)
{ {
struct inode_smack *issp = inode->i_security; struct inode_smack *issp = smack_inode(inode);
struct smack_known *skp = smk_of_current(); struct smack_known *skp = smk_of_current();
struct smack_known *isp = smk_of_inode(inode); struct smack_known *isp = smk_of_inode(inode);
struct smack_known *dsp = smk_of_inode(dir); struct smack_known *dsp = smk_of_inode(dir);
...@@ -1276,7 +1276,7 @@ static void smack_inode_post_setxattr(struct dentry *dentry, const char *name, ...@@ -1276,7 +1276,7 @@ static void smack_inode_post_setxattr(struct dentry *dentry, const char *name,
const void *value, size_t size, int flags) const void *value, size_t size, int flags)
{ {
struct smack_known *skp; struct smack_known *skp;
struct inode_smack *isp = d_backing_inode(dentry)->i_security; struct inode_smack *isp = smack_inode(d_backing_inode(dentry));
if (strcmp(name, XATTR_NAME_SMACKTRANSMUTE) == 0) { if (strcmp(name, XATTR_NAME_SMACKTRANSMUTE) == 0) {
isp->smk_flags |= SMK_INODE_TRANSMUTE; isp->smk_flags |= SMK_INODE_TRANSMUTE;
...@@ -1357,7 +1357,7 @@ static int smack_inode_removexattr(struct dentry *dentry, const char *name) ...@@ -1357,7 +1357,7 @@ static int smack_inode_removexattr(struct dentry *dentry, const char *name)
if (rc != 0) if (rc != 0)
return rc; return rc;
isp = d_backing_inode(dentry)->i_security; isp = smack_inode(d_backing_inode(dentry));
/* /*
* Don't do anything special for these. * Don't do anything special for these.
* XATTR_NAME_SMACKIPIN * XATTR_NAME_SMACKIPIN
...@@ -1632,7 +1632,7 @@ static int smack_mmap_file(struct file *file, ...@@ -1632,7 +1632,7 @@ static int smack_mmap_file(struct file *file,
if (unlikely(IS_PRIVATE(file_inode(file)))) if (unlikely(IS_PRIVATE(file_inode(file))))
return 0; return 0;
isp = file_inode(file)->i_security; isp = smack_inode(file_inode(file));
if (isp->smk_mmap == NULL) if (isp->smk_mmap == NULL)
return 0; return 0;
sbsp = file_inode(file)->i_sb->s_security; sbsp = file_inode(file)->i_sb->s_security;
...@@ -1979,7 +1979,7 @@ static int smack_kernel_act_as(struct cred *new, u32 secid) ...@@ -1979,7 +1979,7 @@ static int smack_kernel_act_as(struct cred *new, u32 secid)
static int smack_kernel_create_files_as(struct cred *new, static int smack_kernel_create_files_as(struct cred *new,
struct inode *inode) struct inode *inode)
{ {
struct inode_smack *isp = inode->i_security; struct inode_smack *isp = smack_inode(inode);
struct task_smack *tsp = smack_cred(new); struct task_smack *tsp = smack_cred(new);
tsp->smk_forked = isp->smk_inode; tsp->smk_forked = isp->smk_inode;
...@@ -2179,7 +2179,7 @@ static int smack_task_kill(struct task_struct *p, struct kernel_siginfo *info, ...@@ -2179,7 +2179,7 @@ static int smack_task_kill(struct task_struct *p, struct kernel_siginfo *info,
*/ */
static void smack_task_to_inode(struct task_struct *p, struct inode *inode) static void smack_task_to_inode(struct task_struct *p, struct inode *inode)
{ {
struct inode_smack *isp = inode->i_security; struct inode_smack *isp = smack_inode(inode);
struct smack_known *skp = smk_of_task_struct(p); struct smack_known *skp = smk_of_task_struct(p);
isp->smk_inode = skp; isp->smk_inode = skp;
...@@ -2642,7 +2642,7 @@ static int smack_inode_setsecurity(struct inode *inode, const char *name, ...@@ -2642,7 +2642,7 @@ static int smack_inode_setsecurity(struct inode *inode, const char *name,
const void *value, size_t size, int flags) const void *value, size_t size, int flags)
{ {
struct smack_known *skp; struct smack_known *skp;
struct inode_smack *nsp = inode->i_security; struct inode_smack *nsp = smack_inode(inode);
struct socket_smack *ssp; struct socket_smack *ssp;
struct socket *sock; struct socket *sock;
int rc = 0; int rc = 0;
...@@ -3250,7 +3250,7 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode) ...@@ -3250,7 +3250,7 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
if (inode == NULL) if (inode == NULL)
return; return;
isp = inode->i_security; isp = smack_inode(inode);
mutex_lock(&isp->smk_lock); mutex_lock(&isp->smk_lock);
/* /*
...@@ -4488,7 +4488,7 @@ static int smack_inode_copy_up(struct dentry *dentry, struct cred **new) ...@@ -4488,7 +4488,7 @@ static int smack_inode_copy_up(struct dentry *dentry, struct cred **new)
/* /*
* Get label from overlay inode and set it in create_sid * Get label from overlay inode and set it in create_sid
*/ */
isp = d_inode(dentry->d_parent)->i_security; isp = smack_inode(d_inode(dentry->d_parent));
skp = isp->smk_inode; skp = isp->smk_inode;
tsp->smk_task = skp; tsp->smk_task = skp;
*new = new_creds; *new = new_creds;
...@@ -4525,7 +4525,7 @@ static int smack_dentry_create_files_as(struct dentry *dentry, int mode, ...@@ -4525,7 +4525,7 @@ static int smack_dentry_create_files_as(struct dentry *dentry, int mode,
/* /*
* the attribute of the containing directory * the attribute of the containing directory
*/ */
isp = d_inode(dentry->d_parent)->i_security; isp = smack_inode(d_inode(dentry->d_parent));
if (isp->smk_flags & SMK_INODE_TRANSMUTE) { if (isp->smk_flags & SMK_INODE_TRANSMUTE) {
rcu_read_lock(); rcu_read_lock();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment