label: rework label_fix() implementations (#8583)

This reworks the SELinux and SMACK label fixing calls in a number of
ways:

1. The two separate boolean arguments of these functions are converted
   into a flags type LabelFixFlags.

2. The operations are now implemented based on O_PATH. This should
   resolve TTOCTTOU races between determining the label for the file
   system object and applying it, as it it allows to pin the object
   while we are operating on it.

3. When changing a label fails we'll query the label previously set, and
   if matches what we want to set anyway we'll suppress the error.

Also, all calls to label_fix() are now (void)ified, when we ignore the
return values.

Fixes: #8566
This commit is contained in:
Lennart Poettering
2018-03-27 07:38:26 +02:00
committed by Zbigniew Jędrzejewski-Szmek
parent ffb3c2bd70
commit 08c849815c
14 changed files with 128 additions and 82 deletions
+5 -5
View File
@@ -28,11 +28,11 @@
#include "selinux-util.h"
#include "smack-util.h"
int label_fix(const char *path, bool ignore_enoent, bool ignore_erofs) {
int label_fix(const char *path, LabelFixFlags flags) {
int r, q;
r = mac_selinux_fix(path, ignore_enoent, ignore_erofs);
q = mac_smack_fix(path, ignore_enoent, ignore_erofs);
r = mac_selinux_fix(path, flags);
q = mac_smack_fix(path, flags);
if (r < 0)
return r;
@@ -60,7 +60,7 @@ int symlink_label(const char *old_path, const char *new_path) {
if (r < 0)
return r;
return mac_smack_fix(new_path, false, false);
return mac_smack_fix(new_path, 0);
}
int btrfs_subvol_make_label(const char *path) {
@@ -78,5 +78,5 @@ int btrfs_subvol_make_label(const char *path) {
if (r < 0)
return r;
return mac_smack_fix(path, false, false);
return mac_smack_fix(path, 0);
}