diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-11-26 22:52:10 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-11-27 21:58:07 +0100 |
commit | 64e96a194d9fb8e9e69769bf88f067fadf9acce7 (patch) | |
tree | efdecb42fa88671e5bfce82dcfc25e91e6770de0 | |
parent | be660c371b231c253a97464ddd8f32ec8721da21 (diff) |
bus-proxy: check passed parameter signature of all driver method calls
-rw-r--r-- | src/bus-proxyd/bus-proxyd.c | 60 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-message.c | 6 | ||||
-rw-r--r-- | src/systemd/sd-bus.h | 1 |
3 files changed, 59 insertions, 8 deletions
diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c index 32c8242221..4df2fb10af 100644 --- a/src/bus-proxyd/bus-proxyd.c +++ b/src/bus-proxyd/bus-proxyd.c @@ -543,14 +543,12 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic if (!streq_ptr(sd_bus_message_get_destination(m), "org.freedesktop.DBus")) return 0; - if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect")) { - if (0 && !isempty(sd_bus_message_get_signature(m, true))) { - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + /* The "Hello()" call is is handled in process_hello() */ - r = sd_bus_error_setf(&error, SD_BUS_ERROR_INVALID_ARGS, "Expected no parameters"); + if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect")) { - return synthetic_reply_method_errno(m, r, &error); - } + if (!sd_bus_message_has_signature(m, "")) + return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters")); return synthetic_reply_method_return(m, "s", "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\" " @@ -640,6 +638,9 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "AddMatch")) { const char *match; + if (!sd_bus_message_has_signature(m, "s")) + return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters")); + r = sd_bus_message_read(m, "s", &match); if (r < 0) return synthetic_reply_method_errno(m, r, NULL); @@ -653,6 +654,9 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "RemoveMatch")) { const char *match; + if (!sd_bus_message_has_signature(m, "s")) + return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters")); + r = sd_bus_message_read(m, "s", &match); if (r < 0) return synthetic_reply_method_errno(m, r, NULL); @@ -669,6 +673,9 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + if (!sd_bus_message_has_signature(m, "s")) + return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters")); + r = get_creds_by_message(a, m, SD_BUS_CREDS_SELINUX_CONTEXT, &creds, &error); if (r < 0) return synthetic_reply_method_errno(m, r, &error); @@ -679,6 +686,9 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + if (!sd_bus_message_has_signature(m, "s")) + return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters")); + r = get_creds_by_message(a, m, SD_BUS_CREDS_PID, &creds, &error); if (r < 0) return synthetic_reply_method_errno(m, r, &error); @@ -689,6 +699,9 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + if (!sd_bus_message_has_signature(m, "s")) + return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters")); + r = get_creds_by_message(a, m, SD_BUS_CREDS_UID, &creds, &error); if (r < 0) return synthetic_reply_method_errno(m, r, &error); @@ -699,6 +712,9 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic sd_id128_t server_id; char buf[SD_ID128_STRING_MAX]; + if (!sd_bus_message_has_signature(m, "")) + return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters")); + r = sd_bus_get_owner_id(a, &server_id); if (r < 0) return synthetic_reply_method_errno(m, r, NULL); @@ -710,6 +726,9 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + if (!sd_bus_message_has_signature(m, "s")) + return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters")); + r = sd_bus_message_read(m, "s", &name); if (r < 0) return synthetic_reply_method_errno(m, r, NULL); @@ -723,11 +742,12 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic return synthetic_reply_method_return(m, "s", creds->unique_name); - /* "Hello" is handled in process_hello() */ - } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "ListActivatableNames")) { _cleanup_strv_free_ char **names = NULL; + if (!sd_bus_message_has_signature(m, "")) + return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters")); + r = sd_bus_list_names(a, NULL, &names); if (r < 0) return synthetic_reply_method_errno(m, r, NULL); @@ -740,6 +760,9 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "ListNames")) { _cleanup_strv_free_ char **names = NULL; + if (!sd_bus_message_has_signature(m, "")) + return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters")); + r = sd_bus_list_names(a, &names, NULL); if (r < 0) return synthetic_reply_method_errno(m, r, NULL); @@ -763,6 +786,9 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic char *arg0; int err = 0; + if (!sd_bus_message_has_signature(m, "s")) + return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters")); + r = sd_bus_message_read(m, "s", &arg0); if (r < 0) return synthetic_reply_method_errno(m, r, NULL); @@ -821,6 +847,9 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "NameHasOwner")) { const char *name; + if (!sd_bus_message_has_signature(m, "s")) + return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters")); + r = sd_bus_message_read(m, "s", &name); if (r < 0) return synthetic_reply_method_errno(m, r, NULL); @@ -837,6 +866,9 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "ReleaseName")) { const char *name; + if (!sd_bus_message_has_signature(m, "s")) + return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters")); + r = sd_bus_message_read(m, "s", &name); if (r < 0) return synthetic_reply_method_errno(m, r, NULL); @@ -858,6 +890,9 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "ReloadConfig")) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + if (!sd_bus_message_has_signature(m, "")) + return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters")); + r = sd_bus_error_setf(&error, SD_BUS_ERROR_NOT_SUPPORTED, "%s() is not supported", sd_bus_message_get_member(m)); return synthetic_reply_method_errno(m, r, &error); @@ -867,6 +902,9 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic uint32_t flags, param; bool in_queue; + if (!sd_bus_message_has_signature(m, "su")) + return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters")); + r = sd_bus_message_read(m, "su", &name, &flags); if (r < 0) return synthetic_reply_method_errno(m, r, NULL); @@ -910,6 +948,9 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic const char *name; uint32_t flags; + if (!sd_bus_message_has_signature(m, "su")) + return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters")); + r = sd_bus_message_read(m, "su", &name, &flags); if (r < 0) return synthetic_reply_method_errno(m, r, NULL); @@ -943,6 +984,9 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic _cleanup_bus_message_unref_ sd_bus_message *msg = NULL; _cleanup_strv_free_ char **args = NULL; + if (!sd_bus_message_has_signature(m, "a{ss}")) + return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters")); + r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{ss}"); if (r < 0) return synthetic_reply_method_errno(m, r, NULL); diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c index 6889754a96..9bc05c2034 100644 --- a/src/libsystemd/sd-bus/bus-message.c +++ b/src/libsystemd/sd-bus/bus-message.c @@ -5396,6 +5396,12 @@ _public_ int sd_bus_message_is_empty(sd_bus_message *m) { return isempty(m->root_container.signature); } +_public_ int sd_bus_message_has_signature(sd_bus_message *m, const char *signature) { + assert_return(m, -EINVAL); + + return streq(strempty(m->root_container.signature), strempty(signature)); +} + _public_ int sd_bus_message_copy(sd_bus_message *m, sd_bus_message *source, int all) { bool done_something = false; int r; diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h index 28c7ee4634..47fc8df1d0 100644 --- a/src/systemd/sd-bus.h +++ b/src/systemd/sd-bus.h @@ -231,6 +231,7 @@ int sd_bus_message_is_signal(sd_bus_message *m, const char *interface, const cha int sd_bus_message_is_method_call(sd_bus_message *m, const char *interface, const char *member); int sd_bus_message_is_method_error(sd_bus_message *m, const char *name); int sd_bus_message_is_empty(sd_bus_message *m); +int sd_bus_message_has_signature(sd_bus_message *m, const char *signature); int sd_bus_message_set_expect_reply(sd_bus_message *m, int b); int sd_bus_message_set_auto_start(sd_bus_message *m, int b); |