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:
committed by
Zbigniew Jędrzejewski-Szmek
parent
ffb3c2bd70
commit
08c849815c
@@ -79,7 +79,7 @@ static int node_symlink(struct udev_device *dev, const char *node, const char *s
|
||||
buf[len] = '\0';
|
||||
if (streq(target, buf)) {
|
||||
log_debug("preserve already existing symlink '%s' to '%s'", slink, target);
|
||||
label_fix(slink, true, false);
|
||||
(void) label_fix(slink, LABEL_IGNORE_ENOENT);
|
||||
utimensat(AT_FDCWD, slink, NULL, AT_SYMLINK_NOFOLLOW);
|
||||
goto exit;
|
||||
}
|
||||
@@ -324,7 +324,7 @@ static int node_permissions_apply(struct udev_device *dev, bool apply,
|
||||
|
||||
/* set the defaults */
|
||||
if (!selinux)
|
||||
mac_selinux_fix(devnode, true, false);
|
||||
(void) mac_selinux_fix(devnode, LABEL_IGNORE_ENOENT);
|
||||
if (!smack)
|
||||
mac_smack_apply(devnode, SMACK_ATTR_ACCESS, NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user