aboutsummaryrefslogtreecommitdiffstats
path: root/libselinux/src/reject_unknown.c
diff options
context:
space:
mode:
authorStephen Smalley <sds@tycho.nsa.gov>2019-02-25 10:49:02 -0500
committerPetr Lautrbach <plautrba@redhat.com>2019-03-01 12:51:31 +0100
commitc19395d72295f5e69275d98df5db22dfdf214b6c (patch)
treeea2410795ff7827e9b20f1005876d03b0226a01f /libselinux/src/reject_unknown.c
parent478c745d82d7c8bb4b15209408335a97891dc4ae (diff)
downloadandroid_external_selinux-c19395d72295f5e69275d98df5db22dfdf214b6c.tar.gz
android_external_selinux-c19395d72295f5e69275d98df5db22dfdf214b6c.tar.bz2
android_external_selinux-c19395d72295f5e69275d98df5db22dfdf214b6c.zip
libselinux: selinux_set_mapping: fix handling of unknown classes/perms
The libselinux selinux_set_mapping() implementation was never updated to handle unknown classes/permissions based on the policy handle_unknown flag. Update it and the internal mapping functions to gracefully handle unknown classes/permissions. Add a security_reject_unknown() interface to expose the corresponding selinuxfs node and use it when creating a mapping to decide whether to fail immediately or proceed. This enables dbus-daemon and XSELinux, which use selinux_set_mapping(), to continue working with the dummy policy or other policies that lack their userspace class/permission definitions as long as the policy was built with -U allow. Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Diffstat (limited to 'libselinux/src/reject_unknown.c')
-rw-r--r--libselinux/src/reject_unknown.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/libselinux/src/reject_unknown.c b/libselinux/src/reject_unknown.c
new file mode 100644
index 00000000..5c1d3605
--- /dev/null
+++ b/libselinux/src/reject_unknown.c
@@ -0,0 +1,40 @@
+#include <unistd.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include "selinux_internal.h"
+#include "policy.h"
+#include <stdio.h>
+#include <limits.h>
+
+int security_reject_unknown(void)
+{
+ int fd, ret, reject_unknown = 0;
+ char path[PATH_MAX];
+ char buf[20];
+
+ if (!selinux_mnt) {
+ errno = ENOENT;
+ return -1;
+ }
+
+ snprintf(path, sizeof(path), "%s/reject_unknown", selinux_mnt);
+ fd = open(path, O_RDONLY | O_CLOEXEC);
+ if (fd < 0)
+ return -1;
+
+ memset(buf, 0, sizeof(buf));
+ ret = read(fd, buf, sizeof(buf) - 1);
+ close(fd);
+ if (ret < 0)
+ return -1;
+
+ if (sscanf(buf, "%d", &reject_unknown) != 1)
+ return -1;
+
+ return reject_unknown;
+}
+
+hidden_def(security_reject_unknown);