Commit 9548906b authored by Tetsuo Handa's avatar Tetsuo Handa Committed by James Morris

xattr: Constify ->name member of "struct xattr".

Since everybody sets kstrdup()ed constant string to "struct xattr"->name but
nobody modifies "struct xattr"->name , we can omit kstrdup() and its failure
checking by constifying ->name member of "struct xattr".
Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reviewed-by: Joel Becker <jlbec@evilplan.org> [ocfs2]
Acked-by: default avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
Acked-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
Acked-by: default avatarMimi Zohar <zohar@linux.vnet.ibm.com>
Reviewed-by: default avatarPaul Moore <paul@paul-moore.com>
Tested-by: default avatarPaul Moore <paul@paul-moore.com>
Acked-by: default avatarEric Paris <eparis@redhat.com>
Signed-off-by: default avatarJames Morris <james.l.morris@oracle.com>
parent be0306bc
...@@ -32,7 +32,7 @@ enum ocfs2_xattr_type { ...@@ -32,7 +32,7 @@ enum ocfs2_xattr_type {
struct ocfs2_security_xattr_info { struct ocfs2_security_xattr_info {
int enable; int enable;
char *name; const char *name;
void *value; void *value;
size_t value_len; size_t value_len;
}; };
......
...@@ -1492,7 +1492,7 @@ struct security_operations { ...@@ -1492,7 +1492,7 @@ struct security_operations {
int (*inode_alloc_security) (struct inode *inode); int (*inode_alloc_security) (struct inode *inode);
void (*inode_free_security) (struct inode *inode); void (*inode_free_security) (struct inode *inode);
int (*inode_init_security) (struct inode *inode, struct inode *dir, int (*inode_init_security) (struct inode *inode, struct inode *dir,
const struct qstr *qstr, char **name, const struct qstr *qstr, const char **name,
void **value, size_t *len); void **value, size_t *len);
int (*inode_create) (struct inode *dir, int (*inode_create) (struct inode *dir,
struct dentry *dentry, umode_t mode); struct dentry *dentry, umode_t mode);
...@@ -1770,7 +1770,7 @@ int security_inode_init_security(struct inode *inode, struct inode *dir, ...@@ -1770,7 +1770,7 @@ int security_inode_init_security(struct inode *inode, struct inode *dir,
const struct qstr *qstr, const struct qstr *qstr,
initxattrs initxattrs, void *fs_data); initxattrs initxattrs, void *fs_data);
int security_old_inode_init_security(struct inode *inode, struct inode *dir, int security_old_inode_init_security(struct inode *inode, struct inode *dir,
const struct qstr *qstr, char **name, const struct qstr *qstr, const char **name,
void **value, size_t *len); void **value, size_t *len);
int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode); int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode);
int security_inode_link(struct dentry *old_dentry, struct inode *dir, int security_inode_link(struct dentry *old_dentry, struct inode *dir,
...@@ -2094,8 +2094,8 @@ static inline int security_inode_init_security(struct inode *inode, ...@@ -2094,8 +2094,8 @@ static inline int security_inode_init_security(struct inode *inode,
static inline int security_old_inode_init_security(struct inode *inode, static inline int security_old_inode_init_security(struct inode *inode,
struct inode *dir, struct inode *dir,
const struct qstr *qstr, const struct qstr *qstr,
char **name, void **value, const char **name,
size_t *len) void **value, size_t *len)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
......
...@@ -31,7 +31,7 @@ struct xattr_handler { ...@@ -31,7 +31,7 @@ struct xattr_handler {
}; };
struct xattr { struct xattr {
char *name; const char *name;
void *value; void *value;
size_t value_len; size_t value_len;
}; };
......
...@@ -16,7 +16,7 @@ struct reiserfs_xattr_header { ...@@ -16,7 +16,7 @@ struct reiserfs_xattr_header {
}; };
struct reiserfs_security_handle { struct reiserfs_security_handle {
char *name; const char *name;
void *value; void *value;
size_t length; size_t length;
}; };
......
...@@ -129,7 +129,7 @@ static void cap_inode_free_security(struct inode *inode) ...@@ -129,7 +129,7 @@ static void cap_inode_free_security(struct inode *inode)
} }
static int cap_inode_init_security(struct inode *inode, struct inode *dir, static int cap_inode_init_security(struct inode *inode, struct inode *dir,
const struct qstr *qstr, char **name, const struct qstr *qstr, const char **name,
void **value, size_t *len) void **value, size_t *len)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
......
...@@ -418,7 +418,7 @@ int evm_inode_init_security(struct inode *inode, ...@@ -418,7 +418,7 @@ int evm_inode_init_security(struct inode *inode,
evm_xattr->value = xattr_data; evm_xattr->value = xattr_data;
evm_xattr->value_len = sizeof(*xattr_data); evm_xattr->value_len = sizeof(*xattr_data);
evm_xattr->name = kstrdup(XATTR_EVM_SUFFIX, GFP_NOFS); evm_xattr->name = XATTR_EVM_SUFFIX;
return 0; return 0;
out: out:
kfree(xattr_data); kfree(xattr_data);
......
...@@ -348,10 +348,10 @@ int security_inode_init_security(struct inode *inode, struct inode *dir, ...@@ -348,10 +348,10 @@ int security_inode_init_security(struct inode *inode, struct inode *dir,
if (unlikely(IS_PRIVATE(inode))) if (unlikely(IS_PRIVATE(inode)))
return 0; return 0;
memset(new_xattrs, 0, sizeof new_xattrs);
if (!initxattrs) if (!initxattrs)
return security_ops->inode_init_security(inode, dir, qstr, return security_ops->inode_init_security(inode, dir, qstr,
NULL, NULL, NULL); NULL, NULL, NULL);
memset(new_xattrs, 0, sizeof(new_xattrs));
lsm_xattr = new_xattrs; lsm_xattr = new_xattrs;
ret = security_ops->inode_init_security(inode, dir, qstr, ret = security_ops->inode_init_security(inode, dir, qstr,
&lsm_xattr->name, &lsm_xattr->name,
...@@ -366,16 +366,14 @@ int security_inode_init_security(struct inode *inode, struct inode *dir, ...@@ -366,16 +366,14 @@ int security_inode_init_security(struct inode *inode, struct inode *dir,
goto out; goto out;
ret = initxattrs(inode, new_xattrs, fs_data); ret = initxattrs(inode, new_xattrs, fs_data);
out: out:
for (xattr = new_xattrs; xattr->name != NULL; xattr++) { for (xattr = new_xattrs; xattr->value != NULL; xattr++)
kfree(xattr->name);
kfree(xattr->value); kfree(xattr->value);
}
return (ret == -EOPNOTSUPP) ? 0 : ret; return (ret == -EOPNOTSUPP) ? 0 : ret;
} }
EXPORT_SYMBOL(security_inode_init_security); EXPORT_SYMBOL(security_inode_init_security);
int security_old_inode_init_security(struct inode *inode, struct inode *dir, int security_old_inode_init_security(struct inode *inode, struct inode *dir,
const struct qstr *qstr, char **name, const struct qstr *qstr, const char **name,
void **value, size_t *len) void **value, size_t *len)
{ {
if (unlikely(IS_PRIVATE(inode))) if (unlikely(IS_PRIVATE(inode)))
......
...@@ -2587,7 +2587,8 @@ static int selinux_dentry_init_security(struct dentry *dentry, int mode, ...@@ -2587,7 +2587,8 @@ static int selinux_dentry_init_security(struct dentry *dentry, int mode,
} }
static int selinux_inode_init_security(struct inode *inode, struct inode *dir, static int selinux_inode_init_security(struct inode *inode, struct inode *dir,
const struct qstr *qstr, char **name, const struct qstr *qstr,
const char **name,
void **value, size_t *len) void **value, size_t *len)
{ {
const struct task_security_struct *tsec = current_security(); const struct task_security_struct *tsec = current_security();
...@@ -2595,7 +2596,7 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir, ...@@ -2595,7 +2596,7 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir,
struct superblock_security_struct *sbsec; struct superblock_security_struct *sbsec;
u32 sid, newsid, clen; u32 sid, newsid, clen;
int rc; int rc;
char *namep = NULL, *context; char *context;
dsec = dir->i_security; dsec = dir->i_security;
sbsec = dir->i_sb->s_security; sbsec = dir->i_sb->s_security;
...@@ -2631,19 +2632,13 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir, ...@@ -2631,19 +2632,13 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir,
if (!ss_initialized || !(sbsec->flags & SE_SBLABELSUPP)) if (!ss_initialized || !(sbsec->flags & SE_SBLABELSUPP))
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (name) { if (name)
namep = kstrdup(XATTR_SELINUX_SUFFIX, GFP_NOFS); *name = XATTR_SELINUX_SUFFIX;
if (!namep)
return -ENOMEM;
*name = namep;
}
if (value && len) { if (value && len) {
rc = security_sid_to_context_force(newsid, &context, &clen); rc = security_sid_to_context_force(newsid, &context, &clen);
if (rc) { if (rc)
kfree(namep);
return rc; return rc;
}
*value = context; *value = context;
*len = clen; *len = clen;
} }
......
...@@ -582,7 +582,7 @@ static void smack_inode_free_security(struct inode *inode) ...@@ -582,7 +582,7 @@ static void smack_inode_free_security(struct inode *inode)
* Returns 0 if it all works out, -ENOMEM if there's no memory * Returns 0 if it all works out, -ENOMEM if there's no memory
*/ */
static int smack_inode_init_security(struct inode *inode, struct inode *dir, static int smack_inode_init_security(struct inode *inode, struct inode *dir,
const struct qstr *qstr, 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 = inode->i_security;
...@@ -591,11 +591,8 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir, ...@@ -591,11 +591,8 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir,
char *dsp = smk_of_inode(dir); char *dsp = smk_of_inode(dir);
int may; int may;
if (name) { if (name)
*name = kstrdup(XATTR_SMACK_SUFFIX, GFP_NOFS); *name = XATTR_SMACK_SUFFIX;
if (*name == NULL)
return -ENOMEM;
}
if (value) { if (value) {
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