mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
protocol-native: improve permission checks
This commit is contained in:
parent
eb0a561f8c
commit
e107d75248
3 changed files with 20 additions and 18 deletions
|
|
@ -33,9 +33,7 @@ extern "C" {
|
||||||
|
|
||||||
struct pw_protocol_native_demarshal {
|
struct pw_protocol_native_demarshal {
|
||||||
int (*func) (void *object, void *data, size_t size);
|
int (*func) (void *object, void *data, size_t size);
|
||||||
|
uint32_t permissions;
|
||||||
#define PW_PROTOCOL_NATIVE_PERM_W (1<<0)
|
|
||||||
uint32_t flags;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \ref pw_protocol_native_ext methods */
|
/** \ref pw_protocol_native_ext methods */
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ process_messages(struct client_data *data)
|
||||||
struct pw_resource *resource;
|
struct pw_resource *resource;
|
||||||
const struct pw_protocol_native_demarshal *demarshal;
|
const struct pw_protocol_native_demarshal *demarshal;
|
||||||
const struct pw_protocol_marshal *marshal;
|
const struct pw_protocol_marshal *marshal;
|
||||||
uint32_t permissions;
|
uint32_t permissions, required;
|
||||||
|
|
||||||
if (!pw_protocol_native_connection_get_next(conn, &opcode, &id, &message, &size))
|
if (!pw_protocol_native_connection_get_next(conn, &opcode, &id, &message, &size))
|
||||||
break;
|
break;
|
||||||
|
|
@ -149,12 +149,8 @@ process_messages(struct client_data *data)
|
||||||
if (resource == NULL) {
|
if (resource == NULL) {
|
||||||
pw_log_error("protocol-native %p: unknown resource %u",
|
pw_log_error("protocol-native %p: unknown resource %u",
|
||||||
client->protocol, id);
|
client->protocol, id);
|
||||||
continue;
|
pw_core_resource_error(client->core_resource, id,
|
||||||
}
|
-EINVAL, "unknown resource %u", id);
|
||||||
permissions = pw_resource_get_permissions(resource);
|
|
||||||
if ((permissions & PW_PERM_X) == 0) {
|
|
||||||
pw_log_error("protocol-native %p: execute not allowed on resource %u",
|
|
||||||
client->protocol, id);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,10 +162,14 @@ process_messages(struct client_data *data)
|
||||||
if (!demarshal[opcode].func)
|
if (!demarshal[opcode].func)
|
||||||
goto invalid_message;
|
goto invalid_message;
|
||||||
|
|
||||||
if ((demarshal[opcode].flags & PW_PROTOCOL_NATIVE_PERM_W) &&
|
permissions = pw_resource_get_permissions(resource);
|
||||||
((permissions & PW_PERM_W) == 0)) {
|
required = demarshal[opcode].permissions | PW_PERM_X;
|
||||||
pw_log_error("protocol-native %p: method %u requires write access on %u",
|
|
||||||
client->protocol, opcode, id);
|
if ((required & permissions) != required) {
|
||||||
|
pw_log_error("protocol-native %p: method %u on %u requires %08x, have %08x",
|
||||||
|
client->protocol, opcode, id, required, permissions);
|
||||||
|
pw_core_resource_error(client->core_resource, id,
|
||||||
|
-EACCES, "no permission to call method %u ", opcode, id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -183,11 +183,15 @@ process_messages(struct client_data *data)
|
||||||
invalid_method:
|
invalid_method:
|
||||||
pw_log_error("protocol-native %p: invalid method %u on resource %u",
|
pw_log_error("protocol-native %p: invalid method %u on resource %u",
|
||||||
client->protocol, opcode, id);
|
client->protocol, opcode, id);
|
||||||
|
pw_core_resource_error(client->core_resource, id,
|
||||||
|
-EINVAL, "invalid method %u on resource %u", opcode, id);
|
||||||
pw_client_destroy(client);
|
pw_client_destroy(client);
|
||||||
goto done;
|
goto done;
|
||||||
invalid_message:
|
invalid_message:
|
||||||
pw_log_error("protocol-native %p: invalid message received %u %u",
|
pw_log_error("protocol-native %p: invalid message received %u %u",
|
||||||
client->protocol, id, opcode);
|
client->protocol, id, opcode);
|
||||||
|
pw_core_resource_error(client->core_resource, id,
|
||||||
|
-EINVAL, "invalid message %u %u", opcode, id);
|
||||||
spa_debug_pod(0, NULL, (struct spa_pod *)message);
|
spa_debug_pod(0, NULL, (struct spa_pod *)message);
|
||||||
pw_client_destroy(client);
|
pw_client_destroy(client);
|
||||||
goto done;
|
goto done;
|
||||||
|
|
|
||||||
|
|
@ -1440,8 +1440,8 @@ static const struct pw_node_proxy_methods pw_protocol_native_node_method_marshal
|
||||||
|
|
||||||
static const struct pw_protocol_native_demarshal pw_protocol_native_node_method_demarshal[] = {
|
static const struct pw_protocol_native_demarshal pw_protocol_native_node_method_demarshal[] = {
|
||||||
{ &node_demarshal_enum_params, 0, },
|
{ &node_demarshal_enum_params, 0, },
|
||||||
{ &node_demarshal_set_param, PW_PROTOCOL_NATIVE_PERM_W, },
|
{ &node_demarshal_set_param, PW_PERM_W, },
|
||||||
{ &node_demarshal_send_command, PW_PROTOCOL_NATIVE_PERM_W, },
|
{ &node_demarshal_send_command, PW_PERM_W, },
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct pw_node_proxy_events pw_protocol_native_node_event_marshal = {
|
static const struct pw_node_proxy_events pw_protocol_native_node_event_marshal = {
|
||||||
|
|
@ -1506,9 +1506,9 @@ static const struct pw_client_proxy_methods pw_protocol_native_client_method_mar
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct pw_protocol_native_demarshal pw_protocol_native_client_method_demarshal[] = {
|
static const struct pw_protocol_native_demarshal pw_protocol_native_client_method_demarshal[] = {
|
||||||
{ &client_demarshal_error, PW_PROTOCOL_NATIVE_PERM_W, },
|
{ &client_demarshal_error, PW_PERM_W, },
|
||||||
{ &client_demarshal_get_permissions, 0, },
|
{ &client_demarshal_get_permissions, 0, },
|
||||||
{ &client_demarshal_update_permissions, PW_PROTOCOL_NATIVE_PERM_W, },
|
{ &client_demarshal_update_permissions, PW_PERM_W, },
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct pw_client_proxy_events pw_protocol_native_client_event_marshal = {
|
static const struct pw_client_proxy_events pw_protocol_native_client_event_marshal = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue