提交 80788c22 编写于 作者: C Casey Schaufler 提交者: Kees Cook

SELinux: 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: NCasey Schaufler <casey@schaufler-ca.com>
Reviewed-by: NKees Cook <keescook@chromium.org>
Signed-off-by: NKees Cook <keescook@chromium.org>
上级 33bf60ca
...@@ -273,7 +273,7 @@ static int __inode_security_revalidate(struct inode *inode, ...@@ -273,7 +273,7 @@ static int __inode_security_revalidate(struct inode *inode,
struct dentry *dentry, struct dentry *dentry,
bool may_sleep) bool may_sleep)
{ {
struct inode_security_struct *isec = inode->i_security; struct inode_security_struct *isec = selinux_inode(inode);
might_sleep_if(may_sleep); might_sleep_if(may_sleep);
...@@ -294,7 +294,7 @@ static int __inode_security_revalidate(struct inode *inode, ...@@ -294,7 +294,7 @@ static int __inode_security_revalidate(struct inode *inode,
static struct inode_security_struct *inode_security_novalidate(struct inode *inode) static struct inode_security_struct *inode_security_novalidate(struct inode *inode)
{ {
return inode->i_security; return selinux_inode(inode);
} }
static struct inode_security_struct *inode_security_rcu(struct inode *inode, bool rcu) static struct inode_security_struct *inode_security_rcu(struct inode *inode, bool rcu)
...@@ -304,7 +304,7 @@ static struct inode_security_struct *inode_security_rcu(struct inode *inode, boo ...@@ -304,7 +304,7 @@ static struct inode_security_struct *inode_security_rcu(struct inode *inode, boo
error = __inode_security_revalidate(inode, NULL, !rcu); error = __inode_security_revalidate(inode, NULL, !rcu);
if (error) if (error)
return ERR_PTR(error); return ERR_PTR(error);
return inode->i_security; return selinux_inode(inode);
} }
/* /*
...@@ -313,14 +313,14 @@ static struct inode_security_struct *inode_security_rcu(struct inode *inode, boo ...@@ -313,14 +313,14 @@ static struct inode_security_struct *inode_security_rcu(struct inode *inode, boo
static struct inode_security_struct *inode_security(struct inode *inode) static struct inode_security_struct *inode_security(struct inode *inode)
{ {
__inode_security_revalidate(inode, NULL, true); __inode_security_revalidate(inode, NULL, true);
return inode->i_security; return selinux_inode(inode);
} }
static struct inode_security_struct *backing_inode_security_novalidate(struct dentry *dentry) static struct inode_security_struct *backing_inode_security_novalidate(struct dentry *dentry)
{ {
struct inode *inode = d_backing_inode(dentry); struct inode *inode = d_backing_inode(dentry);
return inode->i_security; return selinux_inode(inode);
} }
/* /*
...@@ -331,7 +331,7 @@ static struct inode_security_struct *backing_inode_security(struct dentry *dentr ...@@ -331,7 +331,7 @@ static struct inode_security_struct *backing_inode_security(struct dentry *dentr
struct inode *inode = d_backing_inode(dentry); struct inode *inode = d_backing_inode(dentry);
__inode_security_revalidate(inode, dentry, true); __inode_security_revalidate(inode, dentry, true);
return inode->i_security; return selinux_inode(inode);
} }
static void inode_free_rcu(struct rcu_head *head) static void inode_free_rcu(struct rcu_head *head)
...@@ -344,7 +344,7 @@ static void inode_free_rcu(struct rcu_head *head) ...@@ -344,7 +344,7 @@ static void inode_free_rcu(struct rcu_head *head)
static void inode_free_security(struct inode *inode) static void inode_free_security(struct inode *inode)
{ {
struct inode_security_struct *isec = inode->i_security; struct inode_security_struct *isec = selinux_inode(inode);
struct superblock_security_struct *sbsec = inode->i_sb->s_security; struct superblock_security_struct *sbsec = inode->i_sb->s_security;
/* /*
...@@ -1354,7 +1354,7 @@ static int selinux_genfs_get_sid(struct dentry *dentry, ...@@ -1354,7 +1354,7 @@ static int selinux_genfs_get_sid(struct dentry *dentry,
static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dentry) static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dentry)
{ {
struct superblock_security_struct *sbsec = NULL; struct superblock_security_struct *sbsec = NULL;
struct inode_security_struct *isec = inode->i_security; struct inode_security_struct *isec = selinux_inode(inode);
u32 task_sid, sid = 0; u32 task_sid, sid = 0;
u16 sclass; u16 sclass;
struct dentry *dentry; struct dentry *dentry;
...@@ -1654,7 +1654,7 @@ static int inode_has_perm(const struct cred *cred, ...@@ -1654,7 +1654,7 @@ static int inode_has_perm(const struct cred *cred,
return 0; return 0;
sid = cred_sid(cred); sid = cred_sid(cred);
isec = inode->i_security; isec = selinux_inode(inode);
return avc_has_perm(&selinux_state, return avc_has_perm(&selinux_state,
sid, isec->sid, isec->sclass, perms, adp); sid, isec->sid, isec->sclass, perms, adp);
...@@ -2816,7 +2816,7 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir, ...@@ -2816,7 +2816,7 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir,
/* Possibly defer initialization to selinux_complete_init. */ /* Possibly defer initialization to selinux_complete_init. */
if (sbsec->flags & SE_SBINITIALIZED) { if (sbsec->flags & SE_SBINITIALIZED) {
struct inode_security_struct *isec = inode->i_security; struct inode_security_struct *isec = selinux_inode(inode);
isec->sclass = inode_mode_to_security_class(inode->i_mode); isec->sclass = inode_mode_to_security_class(inode->i_mode);
isec->sid = newsid; isec->sid = newsid;
isec->initialized = LABEL_INITIALIZED; isec->initialized = LABEL_INITIALIZED;
...@@ -2916,7 +2916,7 @@ static noinline int audit_inode_permission(struct inode *inode, ...@@ -2916,7 +2916,7 @@ static noinline int audit_inode_permission(struct inode *inode,
unsigned flags) unsigned flags)
{ {
struct common_audit_data ad; struct common_audit_data ad;
struct inode_security_struct *isec = inode->i_security; struct inode_security_struct *isec = selinux_inode(inode);
int rc; int rc;
ad.type = LSM_AUDIT_DATA_INODE; ad.type = LSM_AUDIT_DATA_INODE;
...@@ -3936,7 +3936,7 @@ static int selinux_task_kill(struct task_struct *p, struct kernel_siginfo *info, ...@@ -3936,7 +3936,7 @@ static int selinux_task_kill(struct task_struct *p, struct kernel_siginfo *info,
static void selinux_task_to_inode(struct task_struct *p, static void selinux_task_to_inode(struct task_struct *p,
struct inode *inode) struct inode *inode)
{ {
struct inode_security_struct *isec = inode->i_security; struct inode_security_struct *isec = selinux_inode(inode);
u32 sid = task_sid(p); u32 sid = task_sid(p);
spin_lock(&isec->lock); spin_lock(&isec->lock);
...@@ -6318,7 +6318,7 @@ static void selinux_release_secctx(char *secdata, u32 seclen) ...@@ -6318,7 +6318,7 @@ static void selinux_release_secctx(char *secdata, u32 seclen)
static void selinux_inode_invalidate_secctx(struct inode *inode) static void selinux_inode_invalidate_secctx(struct inode *inode)
{ {
struct inode_security_struct *isec = inode->i_security; struct inode_security_struct *isec = selinux_inode(inode);
spin_lock(&isec->lock); spin_lock(&isec->lock);
isec->initialized = LABEL_INVALID; isec->initialized = LABEL_INVALID;
......
...@@ -170,4 +170,10 @@ static inline struct file_security_struct *selinux_file(const struct file *file) ...@@ -170,4 +170,10 @@ static inline struct file_security_struct *selinux_file(const struct file *file)
return file->f_security + selinux_blob_sizes.lbs_file; return file->f_security + selinux_blob_sizes.lbs_file;
} }
static inline struct inode_security_struct *selinux_inode(
const struct inode *inode)
{
return inode->i_security;
}
#endif /* _SELINUX_OBJSEC_H_ */ #endif /* _SELINUX_OBJSEC_H_ */
...@@ -1378,7 +1378,7 @@ static int sel_make_bools(struct selinux_fs_info *fsi) ...@@ -1378,7 +1378,7 @@ static int sel_make_bools(struct selinux_fs_info *fsi)
goto out; goto out;
} }
isec = (struct inode_security_struct *)inode->i_security; isec = selinux_inode(inode);
ret = security_genfs_sid(fsi->state, "selinuxfs", page, ret = security_genfs_sid(fsi->state, "selinuxfs", page,
SECCLASS_FILE, &sid); SECCLASS_FILE, &sid);
if (ret) { if (ret) {
...@@ -1953,7 +1953,7 @@ static int sel_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1953,7 +1953,7 @@ static int sel_fill_super(struct super_block *sb, void *data, int silent)
} }
inode->i_ino = ++fsi->last_ino; inode->i_ino = ++fsi->last_ino;
isec = (struct inode_security_struct *)inode->i_security; isec = selinux_inode(inode);
isec->sid = SECINITSID_DEVNULL; isec->sid = SECINITSID_DEVNULL;
isec->sclass = SECCLASS_CHR_FILE; isec->sclass = SECCLASS_CHR_FILE;
isec->initialized = LABEL_INITIALIZED; isec->initialized = LABEL_INITIALIZED;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册