mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-21 20:07:13 +07:00
c7c556f1e8
Refactor the logic for changing SELinux policy booleans in a similar manner to the refactoring of policy load, thereby reducing the size of the critical section when the policy write-lock is held and making it easier to convert the policy rwlock to RCU in the future. Instead of directly modifying the policydb in place, modify a copy and then swap it into place through a single pointer update. Only fully copy the portions of the policydb that are affected by boolean changes to avoid the full cost of a deep policydb copy. Introduce another level of indirection for the sidtab since changing booleans does not require updating the sidtab, unlike policy load. While we are here, create a common helper for notifying other kernel components and userspace of a policy change and call it from both security_set_bools() and selinux_policy_commit(). Based on an old (2004) patch by Kaigai Kohei [1] to convert the policy rwlock to RCU that was deferred at the time since it did not significantly improve performance and introduced complexity. Peter Enderborg later submitted a patch series to convert to RCU [2] that would have made changing booleans a much more expensive operation by requiring a full policydb_write();policydb_read(); sequence to deep copy the entire policydb and also had concerns regarding atomic allocations. This change is now simplified by the earlier work to encapsulate policy state in the selinux_policy struct and to refactor policy load. After this change, the last major obstacle to converting the policy rwlock to RCU is likely the sidtab live convert support. [1] https://lore.kernel.org/selinux/6e2f9128-e191-ebb3-0e87-74bfccb0767f@tycho.nsa.gov/ [2] https://lore.kernel.org/selinux/20180530141104.28569-1-peter.enderborg@sony.com/ Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
44 lines
1.1 KiB
C
44 lines
1.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* Implementation of the security services.
|
|
*
|
|
* Author : Stephen Smalley, <sds@tycho.nsa.gov>
|
|
*/
|
|
#ifndef _SS_SERVICES_H_
|
|
#define _SS_SERVICES_H_
|
|
|
|
#include "policydb.h"
|
|
|
|
/* Mapping for a single class */
|
|
struct selinux_mapping {
|
|
u16 value; /* policy value for class */
|
|
unsigned int num_perms; /* number of permissions in class */
|
|
u32 perms[sizeof(u32) * 8]; /* policy values for permissions */
|
|
};
|
|
|
|
/* Map for all of the classes, with array size */
|
|
struct selinux_map {
|
|
struct selinux_mapping *mapping; /* indexed by class */
|
|
u16 size; /* array size of mapping */
|
|
};
|
|
|
|
struct selinux_policy {
|
|
struct sidtab *sidtab;
|
|
struct policydb policydb;
|
|
struct selinux_map map;
|
|
};
|
|
|
|
struct selinux_ss {
|
|
rwlock_t policy_rwlock;
|
|
u32 latest_granting;
|
|
struct selinux_policy *policy;
|
|
} __randomize_layout;
|
|
|
|
void services_compute_xperms_drivers(struct extended_perms *xperms,
|
|
struct avtab_node *node);
|
|
|
|
void services_compute_xperms_decision(struct extended_perms_decision *xpermd,
|
|
struct avtab_node *node);
|
|
|
|
#endif /* _SS_SERVICES_H_ */
|