selinux: shrink critical section in sel_write_load()
Stephen Smalley
maintainerPATCH 1/1 selinux: shrink critical section in sel_write_load()
Currently sel_write_load() takes the policy mutex earlier than necessary. Move the taking of the mutex later and drop it as soon as we are done committing the new policy. This avoids holding it unnecessarily across the vmalloc() and copy_from_user() for the policy data.
Signed-off-by Stephen Smalley <[email protected]>
--- security/selinux/selinuxfs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
security/selinux/selinuxfs.c +6 -3
@@ -592,8 +592,6 @@ static ssize_t sel_write_load(struct file *file, const char __user *buf,if (!count)return -EINVAL ; -mutex_lock (&selinux_state.policy_mutex); - length =avc_has_perm (current_sid (),SECINITSID_SECURITY ,SECCLASS_SECURITY ,SECURITY__LOAD_POLICY ,NULL );if (length)
@@ -614,15 +612,21 @@ static ssize_t sel_write_load(struct file *file, const char __user *buf,pr_warn_ratelimited ("SELinux: failed to load policy\n" ); goto out; } + fsi =file_inode (file)->i_sb->s_fs_info; + +mutex_lock (&selinux_state.policy_mutex); length =sel_make_policy_nodes (fsi, load_state.policy);if (length) {pr_warn_ratelimited ("SELinux: failed to initialize selinuxfs\n" );selinux_policy_cancel (&load_state); +mutex_unlock (&selinux_state.policy_mutex); goto out; }selinux_policy_commit (&load_state); +mutex_unlock (&selinux_state.policy_mutex); + length = count; audit_log(audit_context(), GFP_KERNEL, AUDIT_MAC_POLICY_LOAD, "auid=%u ses=%u lsm=selinux res=1",
@@ -630,7 +634,6 @@ static ssize_t sel_write_load(struct file *file, const char __user *buf, audit_get_sessionid(current)); out: -mutex_unlock (&selinux_state.policy_mutex);vfree (data);return length; }
Signature · 1 line
2.53.0
Stephen Smalley
maintainerQuoted 9 lines · Stephen Smalley
Currently
sel_write_load()takes the policy mutex earlier than necessary. Move the taking of the mutex later and drop it as soon as we are done committing the new policy. This avoids holding it unnecessarily across thevmalloc()andcopy_from_user()for the policy data.Signed-off-by Stephen Smalley <[email protected]>---
Sorry, this is wrong - please ignore.
v2 coming up.