|
|
5cb2893 |
diff --git a/libselinux/include/selinux/label.h b/libselinux/include/selinux/label.h
|
|
|
5cb2893 |
index 1a54307..f6eeb21 100644
|
|
|
5cb2893 |
--- a/libselinux/include/selinux/label.h
|
|
|
5cb2893 |
+++ b/libselinux/include/selinux/label.h
|
|
|
5cb2893 |
@@ -46,8 +46,10 @@ struct selabel_handle;
|
|
|
5cb2893 |
#define SELABEL_OPT_PATH 3
|
|
|
5cb2893 |
/* select a subset of the search space as an optimization (file backend) */
|
|
|
5cb2893 |
#define SELABEL_OPT_SUBSET 4
|
|
|
5cb2893 |
+/* like subset, but an array of subsets */
|
|
|
5cb2893 |
+#define SELABEL_OPT_PREFIXES 5
|
|
|
5cb2893 |
/* total number of options */
|
|
|
5cb2893 |
-#define SELABEL_NOPT 5
|
|
|
5cb2893 |
+#define SELABEL_NOPT 6
|
|
|
5cb2893 |
|
|
|
5cb2893 |
/*
|
|
|
5cb2893 |
* Label operations
|
|
|
a8fa875 |
diff --git a/libselinux/include/selinux/selinux.h b/libselinux/include/selinux/selinux.h
|
|
|
5cb2893 |
index 2985f6f..826ed71 100644
|
|
|
a8fa875 |
--- a/libselinux/include/selinux/selinux.h
|
|
|
a8fa875 |
+++ b/libselinux/include/selinux/selinux.h
|
|
|
5cb2893 |
@@ -139,7 +139,10 @@ struct av_decision {
|
|
|
5cb2893 |
/* Structure for passing options, used by AVC and label subsystems */
|
|
|
5cb2893 |
struct selinux_opt {
|
|
|
5cb2893 |
int type;
|
|
|
5cb2893 |
- const char *value;
|
|
|
5cb2893 |
+ union {
|
|
|
5cb2893 |
+ const char *value;
|
|
|
5cb2893 |
+ const char **values;
|
|
|
5cb2893 |
+ };
|
|
|
5cb2893 |
};
|
|
|
5cb2893 |
|
|
|
5cb2893 |
/* Callback facilities */
|
|
|
5cb2893 |
@@ -410,6 +413,11 @@ extern int matchpathcon_init(const char *path);
|
|
|
5cb2893 |
regexes that have stems that are prefixes of 'prefix'. */
|
|
|
5cb2893 |
extern int matchpathcon_init_prefix(const char *path, const char *prefix);
|
|
|
a8fa875 |
|
|
|
5cb2893 |
+/* Same as matchpathcon_init, but only load entries with
|
|
|
5cb2893 |
+ * regexes that have stems that are prefixes of the 'prefixes'
|
|
|
5cb2893 |
+ * array of entries. The last entry must be NULL. */
|
|
|
5cb2893 |
+extern int matchpathcon_init_prefixes(const char *patch, const char **prefixes);
|
|
|
a8fa875 |
+
|
|
|
5cb2893 |
/* Free the memory allocated by matchpathcon_init. */
|
|
|
5cb2893 |
extern void matchpathcon_fini(void);
|
|
|
5cb2893 |
|
|
|
10e77a8 |
diff --git a/libselinux/man/man3/matchpathcon.3 b/libselinux/man/man3/matchpathcon.3
|
|
|
5cb2893 |
index cdbb252..b6814ed 100644
|
|
|
10e77a8 |
--- a/libselinux/man/man3/matchpathcon.3
|
|
|
10e77a8 |
+++ b/libselinux/man/man3/matchpathcon.3
|
|
|
5cb2893 |
@@ -8,7 +8,9 @@ matchpathcon, matchpathcon_index \- get the default SELinux security context for
|
|
|
10e77a8 |
|
|
|
10e77a8 |
.BI "int matchpathcon_init(const char *" path ");"
|
|
|
10e77a8 |
|
|
|
10e77a8 |
-.BI "int matchpathcon_init_prefix(const char *" path ", const char *" subset ");"
|
|
|
10e77a8 |
+.BI "int matchpathcon_init_prefix(const char *" path ", const char *" prefix ");"
|
|
|
5cb2893 |
+
|
|
|
5cb2893 |
+.BI "int matchpathcon_init_prefixes(const char *" path ", const char **" prefixes ");"
|
|
|
10e77a8 |
|
|
|
10e77a8 |
.BI "int matchpathcon_fini(void);"
|
|
|
10e77a8 |
.sp
|
|
|
5cb2893 |
@@ -50,6 +52,14 @@ by
|
|
|
10e77a8 |
.I prefix.
|
|
|
5cb2893 |
|
|
|
10e77a8 |
.sp
|
|
|
5cb2893 |
+.B matchpathcon_init_prefixes
|
|
|
5cb2893 |
+is the same as
|
|
|
5cb2893 |
+.B matchpathcon_init_prefix
|
|
|
5cb2893 |
+but takes an array of
|
|
|
5cb2893 |
+.I prefixes
|
|
|
5cb2893 |
+instead of a single prefix. The last entry in the array must be NULL.
|
|
|
5cb2893 |
+
|
|
|
5cb2893 |
+.sp
|
|
|
10e77a8 |
.B matchpathcon_fini
|
|
|
10e77a8 |
frees the memory allocated by a prior call to
|
|
|
5cb2893 |
.B matchpathcon_init.
|
|
|
10e77a8 |
diff --git a/libselinux/man/man3/selabel_open.3 b/libselinux/man/man3/selabel_open.3
|
|
|
5113c75 |
index 8674e37..89bb4d3 100644
|
|
|
10e77a8 |
--- a/libselinux/man/man3/selabel_open.3
|
|
|
10e77a8 |
+++ b/libselinux/man/man3/selabel_open.3
|
|
|
10e77a8 |
@@ -66,6 +66,13 @@ A non-null value for this option enables context validation. By default,
|
|
|
10e77a8 |
is used; a custom validation function can be provided via
|
|
|
10e77a8 |
.BR selinux_set_callback (3).
|
|
|
10e77a8 |
Note that an invalid context may not be treated as an error unless it is actually encountered during a lookup operation.
|
|
|
10e77a8 |
+.TP
|
|
|
10e77a8 |
+.B SELABEL_OPT_SUBSET
|
|
|
5113c75 |
+A ":" separates string of path prefixes that tell the system to only loads entries with regular expressions that could match this strings. For example "/dev:/var/run:/tmp". This option can cause the system to use less memory and work faster, but you should only use paths that begin with a prefix.
|
|
|
10e77a8 |
+.TP
|
|
|
10e77a8 |
+.B SELABEL_OPT_PATH
|
|
|
10e77a8 |
+A string representing an alternate path the the regular expressions.
|
|
|
10e77a8 |
+.sp
|
|
|
10e77a8 |
|
|
|
10e77a8 |
.SH "BACKENDS"
|
|
|
10e77a8 |
|
|
|
10e77a8 |
@@ -99,4 +106,3 @@ Eamon Walsh <ewalsh@tycho.nsa.gov>
|
|
|
10e77a8 |
.BR selabel_stats (3),
|
|
|
10e77a8 |
.BR selinux_set_callback (3),
|
|
|
10e77a8 |
.BR selinux (8)
|
|
|
10e77a8 |
-
|
|
|
ca9cea7 |
diff --git a/libselinux/src/callbacks.c b/libselinux/src/callbacks.c
|
|
|
ca9cea7 |
index b245364..7c47222 100644
|
|
|
ca9cea7 |
--- a/libselinux/src/callbacks.c
|
|
|
ca9cea7 |
+++ b/libselinux/src/callbacks.c
|
|
|
ca9cea7 |
@@ -16,6 +16,7 @@ default_selinux_log(int type __attribute__((unused)), const char *fmt, ...)
|
|
|
ee77868 |
{
|
|
|
d0a06b2 |
int rc;
|
|
|
d0a06b2 |
va_list ap;
|
|
|
d0a06b2 |
+ if (is_selinux_enabled() == 0) return 0;
|
|
|
d0a06b2 |
va_start(ap, fmt);
|
|
|
d0a06b2 |
rc = vfprintf(stderr, fmt, ap);
|
|
|
d0a06b2 |
va_end(ap);
|
|
|
10e77a8 |
diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c
|
|
|
5cb2893 |
index ac11b37..42889cf 100644
|
|
|
10e77a8 |
--- a/libselinux/src/label_file.c
|
|
|
10e77a8 |
+++ b/libselinux/src/label_file.c
|
|
|
10e77a8 |
@@ -27,6 +27,7 @@
|
|
|
10e77a8 |
* Internals, mostly moved over from matchpathcon.c
|
|
|
10e77a8 |
*/
|
|
|
10e77a8 |
|
|
|
10e77a8 |
+#define MAX_PREFIX 100
|
|
|
10e77a8 |
/* A file security context specification. */
|
|
|
10e77a8 |
typedef struct spec {
|
|
|
10e77a8 |
struct selabel_lookup_rec lr; /* holds contexts for lookup result */
|
|
|
5cb2893 |
@@ -276,7 +277,7 @@ static int compile_regex(struct saved_data *data, spec_t *spec, char **errbuf)
|
|
|
10e77a8 |
|
|
|
10e77a8 |
|
|
|
10e77a8 |
static int process_line(struct selabel_handle *rec,
|
|
|
10e77a8 |
- const char *path, const char *prefix,
|
|
|
10e77a8 |
+ const char *path, const char **prefix_array,
|
|
|
10e77a8 |
char *line_buf, int pass, unsigned lineno)
|
|
|
10e77a8 |
{
|
|
|
10e77a8 |
int items, len;
|
|
|
5cb2893 |
@@ -310,12 +311,24 @@ static int process_line(struct selabel_handle *rec,
|
|
|
10e77a8 |
}
|
|
|
10e77a8 |
|
|
|
10e77a8 |
len = get_stem_from_spec(regex);
|
|
|
10e77a8 |
- if (len && prefix && strncmp(prefix, regex, len)) {
|
|
|
10e77a8 |
- /* Stem of regex does not match requested prefix, discard. */
|
|
|
10e77a8 |
- free(regex);
|
|
|
10e77a8 |
- free(type);
|
|
|
10e77a8 |
- free(context);
|
|
|
10e77a8 |
- return 0;
|
|
|
10e77a8 |
+ if (len && prefix_array[0]) {
|
|
|
10e77a8 |
+ int i = 0;
|
|
|
10e77a8 |
+ int found = 0;
|
|
|
10e77a8 |
+ while (i < MAX_PREFIX && prefix_array[i]) {
|
|
|
10e77a8 |
+ if (strncmp(prefix_array[i], regex, len) == 0) {
|
|
|
10e77a8 |
+ found = 1;
|
|
|
10e77a8 |
+ break;
|
|
|
10e77a8 |
+ }
|
|
|
10e77a8 |
+ i++;
|
|
|
10e77a8 |
+ }
|
|
|
10e77a8 |
+
|
|
|
10e77a8 |
+ if (! found) {
|
|
|
10e77a8 |
+ /* Stem of regex does not match requested prefix, discard. */
|
|
|
10e77a8 |
+ free(regex);
|
|
|
10e77a8 |
+ free(type);
|
|
|
10e77a8 |
+ free(context);
|
|
|
10e77a8 |
+ return 0;
|
|
|
10e77a8 |
+ }
|
|
|
10e77a8 |
}
|
|
|
10e77a8 |
|
|
|
10e77a8 |
if (pass == 1) {
|
|
|
5cb2893 |
@@ -397,7 +410,8 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
|
|
|
10e77a8 |
{
|
|
|
10e77a8 |
struct saved_data *data = (struct saved_data *)rec->data;
|
|
|
10e77a8 |
const char *path = NULL;
|
|
|
10e77a8 |
- const char *prefix = NULL;
|
|
|
5cb2893 |
+ const char *static_prefix_array[2] = {NULL, };
|
|
|
5cb2893 |
+ const char **prefix_array = static_prefix_array;
|
|
|
10e77a8 |
FILE *fp;
|
|
|
10e77a8 |
FILE *localfp = NULL;
|
|
|
10e77a8 |
FILE *homedirfp = NULL;
|
|
|
5cb2893 |
@@ -418,7 +432,10 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
|
|
|
10e77a8 |
path = opts[n].value;
|
|
|
10e77a8 |
break;
|
|
|
10e77a8 |
case SELABEL_OPT_SUBSET:
|
|
|
10e77a8 |
- prefix = opts[n].value;
|
|
|
5cb2893 |
+ static_prefix_array[0] = opts[n].value;
|
|
|
5cb2893 |
+ break;
|
|
|
5cb2893 |
+ case SELABEL_OPT_PREFIXES:
|
|
|
5cb2893 |
+ prefix_array = opts[n].values;
|
|
|
10e77a8 |
break;
|
|
|
10e77a8 |
case SELABEL_OPT_BASEONLY:
|
|
|
10e77a8 |
baseonly = !!opts[n].value;
|
|
|
5cb2893 |
@@ -480,7 +497,7 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
|
|
|
5cb2893 |
while (getline(&line_buf, &line_len, fp) > 0) {
|
|
|
5cb2893 |
if (data->nspec >= maxnspec)
|
|
|
5cb2893 |
break;
|
|
|
5cb2893 |
- status = process_line(rec, path, prefix, line_buf, pass, ++lineno);
|
|
|
5cb2893 |
+ status = process_line(rec, path, prefix_array, line_buf, pass, ++lineno);
|
|
|
5cb2893 |
if (status)
|
|
|
10e77a8 |
goto finish;
|
|
|
10e77a8 |
}
|
|
|
5cb2893 |
@@ -496,7 +513,7 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
|
|
|
5cb2893 |
while (getline(&line_buf, &line_len, homedirfp) > 0) {
|
|
|
5cb2893 |
if (data->nspec >= maxnspec)
|
|
|
5cb2893 |
break;
|
|
|
5cb2893 |
- status = process_line(rec, homedir_path, prefix, line_buf, pass, ++lineno);
|
|
|
5cb2893 |
+ status = process_line(rec, homedir_path, prefix_array, line_buf, pass, ++lineno);
|
|
|
5cb2893 |
if (status)
|
|
|
10e77a8 |
goto finish;
|
|
|
10e77a8 |
}
|
|
|
5cb2893 |
@@ -506,7 +523,7 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
|
|
|
5cb2893 |
while (getline(&line_buf, &line_len, localfp) > 0) {
|
|
|
5cb2893 |
if (data->nspec >= maxnspec)
|
|
|
5cb2893 |
break;
|
|
|
5cb2893 |
- status = process_line(rec, local_path, prefix, line_buf, pass, ++lineno);
|
|
|
5cb2893 |
+ status = process_line(rec, local_path, prefix_array, line_buf, pass, ++lineno);
|
|
|
5cb2893 |
if (status)
|
|
|
10e77a8 |
goto finish;
|
|
|
10e77a8 |
}
|
|
|
ca9cea7 |
diff --git a/libselinux/src/matchpathcon.c b/libselinux/src/matchpathcon.c
|
|
|
5cb2893 |
index c396add..489ef3a 100644
|
|
|
ca9cea7 |
--- a/libselinux/src/matchpathcon.c
|
|
|
ca9cea7 |
+++ b/libselinux/src/matchpathcon.c
|
|
|
495b754 |
@@ -2,6 +2,7 @@
|
|
|
974a6e4 |
#include <string.h>
|
|
|
974a6e4 |
#include <errno.h>
|
|
|
974a6e4 |
#include <stdio.h>
|
|
|
974a6e4 |
+#include <syslog.h>
|
|
|
974a6e4 |
#include "selinux_internal.h"
|
|
|
974a6e4 |
#include "label_internal.h"
|
|
|
974a6e4 |
#include "callbacks.h"
|
|
|
495b754 |
@@ -62,7 +63,7 @@ static void
|
|
|
974a6e4 |
{
|
|
|
974a6e4 |
va_list ap;
|
|
|
974a6e4 |
va_start(ap, fmt);
|
|
|
974a6e4 |
- vfprintf(stderr, fmt, ap);
|
|
|
974a6e4 |
+ vsyslog(LOG_ERR, fmt, ap);
|
|
|
974a6e4 |
va_end(ap);
|
|
|
974a6e4 |
}
|
|
|
b5b41bc |
|
|
|
5cb2893 |
@@ -304,7 +305,7 @@ static void matchpathcon_init_once(void)
|
|
|
5cb2893 |
destructor_key_initialized = 1;
|
|
|
5cb2893 |
}
|
|
|
8075466 |
|
|
|
5cb2893 |
-int matchpathcon_init_prefix(const char *path, const char *subset)
|
|
|
5cb2893 |
+int matchpathcon_init_prefixes(const char *path, const char **prefixes)
|
|
|
5cb2893 |
{
|
|
|
5cb2893 |
if (!mycanoncon)
|
|
|
5cb2893 |
mycanoncon = default_canoncon;
|
|
|
5cb2893 |
@@ -312,15 +313,22 @@ int matchpathcon_init_prefix(const char *path, const char *subset)
|
|
|
5cb2893 |
__selinux_once(once, matchpathcon_init_once);
|
|
|
5cb2893 |
__selinux_setspecific(destructor_key, (void *)1);
|
|
|
5cb2893 |
|
|
|
5cb2893 |
- options[SELABEL_OPT_SUBSET].type = SELABEL_OPT_SUBSET;
|
|
|
5cb2893 |
- options[SELABEL_OPT_SUBSET].value = subset;
|
|
|
5cb2893 |
+ options[SELABEL_OPT_PREFIXES].type = SELABEL_OPT_PREFIXES;
|
|
|
5cb2893 |
+ options[SELABEL_OPT_PREFIXES].values = prefixes;
|
|
|
5cb2893 |
options[SELABEL_OPT_PATH].type = SELABEL_OPT_PATH;
|
|
|
5cb2893 |
options[SELABEL_OPT_PATH].value = path;
|
|
|
5cb2893 |
|
|
|
5cb2893 |
hnd = selabel_open(SELABEL_CTX_FILE, options, SELABEL_NOPT);
|
|
|
5cb2893 |
return hnd ? 0 : -1;
|
|
|
5cb2893 |
}
|
|
|
5cb2893 |
+hidden_def(matchpathcon_init_prefixes)
|
|
|
5cb2893 |
|
|
|
5cb2893 |
+int matchpathcon_init_prefix(const char *path, const char *prefix)
|
|
|
5cb2893 |
+{
|
|
|
5cb2893 |
+ const char *prefixes[2] = { prefix, NULL };
|
|
|
5cb2893 |
+
|
|
|
5cb2893 |
+ return matchpathcon_init_prefixes(path, prefixes);
|
|
|
5cb2893 |
+}
|
|
|
5cb2893 |
hidden_def(matchpathcon_init_prefix)
|
|
|
8075466 |
|
|
|
5cb2893 |
int matchpathcon_init(const char *path)
|
|
|
5cb2893 |
diff --git a/libselinux/src/selinux_internal.h b/libselinux/src/selinux_internal.h
|
|
|
5cb2893 |
index 710396a..9a3fc14 100644
|
|
|
5cb2893 |
--- a/libselinux/src/selinux_internal.h
|
|
|
5cb2893 |
+++ b/libselinux/src/selinux_internal.h
|
|
|
5cb2893 |
@@ -80,6 +80,7 @@ hidden_proto(selinux_mkload_policy)
|
|
|
5cb2893 |
hidden_proto(selinux_path)
|
|
|
5cb2893 |
hidden_proto(selinux_check_passwd_access)
|
|
|
5cb2893 |
hidden_proto(selinux_check_securetty_context)
|
|
|
5cb2893 |
+ hidden_proto(matchpathcon_init_prefixes)
|
|
|
5cb2893 |
hidden_proto(matchpathcon_init_prefix)
|
|
|
5cb2893 |
hidden_proto(selinux_users_path)
|
|
|
5cb2893 |
hidden_proto(selinux_usersconf_path);
|