Skip to content

Update SELinuxfs out of tree and then swapover

Daniel Burgener selinux stable 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest4 patches 6 repliesIn review
  2. v13 patches 8 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4selinux: Create function for selinuxfs directory cleanupsecurity/selinux/selinuxfs.c+25 -140 replies
2/4selinux: Refactor selinuxfs directory populating functionssecurity/selinux/selinuxfs.c+24 -160 replies
3/4selinux: Standardize string literal usage for selinuxfs directory namessecurity/selinux/selinuxfs.c+6 -20 replies
4/4selinux: Create new booleans and class dirs out of treesecurity/selinux/selinuxfs.c+93 -260 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v5.4 v2 0/4] Update SELinuxfs out of tree and then swapover

v2: Include all commits from original series, and include commit ids

This is a backport for stable of my series to fix a race condition in selinuxfs during policy load:

selinux: Create function for selinuxfs directory cleanup
https://lore.kernel.org/selinux/[email protected]/

selinux: Refactor selinuxfs directory populating functions
https://lore.kernel.org/selinux/[email protected]/

selinux: Standardize string literal usage for selinuxfs directory names
https://lore.kernel.org/selinux/[email protected]/

selinux: Create new booleans and class dirs out of tree
https://lore.kernel.org/selinux/[email protected]/

Several changes were necessary to backport. They are detailed in the commit message for the third commit in the series.

The bulk of the original cover letter is reproduced below.

In the current implementation, on policy load /sys/fs/selinux is updated by deleting the previous contents of /sys/fs/selinux/{class,booleans} and then recreating them. This means that there is a period of time when the contents of these directories do not exist which can cause race conditions as userspace relies on them for information about the policy. In addition, it means that error recovery in the event of failure is challenging.

This patch series follows the design outlined by Al Viro in a previous e-mail to the list[1]. This approach is to first create the new directory structures out of tree, then to perform the swapover, and finally to delete the old directories. Not handled in this series is error recovery in the event of failure.

Error recovery in the selinuxfs recreation is unhandled in the current code, so this series will not cause any regression in this regard. Handling directory recreation in this manner is a prerequisite to make proper error handling possible.

In order to demonstrate the race condition that this series fixes, you can use the following commands:

while true; do cat /sys/fs/selinux/class/service/perms/status

Quoted 1 line

/dev/null; done &

while true; do load_policy; done;

In the existing code, this will display errors fairly often as the class lookup fails. (In normal operation from systemd, this would result in a permission check which would be allowed or denied based on policy settings around unknown object classes.) After applying this patch series you should expect to no longer see such error messages.

Daniel Burgener (4):
selinux: Create function for selinuxfs directory cleanup
selinux: Refactor selinuxfs directory populating functions
selinux: Standardize string literal usage for selinuxfs directory
names
selinux: Create new booleans and class dirs out of tree

 security/selinux/selinuxfs.c | 168 +++++++++++++++++++++++++++--------
 1 file changed, 129 insertions(+), 39 deletions(-)
Signature · 1 line
2.25.4