Commit 66ec384a authored by Daniel Burgener's avatar Daniel Burgener Committed by Paul Moore

selinux: Refactor selinuxfs directory populating functions

Make sel_make_bools and sel_make_classes take the specific elements of
selinux_fs_info that they need rather than the entire struct.

This will allow a future patch to pass temporary elements that are not in
the selinux_fs_info struct to these functions so that the original elements
can be preserved until we are ready to perform the switch over.
Signed-off-by: default avatarDaniel Burgener <dburgener@linux.microsoft.com>
Acked-by: default avatarStephen Smalley <stephen.smalley.work@gmail.com>
Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
parent aeecf4a3
...@@ -346,10 +346,12 @@ static const struct file_operations sel_policyvers_ops = { ...@@ -346,10 +346,12 @@ static const struct file_operations sel_policyvers_ops = {
}; };
/* declaration for sel_write_load */ /* declaration for sel_write_load */
static int sel_make_bools(struct selinux_fs_info *fsi, static int sel_make_bools(struct selinux_policy *newpolicy, struct dentry *bool_dir,
struct selinux_policy *newpolicy); unsigned int *bool_num, char ***bool_pending_names,
static int sel_make_classes(struct selinux_fs_info *fsi, unsigned int **bool_pending_values);
struct selinux_policy *newpolicy); static int sel_make_classes(struct selinux_policy *newpolicy,
struct dentry *class_dir,
unsigned long *last_class_ino);
/* declaration for sel_make_class_dirs */ /* declaration for sel_make_class_dirs */
static struct dentry *sel_make_dir(struct dentry *dir, const char *name, static struct dentry *sel_make_dir(struct dentry *dir, const char *name,
...@@ -539,13 +541,15 @@ static int sel_make_policy_nodes(struct selinux_fs_info *fsi, ...@@ -539,13 +541,15 @@ static int sel_make_policy_nodes(struct selinux_fs_info *fsi,
sel_remove_old_policy_nodes(fsi); sel_remove_old_policy_nodes(fsi);
ret = sel_make_bools(fsi, newpolicy); ret = sel_make_bools(newpolicy, fsi->bool_dir, &fsi->bool_num,
&fsi->bool_pending_names, &fsi->bool_pending_values);
if (ret) { if (ret) {
pr_err("SELinux: failed to load policy booleans\n"); pr_err("SELinux: failed to load policy booleans\n");
return ret; return ret;
} }
ret = sel_make_classes(fsi, newpolicy); ret = sel_make_classes(newpolicy, fsi->class_dir,
&fsi->last_class_ino);
if (ret) { if (ret) {
pr_err("SELinux: failed to load policy classes\n"); pr_err("SELinux: failed to load policy classes\n");
return ret; return ret;
...@@ -1359,13 +1363,13 @@ static void sel_remove_entries(struct dentry *de) ...@@ -1359,13 +1363,13 @@ static void sel_remove_entries(struct dentry *de)
#define BOOL_DIR_NAME "booleans" #define BOOL_DIR_NAME "booleans"
static int sel_make_bools(struct selinux_fs_info *fsi, static int sel_make_bools(struct selinux_policy *newpolicy, struct dentry *bool_dir,
struct selinux_policy *newpolicy) unsigned int *bool_num, char ***bool_pending_names,
unsigned int **bool_pending_values)
{ {
int ret; int ret;
ssize_t len; ssize_t len;
struct dentry *dentry = NULL; struct dentry *dentry = NULL;
struct dentry *dir = fsi->bool_dir;
struct inode *inode = NULL; struct inode *inode = NULL;
struct inode_security_struct *isec; struct inode_security_struct *isec;
char **names = NULL, *page; char **names = NULL, *page;
...@@ -1384,12 +1388,12 @@ static int sel_make_bools(struct selinux_fs_info *fsi, ...@@ -1384,12 +1388,12 @@ static int sel_make_bools(struct selinux_fs_info *fsi,
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
ret = -ENOMEM; ret = -ENOMEM;
dentry = d_alloc_name(dir, names[i]); dentry = d_alloc_name(bool_dir, names[i]);
if (!dentry) if (!dentry)
goto out; goto out;
ret = -ENOMEM; ret = -ENOMEM;
inode = sel_make_inode(dir->d_sb, S_IFREG | S_IRUGO | S_IWUSR); inode = sel_make_inode(bool_dir->d_sb, S_IFREG | S_IRUGO | S_IWUSR);
if (!inode) { if (!inode) {
dput(dentry); dput(dentry);
goto out; goto out;
...@@ -1418,9 +1422,9 @@ static int sel_make_bools(struct selinux_fs_info *fsi, ...@@ -1418,9 +1422,9 @@ static int sel_make_bools(struct selinux_fs_info *fsi,
inode->i_ino = i|SEL_BOOL_INO_OFFSET; inode->i_ino = i|SEL_BOOL_INO_OFFSET;
d_add(dentry, inode); d_add(dentry, inode);
} }
fsi->bool_num = num; *bool_num = num;
fsi->bool_pending_names = names; *bool_pending_names = names;
fsi->bool_pending_values = values; *bool_pending_values = values;
free_page((unsigned long)page); free_page((unsigned long)page);
return 0; return 0;
...@@ -1433,7 +1437,7 @@ static int sel_make_bools(struct selinux_fs_info *fsi, ...@@ -1433,7 +1437,7 @@ static int sel_make_bools(struct selinux_fs_info *fsi,
kfree(names); kfree(names);
} }
kfree(values); kfree(values);
sel_remove_entries(dir); sel_remove_entries(bool_dir);
return ret; return ret;
} }
...@@ -1880,8 +1884,9 @@ static int sel_make_class_dir_entries(struct selinux_policy *newpolicy, ...@@ -1880,8 +1884,9 @@ static int sel_make_class_dir_entries(struct selinux_policy *newpolicy,
return rc; return rc;
} }
static int sel_make_classes(struct selinux_fs_info *fsi, static int sel_make_classes(struct selinux_policy *newpolicy,
struct selinux_policy *newpolicy) struct dentry *class_dir,
unsigned long *last_class_ino)
{ {
int rc, nclasses, i; int rc, nclasses, i;
...@@ -1892,13 +1897,13 @@ static int sel_make_classes(struct selinux_fs_info *fsi, ...@@ -1892,13 +1897,13 @@ static int sel_make_classes(struct selinux_fs_info *fsi,
return rc; return rc;
/* +2 since classes are 1-indexed */ /* +2 since classes are 1-indexed */
fsi->last_class_ino = sel_class_to_ino(nclasses + 2); *last_class_ino = sel_class_to_ino(nclasses + 2);
for (i = 0; i < nclasses; i++) { for (i = 0; i < nclasses; i++) {
struct dentry *class_name_dir; struct dentry *class_name_dir;
class_name_dir = sel_make_dir(fsi->class_dir, classes[i], class_name_dir = sel_make_dir(class_dir, classes[i],
&fsi->last_class_ino); last_class_ino);
if (IS_ERR(class_name_dir)) { if (IS_ERR(class_name_dir)) {
rc = PTR_ERR(class_name_dir); rc = PTR_ERR(class_name_dir);
goto out; goto out;
......
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