diff options
-rw-r--r-- | connection.c | 45 | ||||
-rw-r--r-- | connection.h | 6 | ||||
-rw-r--r-- | handle.c | 9 | ||||
-rw-r--r-- | kdbus.txt | 72 | ||||
-rw-r--r-- | match.c | 16 | ||||
-rw-r--r-- | message.c | 4 | ||||
-rw-r--r-- | names.c | 10 |
7 files changed, 80 insertions, 82 deletions
diff --git a/connection.c b/connection.c index 44f5f80fd55..b27877114cb 100644 --- a/connection.c +++ b/connection.c @@ -516,7 +516,7 @@ static int kdbus_conn_queue_alloc(struct kdbus_conn *conn, } if (conn->msg_count > KDBUS_CONN_MAX_MSGS && - !kdbus_bus_uid_is_privileged(conn->ep->bus)) { + !kdbus_bus_uid_is_privileged(conn->bus)) { ret = -ENOBUFS; goto exit_unlock; } @@ -1042,7 +1042,6 @@ int kdbus_cmd_msg_cancel(struct kdbus_conn *conn, u64 cookie) { struct kdbus_conn_reply *reply, *reply_tmp; - struct kdbus_bus *bus = conn->ep->bus; struct kdbus_conn *c; bool found = false; int i; @@ -1050,8 +1049,8 @@ int kdbus_cmd_msg_cancel(struct kdbus_conn *conn, if (atomic_read(&conn->reply_count) == 0) return -ENOENT; - mutex_lock(&bus->lock); - hash_for_each(bus->conn_hash, i, c, hentry) { + mutex_lock(&conn->bus->lock); + hash_for_each(conn->bus->conn_hash, i, c, hentry) { mutex_lock(&c->lock); list_for_each_entry_safe(reply, reply_tmp, &c->reply_list, entry) { @@ -1064,7 +1063,7 @@ int kdbus_cmd_msg_cancel(struct kdbus_conn *conn, } mutex_unlock(&c->lock); } - mutex_unlock(&bus->lock); + mutex_unlock(&conn->bus->lock); return found ? 0 : -ENOENT; } @@ -1379,7 +1378,6 @@ int kdbus_conn_disconnect(struct kdbus_conn *conn, bool ensure_msg_list_empty) { struct kdbus_conn_reply *reply, *reply_tmp; struct kdbus_conn_queue *queue, *tmp; - struct kdbus_bus *bus; LIST_HEAD(notify_list); mutex_lock(&conn->lock); @@ -1396,13 +1394,11 @@ int kdbus_conn_disconnect(struct kdbus_conn *conn, bool ensure_msg_list_empty) conn->disconnected = true; mutex_unlock(&conn->lock); - bus = conn->ep->bus; - /* remove from bus */ - mutex_lock(&bus->lock); + mutex_lock(&conn->bus->lock); hash_del(&conn->hentry); list_del(&conn->monitor_entry); - mutex_unlock(&bus->lock); + mutex_unlock(&conn->bus->lock); /* clean up any messages still left on this endpoint */ mutex_lock(&conn->lock); @@ -1427,8 +1423,8 @@ int kdbus_conn_disconnect(struct kdbus_conn *conn, bool ensure_msg_list_empty) int i; struct kdbus_conn_reply *reply, *reply_tmp; - mutex_lock(&bus->lock); - hash_for_each(bus->conn_hash, i, c, hentry) { + mutex_lock(&conn->bus->lock); + hash_for_each(conn->bus->conn_hash, i, c, hentry) { mutex_lock(&c->lock); list_for_each_entry_safe(reply, reply_tmp, &c->reply_list, entry) { @@ -1457,7 +1453,7 @@ int kdbus_conn_disconnect(struct kdbus_conn *conn, bool ensure_msg_list_empty) } mutex_unlock(&c->lock); } - mutex_unlock(&bus->lock); + mutex_unlock(&conn->bus->lock); } kdbus_notify_id_change(KDBUS_ITEM_ID_REMOVE, conn->id, conn->flags, @@ -1466,7 +1462,7 @@ int kdbus_conn_disconnect(struct kdbus_conn *conn, bool ensure_msg_list_empty) del_timer_sync(&conn->timer); cancel_work_sync(&conn->work); - kdbus_name_remove_by_conn(bus->name_registry, conn); + kdbus_name_remove_by_conn(conn->bus->name_registry, conn); return 0; } @@ -1504,6 +1500,7 @@ static void __kdbus_conn_free(struct kref *kref) kdbus_match_db_free(conn->match_db); kdbus_pool_free(conn->pool); kdbus_ep_unref(conn->ep); + kdbus_bus_unref(conn->bus); kfree(conn->name); kfree(conn); } @@ -1557,7 +1554,6 @@ int kdbus_conn_move_messages(struct kdbus_conn *conn_dst, { struct kdbus_conn_reply *reply, *reply_tmp; struct kdbus_conn_queue *q, *q_tmp; - struct kdbus_bus *bus; struct kdbus_conn *c; LIST_HEAD(msg_list); int i, ret = 0; @@ -1600,9 +1596,8 @@ int kdbus_conn_move_messages(struct kdbus_conn *conn_dst, * anyone is waiting for a reply from conn_src. In such cases, * move it to the conn_dst. */ - bus = conn_dst->ep->bus; - mutex_lock(&bus->lock); - hash_for_each(bus->conn_hash, i, c, hentry) { + mutex_lock(&conn_dst->bus->lock); + hash_for_each(conn_dst->bus->conn_hash, i, c, hentry) { /* conn_dst can't have a pending reply to itself */ if (c == conn_dst) continue; @@ -1617,7 +1612,7 @@ int kdbus_conn_move_messages(struct kdbus_conn *conn_dst, } mutex_unlock(&c->lock); } - mutex_unlock(&bus->lock); + mutex_unlock(&conn_dst->bus->lock); wake_up_interruptible(&conn_dst->ep->wait); @@ -1659,11 +1654,9 @@ int kdbus_cmd_conn_info(struct kdbus_conn *conn, name = cmd_info->name; hash = kdbus_str_hash(name); } else { - struct kdbus_bus *bus = conn->ep->bus; - - mutex_lock(&bus->lock); - owner_conn = kdbus_bus_find_conn_by_id(bus, cmd_info->id); - mutex_unlock(&bus->lock); + mutex_lock(&conn->bus->lock); + owner_conn = kdbus_bus_find_conn_by_id(conn->bus, cmd_info->id); + mutex_unlock(&conn->bus->lock); } /* @@ -1679,7 +1672,7 @@ int kdbus_cmd_conn_info(struct kdbus_conn *conn, goto exit; } - e = kdbus_name_lookup(conn->ep->bus->name_registry, name); + e = kdbus_name_lookup(conn->bus->name_registry, name); if (!e) { ret = -ENOENT; goto exit; @@ -1926,6 +1919,7 @@ int kdbus_conn_new(struct kdbus_ep *ep, if (ret < 0) goto exit_free_pool; + conn->bus = kdbus_bus_ref(ep->bus); conn->ep = kdbus_ep_ref(ep); /* get new id for this connection */ @@ -2023,6 +2017,7 @@ exit_release_names: kdbus_name_remove_by_conn(bus->name_registry, conn); exit_unref_ep: kdbus_ep_unref(conn->ep); + kdbus_bus_unref(conn->bus); kdbus_match_db_free(conn->match_db); exit_free_pool: kdbus_pool_free(conn->pool); diff --git a/connection.h b/connection.h index 61e3b9a45fa..a27d7d1a5e5 100644 --- a/connection.h +++ b/connection.h @@ -22,9 +22,10 @@ * struct kdbus_conn - connection to a bus * @kref: Reference count * @disconnected: Invalidated data + * @id: Connection ID * @name: Human-readable connection name, used for debugging + * @bus: The bus this connection belongs to * @ep: The endpoint this connection belongs to - * @id: Connection ID * @flags: KDBUS_HELLO_* flags * @attach_flags: KDBUS_ATTACH_* flags * @lock: Connection data lock @@ -54,9 +55,10 @@ struct kdbus_conn { struct kref kref; bool disconnected; + u64 id; const char *name; + struct kdbus_bus *bus; struct kdbus_ep *ep; - u64 id; u64 flags; u64 attach_flags; struct mutex lock; @@ -518,7 +518,6 @@ static long kdbus_handle_ioctl_ep_connected(struct file *file, unsigned int cmd, { struct kdbus_handle *handle = file->private_data; struct kdbus_conn *conn = handle->conn; - struct kdbus_bus *bus = conn->ep->bus; void *p = NULL; long ret = 0; u64 size; @@ -538,7 +537,7 @@ static long kdbus_handle_ioctl_ep_connected(struct file *file, unsigned int cmd, break; /* mangling policy is a privileged operation */ - if (!kdbus_bus_uid_is_privileged(bus)) { + if (!kdbus_bus_uid_is_privileged(conn->bus)) { ret = -EFAULT; break; } @@ -562,7 +561,7 @@ static long kdbus_handle_ioctl_ep_connected(struct file *file, unsigned int cmd, if (ret < 0) break; - ret = kdbus_cmd_name_acquire(bus->name_registry, conn, p); + ret = kdbus_cmd_name_acquire(conn->bus->name_registry, conn, p); if (ret < 0) break; @@ -582,7 +581,7 @@ static long kdbus_handle_ioctl_ep_connected(struct file *file, unsigned int cmd, if (ret < 0) break; - ret = kdbus_cmd_name_release(bus->name_registry, conn, p); + ret = kdbus_cmd_name_release(conn->bus->name_registry, conn, p); break; case KDBUS_CMD_NAME_LIST: { @@ -597,7 +596,7 @@ static long kdbus_handle_ioctl_ep_connected(struct file *file, unsigned int cmd, return PTR_ERR(p); cmd = p; - ret = kdbus_cmd_name_list(bus->name_registry, conn, cmd); + ret = kdbus_cmd_name_list(conn->bus->name_registry, conn, cmd); if (ret < 0) break; diff --git a/kdbus.txt b/kdbus.txt index 50950d44a42..db2d48c0340 100644 --- a/kdbus.txt +++ b/kdbus.txt @@ -110,15 +110,15 @@ Data Structures | /dev/kdbus/control | | +---------------------------------------------------------------------+ | | | Bus (System Bus) | | - | | ./0-system/control | | + | | /dev/kdbus/0-system/ | | | | +-------------------------------+ +-------------------------------+ | | | | | Endpoint | | Endpoint | | | - | | | ./bus | | ./ep.sandbox | | | - | | | +------------+ +------------+ | | +------------+ +------------+ | | | - | | | | Connection | | Connection | | | | Connection | | Connection | | | | - | | | | :1.22 | | :1.25 | | | | :1.55 | | :1:81 | | | | - | | | +------------+ +------------+ | | +------------+ +------------+ | | | + | | | /dev/kdbus/0-system/bus | | /dev/kdbus/0-system/ep.app | | | | | +-------------------------------+ +-------------------------------+ | | + | | +--------------+ +--------------+ +--------------+ +--------------+ | | + | | | Connection | | Connection | | Connection | | Connection | | | + | | | :1.22 | | :1.25 | | :1.55 | | :1:81 | | | + | | +--------------+ +--------------+ +--------------+ +--------------+ | | | +---------------------------------------------------------------------+ | | | | +---------------------------------------------------------------------+ | @@ -127,39 +127,41 @@ Data Structures | | +-------------------------------+ +-------------------------------+ | | | | | Endpoint | | Endpoint | | | | | | /dev/kdbus/2702-user/bus | | /dev/kdbus/2702-user/ep.app | | | - | | | +------------+ +------------+ | | +------------+ +------------+ | | | - | | | | Connection | | Connection | | | | Connection | | Connection | | | | - | | | | :1.22 | | :1.25 | | | | :1.55 | | :1:81 | | | | - | | | +------------+ +------------+ | | +------------+ +------------+ | | | | | +-------------------------------+ +-------------------------------+ | | - | +---------------------------------------------------------------------+ | - +-------------------------------------------------------------------------+ - | Domain (Container; inside it, fedoracontainer/ becomes /dev/kdbus/) | - | /dev/kdbus/domain/fedoracontainer/control | - | +---------------------------------------------------------------------+ | - | | Bus | | - | | ./0-system/ | | - | | +---------------------------------+ | | - | | | Endpoint | | | - | | | ./bus | | | - | | | +-------------+ +-------------+ | | | - | | | | Connection | | Connection | | | | - | | | | :1.22 | | :1.25 | | | | - | | | +-------------+ +-------------+ | | | - | | +---------------------------------+ | | + | | +--------------+ +--------------+ +--------------+ +--------------+ | | + | | | Connection | | Connection | | Connection | | Connection | | | + | | | :1.22 | | :1.25 | | :1.55 | | :1:81 | | | + | | +--------------+ +--------------+ +-------------------------------+ | | | +---------------------------------------------------------------------+ | | | | +---------------------------------------------------------------------+ | - | | Bus | | - | | /dev/kdbus/2702-user/ | | - | | +---------------------------------+ | | - | | | Endpoint | | | - | | | /dev/kdbus/2702-user/bus | | | - | | | +-------------+ +-------------+ | | | - | | | | Connection | | Connection | | | | - | | | | :1.22 | | :1.25 | | | | - | | | +-------------+ +-------------+ | | | - | | +---------------------------------+ | | + | | Domain (Container; inside it, fedoracontainer/ becomes /dev/kdbus/) | | + | | /dev/kdbus/domain/fedoracontainer/control | | + | | +-----------------------------------------------------------------+ | | + | | | Bus (System Bus of "fedoracontainer") | | | + | | | /dev/kdbus/domain/fedoracontainer/0-system/ | | | + | | | +-----------------------------+ | | | + | | | | Endpoint | | | | + | | | | /dev/.../0-system/bus | | | | + | | | +-----------------------------+ | | | + | | | +-------------+ +-------------+ | | | + | | | | Connection | | Connection | | | | + | | | | :1.22 | | :1.25 | | | | + | | | +-------------+ +-------------+ | | | + | | +-----------------------------------------------------------------+ | | + | | | | + | | +-----------------------------------------------------------------+ | | + | | | Bus (User Bus for UID 270 of "fedoracontainer") | | | + | | | /dev/kdbus/domain/fedoracontainer/2702-user/ | | | + | | | +-----------------------------+ | | | + | | | | Endpoint | | | | + | | | | /dev/.../2702-user/bus | | | | + | | | +-----------------------------+ | | | + | | | +-------------+ +-------------+ | | | + | | | | Connection | | Connection | | | | + | | | | :1.22 | | :1.25 | | | | + | | | +-------------+ +-------------+ | | | + | | +-----------------------------------------------------------------+ | | | +---------------------------------------------------------------------+ | +-------------------------------------------------------------------------+ @@ -164,7 +164,7 @@ static bool kdbus_match_bloom(const struct kdbus_bloom_filter *filter, const struct kdbus_bloom_mask *mask, const struct kdbus_conn *conn) { - size_t n = conn->ep->bus->bloom.size / sizeof(u64); + size_t n = conn->bus->bloom.size / sizeof(u64); const u64 *m; size_t i; @@ -351,11 +351,11 @@ int kdbus_match_db_add(struct kdbus_conn *conn, if (cmd->owner_id == 0) cmd->owner_id = conn->id; else if (cmd->owner_id != conn->id && - !kdbus_bus_uid_is_privileged(conn->ep->bus)) + !kdbus_bus_uid_is_privileged(conn->bus)) return -EPERM; if (cmd->owner_id != 0 && cmd->owner_id != conn->id) { - struct kdbus_bus *bus = conn->ep->bus; + struct kdbus_bus *bus = conn->bus; mutex_lock(&bus->lock); target_conn = kdbus_bus_find_conn_by_id(bus, @@ -401,8 +401,8 @@ int kdbus_match_db_add(struct kdbus_conn *conn, switch (item->type) { case KDBUS_ITEM_BLOOM_MASK: - if (size < conn->ep->bus->bloom.size || - size % conn->ep->bus->bloom.size > 0) { + if (size < conn->bus->bloom.size || + size % conn->bus->bloom.size > 0) { ret = -EDOM; break; } @@ -416,7 +416,7 @@ int kdbus_match_db_add(struct kdbus_conn *conn, /* we get an array of n generations of bloom masks */ rule->bloom_mask.generations = - size / conn->ep->bus->bloom.size; + size / conn->bus->bloom.size; break; @@ -522,11 +522,11 @@ int kdbus_match_db_remove(struct kdbus_conn *conn, if (cmd->owner_id == 0) cmd->owner_id = conn->id; else if (cmd->owner_id != conn->id && - !kdbus_bus_uid_is_privileged(conn->ep->bus)) + !kdbus_bus_uid_is_privileged(conn->bus)) return -EPERM; if (cmd->owner_id != 0 && cmd->owner_id != conn->id) { - struct kdbus_bus *bus = conn->ep->bus; + struct kdbus_bus *bus = conn->bus; mutex_lock(&bus->lock); target_conn = kdbus_bus_find_conn_by_id(bus, cmd->owner_id); diff --git a/message.c b/message.c index 23a52ab948b..ef247d0cb78 100644 --- a/message.c +++ b/message.c @@ -110,7 +110,7 @@ static int kdbus_msg_scan_items(struct kdbus_conn *conn, vecs_size += item->vec.size; if (vecs_size > KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE && - !kdbus_bus_uid_is_privileged(conn->ep->bus)) + !kdbus_bus_uid_is_privileged(conn->bus)) return -EMSGSIZE; /* \0-bytes records store only the alignment bytes */ @@ -185,7 +185,7 @@ static int kdbus_msg_scan_items(struct kdbus_conn *conn, return -EFAULT; /* do not allow mismatching bloom filter sizes */ - if (bloom_size != conn->ep->bus->bloom.size) + if (bloom_size != conn->bus->bloom.size) return -EDOM; kmsg->bloom_filter = &item->bloom_filter; @@ -539,7 +539,7 @@ int kdbus_cmd_name_acquire(struct kdbus_name_registry *reg, /* privileged users can act on behalf of someone else */ if (cmd->owner_id != 0) { struct kdbus_conn *new_conn; - struct kdbus_bus *bus = conn->ep->bus; + struct kdbus_bus *bus = conn->bus; if (!kdbus_bus_uid_is_privileged(bus)) return -EPERM; @@ -608,7 +608,7 @@ int kdbus_cmd_name_release(struct kdbus_name_registry *reg, /* privileged users can act on behalf of someone else */ if (cmd->owner_id > 0) { - struct kdbus_bus *bus = conn->ep->bus; + struct kdbus_bus *bus = conn->bus; if (!kdbus_bus_uid_is_privileged(bus)) { ret = -EPERM; @@ -690,7 +690,7 @@ static int kdbus_name_list_all(struct kdbus_conn *conn, u64 flags, size_t p = *pos; int ret, i; - hash_for_each(conn->ep->bus->conn_hash, i, c, hentry) { + hash_for_each(conn->bus->conn_hash, i, c, hentry) { bool added = false; /* skip activators */ @@ -772,7 +772,7 @@ int kdbus_cmd_name_list(struct kdbus_name_registry *reg, int ret; mutex_lock(®->entries_lock); - mutex_lock(&conn->ep->bus->lock); + mutex_lock(&conn->bus->lock); /* size of header */ size = sizeof(struct kdbus_name_list); @@ -807,7 +807,7 @@ exit_pool_free: if (ret < 0) kdbus_pool_free_range(conn->pool, off); exit_unlock: - mutex_unlock(&conn->ep->bus->lock); + mutex_unlock(&conn->bus->lock); mutex_unlock(®->entries_lock); return ret; |