@@ -513,7 +513,8 @@ static int ll_dir_setdirstripe(struct dentry *dparent, struct lmv_user_md *lump,
* to determine the security context for the file. So our fake
* dentry should be real enough for this purpose.
*/
- err = ll_dentry_init_security(&dentry, mode, &dentry.d_name,
+ err = ll_dentry_init_security(parent,
+ &dentry, mode, &dentry.d_name,
&op_data->op_file_secctx_name,
&op_data->op_file_secctx,
&op_data->op_file_secctx_size);
@@ -447,7 +447,8 @@ static inline void obd_connect_set_secctx(struct obd_connect_data *data)
#endif
}
-int ll_dentry_init_security(struct dentry *dentry, int mode, struct qstr *name,
+int ll_dentry_init_security(struct inode *parent, struct dentry *dentry,
+ int mode, struct qstr *name,
const char **secctx_name, void **secctx,
u32 *secctx_size);
int ll_inode_init_security(struct dentry *dentry, struct inode *inode,
@@ -891,7 +891,8 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
if (it->it_op & IT_CREAT &&
test_bit(LL_SBI_FILE_SECCTX, ll_i2sbi(parent)->ll_flags)) {
- rc = ll_dentry_init_security(dentry, it->it_create_mode,
+ rc = ll_dentry_init_security(parent,
+ dentry, it->it_create_mode,
&dentry->d_name,
&op_data->op_file_secctx_name,
&op_data->op_file_secctx,
@@ -1570,7 +1571,8 @@ static int ll_new_node(struct inode *dir, struct dentry *dchild,
ll_qos_mkdir_prep(op_data, dir);
if (test_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags)) {
- err = ll_dentry_init_security(dchild, mode, &dchild->d_name,
+ err = ll_dentry_init_security(dir,
+ dchild, mode, &dchild->d_name,
&op_data->op_file_secctx_name,
&op_data->op_file_secctx,
&op_data->op_file_secctx_size);
@@ -38,7 +38,8 @@
/*
* Check for LL_SBI_FILE_SECCTX before calling.
*/
-int ll_dentry_init_security(struct dentry *dentry, int mode, struct qstr *name,
+int ll_dentry_init_security(struct inode *parent, struct dentry *dentry,
+ int mode, struct qstr *name,
const char **secctx_name, void **secctx,
u32 *secctx_size)
{
@@ -58,6 +59,15 @@ int ll_dentry_init_security(struct dentry *dentry, int mode, struct qstr *name,
* from SELinux.
*/
+ /* fetch length of security xattr name */
+ rc = security_inode_listsecurity(parent, NULL, 0);
+ /* xattr name length == 0 means SELinux is disabled */
+ if (rc == 0)
+ return 0;
+ /* we support SELinux only */
+ if (rc != strlen(XATTR_NAME_SELINUX) + 1)
+ return -EOPNOTSUPP;
+
rc = security_dentry_init_security(dentry, mode, name, secctx,
secctx_size);
/* Usually, security_dentry_init_security() returns -EOPNOTSUPP when