selinuxfs cleanups - fix hard link count
PATCH 1/5 selinuxfs cleanups - fix hard link count
This patch fixes the hard link count for selinuxfs directories, which are currently one short.
Please apply.
---
security/selinux/selinuxfs.c | 4 ++++ 1 file changed, 4 insertions(+)
security/selinux/selinuxfs.c +4 -0
@@ -1198,6 +1198,8 @@ static int sel_make_dir(struct super_blo } inode->i_op = &simple_dir_inode_operations; inode->i_fop = &simple_dir_operations; +/* directory inodes start off with i_nlink == 2 (for "." entry) */ + inode->i_nlink++;d_add (dentry, inode); out:return ret;
@@ -1239,6 +1241,8 @@ static int sel_fill_super(struct super_b goto out; inode->i_op = &simple_dir_inode_operations; inode->i_fop = &simple_dir_operations; +/* directory inodes start off with i_nlink == 2 (for "." entry) */ + inode->i_nlink++;d_add (dentry, inode); bool_dir = dentry; ret =sel_make_bools ();
PATCH 2/5 selinuxfs cleanups - use sel_make_dir()
Use existing sel_make_dir() helper to create booleans directory rather than duplicating the logic.
Please apply.
---
security/selinux/selinuxfs.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
security/selinux/selinuxfs.c +4 -8
@@ -1235,15 +1235,11 @@ static int sel_fill_super(struct super_b dentry =d_alloc_name (sb->s_root,BOOL_DIR_NAME );if (!dentry)return -ENOMEM ; + + ret =sel_make_dir (sb, dentry); +if (ret) +return ret; - inode =sel_make_inode (sb,S_IFDIR |S_IRUGO |S_IXUGO ); -if (!inode) - goto out; - inode->i_op = &simple_dir_inode_operations; - inode->i_fop = &simple_dir_operations; -/* directory inodes start off with i_nlink == 2 (for "." entry) */ - inode->i_nlink++; -d_add (dentry, inode); bool_dir = dentry; ret =sel_make_bools ();if (ret)
PATCH 3/5 selinuxfs cleanups - sel_fill_super exit path
In reply to James MorrisThis patch unifies the error path of sel_fill_super() so that all errors pass through the same point and generate an error message. Also, removes a spurious dput() in the error path which breaks the refcounting for the filesystem (litter_kill_super() will correctly clean things up itself on error).
Please apply.
---
selinuxfs.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-)
security/selinux/selinuxfs.c +24 -17
@@ -1230,28 +1230,34 @@ static int sel_fill_super(struct super_b }; ret =simple_fill_super (sb,SELINUX_MAGIC , selinux_files);if (ret) -return ret; + goto err; dentry =d_alloc_name (sb->s_root,BOOL_DIR_NAME ); -if (!dentry) -return -ENOMEM ; +if (!dentry) { + ret = -ENOMEM ; + goto err; + } ret =sel_make_dir (sb, dentry);if (ret) -return ret; + goto err; bool_dir = dentry; ret =sel_make_bools ();if (ret) - goto out; + goto err; dentry =d_alloc_name (sb->s_root,NULL_FILE_NAME ); -if (!dentry) -return -ENOMEM ; +if (!dentry) { + ret = -ENOMEM ; + goto err; + } inode =sel_make_inode (sb,S_IFCHR |S_IRUGO |S_IWUGO ); -if (!inode) - goto out; +if (!inode) { + ret = -ENOMEM ; + goto err; + } isec = (struct inode_security_struct *)inode->i_security; isec->sid =SECINITSID_DEVNULL ; isec->sclass =SECCLASS_CHR_FILE ;
@@ -1262,22 +1268,23 @@ static int sel_fill_super(struct super_b selinux_null = dentry; dentry =d_alloc_name (sb->s_root,"avc" ); -if (!dentry) -return -ENOMEM ; +if (!dentry) { + ret = -ENOMEM ; + goto err; + } ret =sel_make_dir (sb, dentry);if (ret) - goto out; + goto err; ret =sel_make_avc_files (dentry);if (ret) - goto out; - -return 0 ; + goto err; out: -dput (dentry); +return ret; +err:printk (KERN_ERR "%s: failed while creating inodes\n" , __FUNCTION__); -return -ENOMEM ; + goto out; } static struct super_block *sel_get_sb(struct file_system_type *fs_type,
PATCH 4/5 selinuxfs cleanups - sel_make_bools
In reply to James MorrisRemove the call to sel_make_bools() from sel_fill_super(), as policy needs to be loaded before the boolean files can be created. Policy will never be loaded during sel_fill_super() as selinuxfs is kernel mounted during init and the only means to load policy is via selinuxfs.
Also, the call to d_genocide() on the error path of sel_make_bools() is incorrect and replaced with sel_remove_bools().
Please apply.
--- security/selinux/selinuxfs.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
security/selinux/selinuxfs.c +1 -4
@@ -987,7 +987,7 @@ out:return ret; err:kfree (values); -d_genocide (dir); +sel_remove_bools (dir); ret = -ENOMEM ; goto out; }
@@ -1243,9 +1243,6 @@ static int sel_fill_super(struct super_b goto err; bool_dir = dentry; - ret =sel_make_bools (); -if (ret) - goto err; dentry =d_alloc_name (sb->s_root,NULL_FILE_NAME );if (!dentry) {
PATCH 5/5 selinuxfs cleanups - sel_make_avc_files
In reply to James MorrisFix copy & paste error in sel_make_avc_files(), removing a supurious call to d_genocide() in the error path. All of this will be cleaned up by kill_litter_super().
Please apply.
---
security/selinux/selinuxfs.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
security/selinux/selinuxfs.c +2 -5
@@ -1168,22 +1168,19 @@ static int sel_make_avc_files(struct den dentry =d_alloc_name (dir, files[i].name);if (!dentry) { ret = -ENOMEM ; - goto err; + goto out; } inode =sel_make_inode (dir->d_sb,S_IFREG |files[i].mode);if (!inode) { ret = -ENOMEM ; - goto err; + goto out; } inode->i_fop = files[i].ops;d_add (dentry, inode); } out:return ret; -err: -d_genocide (dir); - goto out; }static int sel_make_dir (struct super_block *sb,struct dentry *dentry)