diff options
| author | Nick Kralevich <nnk@google.com> | 2015-10-10 20:07:24 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-10-10 20:07:24 +0000 |
| commit | 2fb90dc8b2b590e674c5e433e8bf3d3f08a887c8 (patch) | |
| tree | 49caabc5a311eb8731fc2c902eea663cb38a6cea /init | |
| parent | 4b2d6dd346a2c58cf034229afaaf91cc82901d5e (diff) | |
| parent | 468573930df71230ab43a356d2b7c2e960a2f1ea (diff) | |
| download | core-2fb90dc8b2b590e674c5e433e8bf3d3f08a887c8.tar.gz core-2fb90dc8b2b590e674c5e433e8bf3d3f08a887c8.tar.bz2 core-2fb90dc8b2b590e674c5e433e8bf3d3f08a887c8.zip | |
Merge changes from topic 'userspace-audit'
* changes:
debuggerd: audit pid, uid and gid on SE Linux denial
property_service: log pid,uid and gid of setprop client
Diffstat (limited to 'init')
| -rw-r--r-- | init/init.cpp | 11 | ||||
| -rw-r--r-- | init/property_service.cpp | 20 | ||||
| -rw-r--r-- | init/property_service.h | 6 |
3 files changed, 28 insertions, 9 deletions
diff --git a/init/init.cpp b/init/init.cpp index ee1351d95..a898b03e3 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -467,7 +467,16 @@ int selinux_reload_policy(void) } static int audit_callback(void *data, security_class_t /*cls*/, char *buf, size_t len) { - snprintf(buf, len, "property=%s", !data ? "NULL" : (char *)data); + + property_audit_data *d = reinterpret_cast<property_audit_data*>(data); + + if (!d || !d->name || !d->cr) { + ERROR("audit_callback invoked with null data arguments!"); + return 0; + } + + snprintf(buf, len, "property=%s pid=%d uid=%d gid=%d", d->name, + d->cr->pid, d->cr->uid, d->cr->gid); return 0; } diff --git a/init/property_service.cpp b/init/property_service.cpp index 719482075..ebf768eec 100644 --- a/init/property_service.cpp +++ b/init/property_service.cpp @@ -90,10 +90,11 @@ void property_init() { } } -static int check_mac_perms(const char *name, char *sctx) +static int check_mac_perms(const char *name, char *sctx, struct ucred *cr) { char *tctx = NULL; int result = 0; + property_audit_data audit_data; if (!sctx) goto err; @@ -104,7 +105,10 @@ static int check_mac_perms(const char *name, char *sctx) if (selabel_lookup(sehandle_prop, &tctx, name, 1) != 0) goto err; - if (selinux_check_access(sctx, tctx, "property_service", "set", (void*) name) == 0) + audit_data.name = name; + audit_data.cr = cr; + + if (selinux_check_access(sctx, tctx, "property_service", "set", reinterpret_cast<void*>(&audit_data)) == 0) result = 1; freecon(tctx); @@ -112,7 +116,7 @@ static int check_mac_perms(const char *name, char *sctx) return result; } -static int check_control_mac_perms(const char *name, char *sctx) +static int check_control_mac_perms(const char *name, char *sctx, struct ucred *cr) { /* * Create a name prefix out of ctl.<service name> @@ -126,19 +130,19 @@ static int check_control_mac_perms(const char *name, char *sctx) if (ret < 0 || (size_t) ret >= sizeof(ctl_name)) return 0; - return check_mac_perms(ctl_name, sctx); + return check_mac_perms(ctl_name, sctx, cr); } /* * Checks permissions for setting system properties. * Returns 1 if uid allowed, 0 otherwise. */ -static int check_perms(const char *name, char *sctx) +static int check_perms(const char *name, char *sctx, struct ucred *cr) { if(!strncmp(name, "ro.", 3)) name +=3; - return check_mac_perms(name, sctx); + return check_mac_perms(name, sctx, cr); } std::string property_get(const char* name) { @@ -321,14 +325,14 @@ static void handle_property_set_fd() // Keep the old close-socket-early behavior when handling // ctl.* properties. close(s); - if (check_control_mac_perms(msg.value, source_ctx)) { + if (check_control_mac_perms(msg.value, source_ctx, &cr)) { handle_control_message((char*) msg.name + 4, (char*) msg.value); } else { ERROR("sys_prop: Unable to %s service ctl [%s] uid:%d gid:%d pid:%d\n", msg.name + 4, msg.value, cr.uid, cr.gid, cr.pid); } } else { - if (check_perms(msg.name, source_ctx)) { + if (check_perms(msg.name, source_ctx, &cr)) { property_set((char*) msg.name, (char*) msg.value); } else { ERROR("sys_prop: permission denied uid:%d name:%s\n", diff --git a/init/property_service.h b/init/property_service.h index 51d740450..1a48fb188 100644 --- a/init/property_service.h +++ b/init/property_service.h @@ -18,9 +18,15 @@ #define _INIT_PROPERTY_H #include <stddef.h> +#include <sys/socket.h> #include <sys/system_properties.h> #include <string> +struct property_audit_data { + ucred *cr; + const char* name; +}; + extern void property_init(void); extern void property_load_boot_defaults(void); extern void load_persist_props(void); |
