stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Burgener <dburgener@linux.microsoft.com>
To: stable@vger.kernel.org
Cc: stephen.smalley.work@gmail.com, paul@paul-moore.com,
	selinux@vger.kernel.org, jmorris@namei.org, sashal@kernel.org
Subject: [PATCH v5.4 v2 1/4] selinux: Create function for selinuxfs directory cleanup
Date: Fri, 16 Oct 2020 09:48:32 -0400	[thread overview]
Message-ID: <20201016134835.1886478-2-dburgener@linux.microsoft.com> (raw)
In-Reply-To: <20201016134835.1886478-1-dburgener@linux.microsoft.com>

upstream commit aeecf4a3fb11954cb10b8bc57e1661a6e4e9f3a9

Separating the cleanup from the creation will simplify two things in
future patches in this series.  First, the creation can be made generic,
to create directories not tied to the selinux_fs_info structure.  Second,
we will ultimately want to reorder creation and deletion so that the
deletions aren't performed until the new directory structures have already
been moved into place.

Signed-off-by: Daniel Burgener <dburgener@linux.microsoft.com>
---
 security/selinux/selinuxfs.c | 39 +++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 14 deletions(-)

diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index e9eaff90cbcc..092c7295f78d 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -348,6 +348,9 @@ static int sel_make_policycap(struct selinux_fs_info *fsi);
 static struct dentry *sel_make_dir(struct dentry *dir, const char *name,
 			unsigned long *ino);
 
+/* declaration for sel_remove_old_policy_nodes */
+static void sel_remove_entries(struct dentry *de);
+
 static ssize_t sel_read_mls(struct file *filp, char __user *buf,
 				size_t count, loff_t *ppos)
 {
@@ -502,10 +505,32 @@ static const struct file_operations sel_policy_ops = {
 	.llseek		= generic_file_llseek,
 };
 
+static void sel_remove_old_policy_nodes(struct selinux_fs_info *fsi)
+{
+	u32 i;
+
+	/* bool_dir cleanup */
+	for (i = 0; i < fsi->bool_num; i++)
+		kfree(fsi->bool_pending_names[i]);
+	kfree(fsi->bool_pending_names);
+	kfree(fsi->bool_pending_values);
+	fsi->bool_num = 0;
+	fsi->bool_pending_names = NULL;
+	fsi->bool_pending_values = NULL;
+
+	sel_remove_entries(fsi->bool_dir);
+
+	/* class_dir cleanup */
+	sel_remove_entries(fsi->class_dir);
+
+}
+
 static int sel_make_policy_nodes(struct selinux_fs_info *fsi)
 {
 	int ret;
 
+	sel_remove_old_policy_nodes(fsi);
+
 	ret = sel_make_bools(fsi);
 	if (ret) {
 		pr_err("SELinux: failed to load policy booleans\n");
@@ -1336,17 +1361,6 @@ static int sel_make_bools(struct selinux_fs_info *fsi)
 	int *values = NULL;
 	u32 sid;
 
-	/* remove any existing files */
-	for (i = 0; i < fsi->bool_num; i++)
-		kfree(fsi->bool_pending_names[i]);
-	kfree(fsi->bool_pending_names);
-	kfree(fsi->bool_pending_values);
-	fsi->bool_num = 0;
-	fsi->bool_pending_names = NULL;
-	fsi->bool_pending_values = NULL;
-
-	sel_remove_entries(dir);
-
 	ret = -ENOMEM;
 	page = (char *)get_zeroed_page(GFP_KERNEL);
 	if (!page)
@@ -1798,9 +1812,6 @@ static int sel_make_classes(struct selinux_fs_info *fsi)
 	int rc, nclasses, i;
 	char **classes;
 
-	/* delete any existing entries */
-	sel_remove_entries(fsi->class_dir);
-
 	rc = security_get_classes(fsi->state, &classes, &nclasses);
 	if (rc)
 		return rc;
-- 
2.25.4


  reply	other threads:[~2020-10-16 13:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-16 13:48 [PATCH v5.4 v2 0/4] Update SELinuxfs out of tree and then swapover Daniel Burgener
2020-10-16 13:48 ` Daniel Burgener [this message]
2020-10-16 13:48 ` [PATCH v5.4 v2 2/4] selinux: Refactor selinuxfs directory populating functions Daniel Burgener
2020-10-16 13:48 ` [PATCH v5.4 v2 3/4] selinux: Standardize string literal usage for selinuxfs directory names Daniel Burgener
2020-10-16 13:48 ` [PATCH v5.4 v2 4/4] selinux: Create new booleans and class dirs out of tree Daniel Burgener
2020-10-16 15:01 ` [PATCH v5.4 v2 0/4] Update SELinuxfs out of tree and then swapover Greg KH
2020-10-16 15:38   ` Sasha Levin
2020-10-16 15:44     ` Greg KH
2020-10-16 15:49       ` Sasha Levin
2020-10-16 16:01         ` Daniel Burgener
2020-10-16 22:56           ` Paul Moore

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201016134835.1886478-2-dburgener@linux.microsoft.com \
    --to=dburgener@linux.microsoft.com \
    --cc=jmorris@namei.org \
    --cc=paul@paul-moore.com \
    --cc=sashal@kernel.org \
    --cc=selinux@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=stephen.smalley.work@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).