Setting security XATTR on ubifs
Subodh Nijsure
snijsure at grid-net.com
Fri May 20 19:36:41 EDT 2011
we have implemented modifications to UBIFS to add support for SELinux
labeling. Function that created this XATTR is called
ubifs_init_security(), shown below.
Following example of how JFFS2 does extended attribute labeling, This
function is being called from
ubifs_create(),ubifs_mkdir(), ubifs_mknod(), ubifs_symlink() (in
fs/ubifs/dir.c)
With this modification things work "mostly", I am able to label the file
system, but sometimes the file system is getting corrupted. I will
certainly post the patch once things work reliably.
I don't _fully_ understand how ubifs is doing space management, hence
the immediate questions I have are:
1. What is the right point to add the XATTR to the UBIFS inode, after
the ubifs_new_inode() is done? Should ubifs_budget_space() be updated to
handle extra space needed by the XATTR.
2. In function below ui_mutex is being locked/unlocked while XATTR for
the file is updated. Is that required while updating the extended
attribute?
-Subodh Nijsure
static void ubifs_init_security(struct dentry *dentry, struct inode
*inode, struct inode *dir)
{
int err;
char *name;
void *value = NULL;
size_t len = 0;
struct ubifs_inode *dir_ui = ubifs_inode(dir);
mutex_lock(&dir_ui->ui_mutex);
err = security_inode_init_security(inode, dir, &name, &value,
&len);
if (err) {
if (err == -EOPNOTSUPP)
return;
ubifs_err("unable to retrieve security context, error %
d", err);
mutex_unlock(&dir_ui->ui_mutex);
return;
}
err = ubifs_setxattr(dentry, name, value, len, 0);
if (err)
ubifs_err("unable to set security context (extended
attribute), err %d",err);
kfree(name);
if ( value )
kfree(value);
mutex_unlock(&dir_ui->ui_mutex);
}
More information about the linux-mtd
mailing list