Skip to content

Commit 714362f

Browse files
stephensmalleygregkh
authored andcommitted
selinux: allow multiple opens of /sys/fs/selinux/policy
commit a02cd68 upstream. Currently there can only be a single open of /sys/fs/selinux/policy at any time. This allows any process to block any other process from reading the kernel policy. The original motivation seems to have been a mix of preventing an inconsistent view of the policy size and preventing userspace from allocating kernel memory without bound, but this is arguably equally bad. Eliminate the policy_opened flag and shrink the critical section that the policy mutex is held. While we are making changes here, drop a couple of extraneous BUG_ONs. Cc: stable@vger.kernel.org Link: https://lore.kernel.org/selinux/20100726193414.19538.64028.stgit@paris.rdu.redhat.com/ Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com> Signed-off-by: Paul Moore <paul@paul-moore.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 579d3e4 commit 714362f

1 file changed

Lines changed: 4 additions & 23 deletions

File tree

security/selinux/selinuxfs.c

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ struct selinux_fs_info {
7676
int *bool_pending_values;
7777
struct dentry *class_dir;
7878
unsigned long last_class_ino;
79-
bool policy_opened;
8079
unsigned long last_ino;
8180
struct super_block *sb;
8281
};
@@ -340,44 +339,31 @@ struct policy_load_memory {
340339

341340
static int sel_open_policy(struct inode *inode, struct file *filp)
342341
{
343-
struct selinux_fs_info *fsi = inode->i_sb->s_fs_info;
344342
struct policy_load_memory *plm = NULL;
345343
int rc;
346344

347-
BUG_ON(filp->private_data);
348-
349-
mutex_lock(&selinux_state.policy_mutex);
350-
351345
rc = avc_has_perm(current_sid(), SECINITSID_SECURITY,
352346
SECCLASS_SECURITY, SECURITY__READ_POLICY, NULL);
353347
if (rc)
354-
goto err;
355-
356-
rc = -EBUSY;
357-
if (fsi->policy_opened)
358-
goto err;
348+
return rc;
359349

360-
rc = -ENOMEM;
361350
plm = kzalloc_obj(*plm);
362351
if (!plm)
363-
goto err;
352+
return -ENOMEM;
364353

354+
mutex_lock(&selinux_state.policy_mutex);
365355
rc = security_read_policy(&plm->data, &plm->len);
366356
if (rc)
367357
goto err;
368-
369358
if ((size_t)i_size_read(inode) != plm->len) {
370359
inode_lock(inode);
371360
i_size_write(inode, plm->len);
372361
inode_unlock(inode);
373362
}
374-
375-
fsi->policy_opened = 1;
363+
mutex_unlock(&selinux_state.policy_mutex);
376364

377365
filp->private_data = plm;
378366

379-
mutex_unlock(&selinux_state.policy_mutex);
380-
381367
return 0;
382368
err:
383369
mutex_unlock(&selinux_state.policy_mutex);
@@ -390,13 +376,8 @@ static int sel_open_policy(struct inode *inode, struct file *filp)
390376

391377
static int sel_release_policy(struct inode *inode, struct file *filp)
392378
{
393-
struct selinux_fs_info *fsi = inode->i_sb->s_fs_info;
394379
struct policy_load_memory *plm = filp->private_data;
395380

396-
BUG_ON(!plm);
397-
398-
fsi->policy_opened = 0;
399-
400381
vfree(plm->data);
401382
kfree(plm);
402383

0 commit comments

Comments
 (0)