Commit edb20fb5 authored by James Morris's avatar James Morris Committed by Linus Torvalds

[PATCH] SELinux: fix hard link count for selinuxfs root directory

A further fix is needed for selinuxfs link count management, to ensure that
the count is correct for the parent directory when a subdirectory is
created.  This is only required for the root directory currently, but the
code has been updated for the general case.
Signed-off-by: default avatarJames Morris <jmorris@namei.org>
Acked-by: default avatarStephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent d6aafa65
...@@ -1166,12 +1166,12 @@ static int sel_make_avc_files(struct dentry *dir) ...@@ -1166,12 +1166,12 @@ static int sel_make_avc_files(struct dentry *dir)
return ret; return ret;
} }
static int sel_make_dir(struct super_block *sb, struct dentry *dentry) static int sel_make_dir(struct inode *dir, struct dentry *dentry)
{ {
int ret = 0; int ret = 0;
struct inode *inode; struct inode *inode;
inode = sel_make_inode(sb, S_IFDIR | S_IRUGO | S_IXUGO); inode = sel_make_inode(dir->i_sb, S_IFDIR | S_IRUGO | S_IXUGO);
if (!inode) { if (!inode) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
...@@ -1181,6 +1181,8 @@ static int sel_make_dir(struct super_block *sb, struct dentry *dentry) ...@@ -1181,6 +1181,8 @@ static int sel_make_dir(struct super_block *sb, struct dentry *dentry)
/* directory inodes start off with i_nlink == 2 (for "." entry) */ /* directory inodes start off with i_nlink == 2 (for "." entry) */
inode->i_nlink++; inode->i_nlink++;
d_add(dentry, inode); d_add(dentry, inode);
/* bump link count on parent directory, too */
dir->i_nlink++;
out: out:
return ret; return ret;
} }
...@@ -1189,7 +1191,7 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent) ...@@ -1189,7 +1191,7 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent)
{ {
int ret; int ret;
struct dentry *dentry; struct dentry *dentry;
struct inode *inode; struct inode *inode, *root_inode;
struct inode_security_struct *isec; struct inode_security_struct *isec;
static struct tree_descr selinux_files[] = { static struct tree_descr selinux_files[] = {
...@@ -1212,13 +1214,15 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent) ...@@ -1212,13 +1214,15 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent)
if (ret) if (ret)
goto err; goto err;
root_inode = sb->s_root->d_inode;
dentry = d_alloc_name(sb->s_root, BOOL_DIR_NAME); dentry = d_alloc_name(sb->s_root, BOOL_DIR_NAME);
if (!dentry) { if (!dentry) {
ret = -ENOMEM; ret = -ENOMEM;
goto err; goto err;
} }
ret = sel_make_dir(sb, dentry); ret = sel_make_dir(root_inode, dentry);
if (ret) if (ret)
goto err; goto err;
...@@ -1250,7 +1254,7 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent) ...@@ -1250,7 +1254,7 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent)
goto err; goto err;
} }
ret = sel_make_dir(sb, dentry); ret = sel_make_dir(root_inode, dentry);
if (ret) if (ret)
goto err; goto err;
......
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