Messages in this thread Patch in this message | | | From | Paul Osmialowski <> | Subject | [RFC PATCH] kdbus: move all kdbus headers to include/linux/kdbus | Date | Wed, 25 Mar 2015 16:37:15 +0100 |
| |
These headers are required to implement LSM hooks for kdbus and possibly other things that might deal with kdbus.
Signed-off-by: Paul Osmialowski <p.osmialowsk@samsung.com> --- include/linux/kdbus/bus.h | 101 +++++++++++++++ include/linux/kdbus/connection.h | 257 +++++++++++++++++++++++++++++++++++++++ include/linux/kdbus/domain.h | 77 ++++++++++++ include/linux/kdbus/endpoint.h | 67 ++++++++++ include/linux/kdbus/fs.h | 28 +++++ include/linux/kdbus/handle.h | 85 +++++++++++++ include/linux/kdbus/item.h | 64 ++++++++++ include/linux/kdbus/limits.h | 64 ++++++++++ include/linux/kdbus/match.h | 35 ++++++ include/linux/kdbus/message.h | 133 ++++++++++++++++++++ include/linux/kdbus/metadata.h | 57 +++++++++ include/linux/kdbus/names.h | 74 +++++++++++ include/linux/kdbus/node.h | 84 +++++++++++++ include/linux/kdbus/notify.h | 30 +++++ include/linux/kdbus/policy.h | 51 ++++++++ include/linux/kdbus/pool.h | 46 +++++++ include/linux/kdbus/queue.h | 92 ++++++++++++++ include/linux/kdbus/reply.h | 68 +++++++++++ include/linux/kdbus/util.h | 74 +++++++++++ ipc/kdbus/Makefile | 2 + ipc/kdbus/bus.h | 101 --------------- ipc/kdbus/connection.h | 257 --------------------------------------- ipc/kdbus/domain.h | 77 ------------ ipc/kdbus/endpoint.h | 67 ---------- ipc/kdbus/fs.h | 28 ----- ipc/kdbus/handle.h | 85 ------------- ipc/kdbus/item.h | 64 ---------- ipc/kdbus/limits.h | 64 ---------- ipc/kdbus/match.h | 35 ------ ipc/kdbus/message.h | 133 -------------------- ipc/kdbus/metadata.h | 57 --------- ipc/kdbus/names.h | 74 ----------- ipc/kdbus/node.h | 84 ------------- ipc/kdbus/notify.h | 30 ----- ipc/kdbus/policy.h | 51 -------- ipc/kdbus/pool.h | 46 ------- ipc/kdbus/queue.h | 92 -------------- ipc/kdbus/reply.h | 68 ----------- ipc/kdbus/util.h | 74 ----------- 39 files changed, 1489 insertions(+), 1487 deletions(-) create mode 100644 include/linux/kdbus/bus.h create mode 100644 include/linux/kdbus/connection.h create mode 100644 include/linux/kdbus/domain.h create mode 100644 include/linux/kdbus/endpoint.h create mode 100644 include/linux/kdbus/fs.h create mode 100644 include/linux/kdbus/handle.h create mode 100644 include/linux/kdbus/item.h create mode 100644 include/linux/kdbus/limits.h create mode 100644 include/linux/kdbus/match.h create mode 100644 include/linux/kdbus/message.h create mode 100644 include/linux/kdbus/metadata.h create mode 100644 include/linux/kdbus/names.h create mode 100644 include/linux/kdbus/node.h create mode 100644 include/linux/kdbus/notify.h create mode 100644 include/linux/kdbus/policy.h create mode 100644 include/linux/kdbus/pool.h create mode 100644 include/linux/kdbus/queue.h create mode 100644 include/linux/kdbus/reply.h create mode 100644 include/linux/kdbus/util.h delete mode 100644 ipc/kdbus/bus.h delete mode 100644 ipc/kdbus/connection.h delete mode 100644 ipc/kdbus/domain.h delete mode 100644 ipc/kdbus/endpoint.h delete mode 100644 ipc/kdbus/fs.h delete mode 100644 ipc/kdbus/handle.h delete mode 100644 ipc/kdbus/item.h delete mode 100644 ipc/kdbus/limits.h delete mode 100644 ipc/kdbus/match.h delete mode 100644 ipc/kdbus/message.h delete mode 100644 ipc/kdbus/metadata.h delete mode 100644 ipc/kdbus/names.h delete mode 100644 ipc/kdbus/node.h delete mode 100644 ipc/kdbus/notify.h delete mode 100644 ipc/kdbus/policy.h delete mode 100644 ipc/kdbus/pool.h delete mode 100644 ipc/kdbus/queue.h delete mode 100644 ipc/kdbus/reply.h delete mode 100644 ipc/kdbus/util.h
diff --git a/include/linux/kdbus/bus.h b/include/linux/kdbus/bus.h new file mode 100644 index 0000000..5bea5ef --- /dev/null +++ b/include/linux/kdbus/bus.h @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUS_BUS_H +#define __KDBUS_BUS_H + +#include <linux/hashtable.h> +#include <linux/list.h> +#include <linux/mutex.h> +#include <linux/rwsem.h> +#include <linux/spinlock.h> +#include <uapi/linux/kdbus.h> + +#include "metadata.h" +#include "names.h" +#include "node.h" +#include "policy.h" + +struct kdbus_conn; +struct kdbus_domain; +struct kdbus_kmsg; +struct kdbus_user; + +/** + * struct kdbus_bus - bus in a domain + * @node: kdbus_node + * @id: ID of this bus in the domain + * @bus_flags: Simple pass-through flags from userspace to userspace + * @attach_flags_req: KDBUS_ATTACH_* flags required by connecting peers + * @attach_flags_owner: KDBUS_ATTACH_* flags of bus creator that other + * connections can see or query + * @id128: Unique random 128 bit ID of this bus + * @bloom: Bloom parameters + * @domain: Domain of this bus + * @creator: Creator of the bus + * @creator_meta: Meta information about the bus creator + * @policy_db: Policy database for this bus + * @name_registry: Name registry of this bus + * @conn_rwlock: Read/Write lock for all lists of child connections + * @conn_hash: Map of connection IDs + * @monitors_list: Connections that monitor this bus + * @notify_list: List of pending kernel-generated messages + * @notify_lock: Notification list lock + * @notify_flush_lock: Notification flushing lock + */ +struct kdbus_bus { + struct kdbus_node node; + + /* static */ + u64 id; + u64 bus_flags; + u64 attach_flags_req; + u64 attach_flags_owner; + u8 id128[16]; + struct kdbus_bloom_parameter bloom; + struct kdbus_domain *domain; + struct kdbus_user *creator; + struct kdbus_meta_proc *creator_meta; + + /* protected by own locks */ + struct kdbus_policy_db policy_db; + struct kdbus_name_registry *name_registry; + + /* protected by conn_rwlock */ + struct rw_semaphore conn_rwlock; + DECLARE_HASHTABLE(conn_hash, 8); + struct list_head monitors_list; + + /* protected by notify_lock */ + struct list_head notify_list; + spinlock_t notify_lock; + struct mutex notify_flush_lock; +}; + +struct kdbus_bus *kdbus_bus_ref(struct kdbus_bus *bus); +struct kdbus_bus *kdbus_bus_unref(struct kdbus_bus *bus); + +struct kdbus_conn *kdbus_bus_find_conn_by_id(struct kdbus_bus *bus, u64 id); +void kdbus_bus_broadcast(struct kdbus_bus *bus, + struct kdbus_conn *conn_src, + struct kdbus_kmsg *kmsg); +void kdbus_bus_eavesdrop(struct kdbus_bus *bus, + struct kdbus_conn *conn_src, + struct kdbus_kmsg *kmsg); + +struct kdbus_bus *kdbus_cmd_bus_make(struct kdbus_domain *domain, + void __user *argp); +int kdbus_cmd_bus_creator_info(struct kdbus_conn *conn, void __user *argp); + +#endif diff --git a/include/linux/kdbus/connection.h b/include/linux/kdbus/connection.h new file mode 100644 index 0000000..d1ffe90 --- /dev/null +++ b/include/linux/kdbus/connection.h @@ -0,0 +1,257 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * Copyright (C) 2014-2015 Djalal Harouni + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUS_CONNECTION_H +#define __KDBUS_CONNECTION_H + +#include <linux/atomic.h> +#include <linux/kref.h> +#include <linux/lockdep.h> +#include <linux/path.h> + +#include "limits.h" +#include "metadata.h" +#include "pool.h" +#include "queue.h" +#include "util.h" + +#define KDBUS_HELLO_SPECIAL_CONN (KDBUS_HELLO_ACTIVATOR | \ + KDBUS_HELLO_POLICY_HOLDER | \ + KDBUS_HELLO_MONITOR) + +struct kdbus_quota; +struct kdbus_kmsg; + +/** + * struct kdbus_conn - connection to a bus + * @kref: Reference count + * @active: Active references to the connection + * @id: Connection ID + * @flags: KDBUS_HELLO_* flags + * @attach_flags_send: KDBUS_ATTACH_* flags for sending + * @attach_flags_recv: KDBUS_ATTACH_* flags for receiving + * @description: Human-readable connection description, used for + * debugging. This field is only set when the + * connection is created. + * @ep: The endpoint this connection belongs to + * @lock: Connection data lock + * @hentry: Entry in ID <-> connection map + * @ep_entry: Entry in endpoint + * @monitor_entry: Entry in monitor, if the connection is a monitor + * @reply_list: List of connections this connection should + * reply to + * @work: Delayed work to handle timeouts + * activator for + * @match_db: Subscription filter to broadcast messages + * @meta: Active connection creator's metadata/credentials, + * either from the handle or from HELLO + * @pool: The user's buffer to receive messages + * @user: Owner of the connection + * @cred: The credentials of the connection at creation time + * @name_count: Number of owned well-known names + * @request_count: Number of pending requests issued by this + * connection that are waiting for replies from + * other peers + * @lost_count: Number of lost broadcast messages + * @wait: Wake up this endpoint + * @queue: The message queue associated with this connection + * @quota: Array of per-user quota indexed by user->id + * @n_quota: Number of elements in quota array + * @activator_of: Well-known name entry this connection acts as an + * @names_list: List of well-known names + * @names_queue_list: Well-known names this connection waits for + * @privileged: Whether this connection is privileged on the bus + * @faked_meta: Whether the metadata was faked on HELLO + */ +struct kdbus_conn { + struct kref kref; + atomic_t active; +#ifdef CONFIG_DEBUG_LOCK_ALLOC + struct lockdep_map dep_map; +#endif + u64 id; + u64 flags; + atomic64_t attach_flags_send; + atomic64_t attach_flags_recv; + const char *description; + struct kdbus_ep *ep; + struct mutex lock; + struct hlist_node hentry; + struct list_head ep_entry; + struct list_head monitor_entry; + struct list_head reply_list; + struct delayed_work work; + struct kdbus_match_db *match_db; + struct kdbus_meta_proc *meta; + struct kdbus_pool *pool; + struct kdbus_user *user; + const struct cred *cred; + atomic_t name_count; + atomic_t request_count; + atomic_t lost_count; + wait_queue_head_t wait; + struct kdbus_queue queue; + + struct kdbus_quota *quota; + unsigned int n_quota; + + /* protected by registry->rwlock */ + struct kdbus_name_entry *activator_of; + struct list_head names_list; + struct list_head names_queue_list; + + bool privileged:1; + bool faked_meta:1; +}; + +struct kdbus_conn *kdbus_conn_ref(struct kdbus_conn *conn); +struct kdbus_conn *kdbus_conn_unref(struct kdbus_conn *conn); +bool kdbus_conn_active(const struct kdbus_conn *conn); +int kdbus_conn_acquire(struct kdbus_conn *conn); +void kdbus_conn_release(struct kdbus_conn *conn); +int kdbus_conn_disconnect(struct kdbus_conn *conn, bool ensure_queue_empty); +bool kdbus_conn_has_name(struct kdbus_conn *conn, const char *name); +int kdbus_conn_quota_inc(struct kdbus_conn *c, struct kdbus_user *u, + size_t memory, size_t fds); +void kdbus_conn_quota_dec(struct kdbus_conn *c, struct kdbus_user *u, + size_t memory, size_t fds); +void kdbus_conn_lost_message(struct kdbus_conn *c); +int kdbus_conn_entry_insert(struct kdbus_conn *conn_src, + struct kdbus_conn *conn_dst, + const struct kdbus_kmsg *kmsg, + struct kdbus_reply *reply); +void kdbus_conn_move_messages(struct kdbus_conn *conn_dst, + struct kdbus_conn *conn_src, + u64 name_id); + +/* policy */ +bool kdbus_conn_policy_own_name(struct kdbus_conn *conn, + const struct cred *conn_creds, + const char *name); +bool kdbus_conn_policy_talk(struct kdbus_conn *conn, + const struct cred *conn_creds, + struct kdbus_conn *to); +bool kdbus_conn_policy_see_name_unlocked(struct kdbus_conn *conn, + const struct cred *curr_creds, + const char *name); +bool kdbus_conn_policy_see_notification(struct kdbus_conn *conn, + const struct cred *curr_creds, + const struct kdbus_kmsg *kmsg); + +/* command dispatcher */ +struct kdbus_conn *kdbus_cmd_hello(struct kdbus_ep *ep, bool privileged, + void __user *argp); +int kdbus_cmd_byebye_unlocked(struct kdbus_conn *conn, void __user *argp); +int kdbus_cmd_conn_info(struct kdbus_conn *conn, void __user *argp); +int kdbus_cmd_update(struct kdbus_conn *conn, void __user *argp); +int kdbus_cmd_send(struct kdbus_conn *conn, struct file *f, void __user *argp); +int kdbus_cmd_recv(struct kdbus_conn *conn, void __user *argp); +int kdbus_cmd_free(struct kdbus_conn *conn, void __user *argp); + +/** + * kdbus_conn_is_ordinary() - Check if connection is ordinary + * @conn: The connection to check + * + * Return: Non-zero if the connection is an ordinary connection + */ +static inline int kdbus_conn_is_ordinary(const struct kdbus_conn *conn) +{ + return !(conn->flags & KDBUS_HELLO_SPECIAL_CONN); +} + +/** + * kdbus_conn_is_activator() - Check if connection is an activator + * @conn: The connection to check + * + * Return: Non-zero if the connection is an activator + */ +static inline int kdbus_conn_is_activator(const struct kdbus_conn *conn) +{ + return conn->flags & KDBUS_HELLO_ACTIVATOR; +} + +/** + * kdbus_conn_is_policy_holder() - Check if connection is a policy holder + * @conn: The connection to check + * + * Return: Non-zero if the connection is a policy holder + */ +static inline int kdbus_conn_is_policy_holder(const struct kdbus_conn *conn) +{ + return conn->flags & KDBUS_HELLO_POLICY_HOLDER; +} + +/** + * kdbus_conn_is_monitor() - Check if connection is a monitor + * @conn: The connection to check + * + * Return: Non-zero if the connection is a monitor + */ +static inline int kdbus_conn_is_monitor(const struct kdbus_conn *conn) +{ + return conn->flags & KDBUS_HELLO_MONITOR; +} + +/** + * kdbus_conn_lock2() - Lock two connections + * @a: connection A to lock or NULL + * @b: connection B to lock or NULL + * + * Lock two connections at once. As we need to have a stable locking order, we + * always lock the connection with lower memory address first. + */ +static inline void kdbus_conn_lock2(struct kdbus_conn *a, struct kdbus_conn *b) +{ + if (a < b) { + if (a) + mutex_lock(&a->lock); + if (b && b != a) + mutex_lock_nested(&b->lock, !!a); + } else { + if (b) + mutex_lock(&b->lock); + if (a && a != b) + mutex_lock_nested(&a->lock, !!b); + } +} + +/** + * kdbus_conn_unlock2() - Unlock two connections + * @a: connection A to unlock or NULL + * @b: connection B to unlock or NULL + * + * Unlock two connections at once. See kdbus_conn_lock2(). + */ +static inline void kdbus_conn_unlock2(struct kdbus_conn *a, + struct kdbus_conn *b) +{ + if (a) + mutex_unlock(&a->lock); + if (b && b != a) + mutex_unlock(&b->lock); +} + +/** + * kdbus_conn_assert_active() - lockdep assert on active lock + * @conn: connection that shall be active + * + * This verifies via lockdep that the caller holds an active reference to the + * given connection. + */ +static inline void kdbus_conn_assert_active(struct kdbus_conn *conn) +{ + lockdep_assert_held(conn); +} + +#endif diff --git a/include/linux/kdbus/domain.h b/include/linux/kdbus/domain.h new file mode 100644 index 0000000..447a2bd --- /dev/null +++ b/include/linux/kdbus/domain.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUS_DOMAIN_H +#define __KDBUS_DOMAIN_H + +#include <linux/fs.h> +#include <linux/idr.h> +#include <linux/kref.h> +#include <linux/user_namespace.h> + +#include "node.h" + +/** + * struct kdbus_domain - domain for buses + * @node: Underlying API node + * @lock: Domain data lock + * @last_id: Last used object id + * @user_idr: Set of all users indexed by UID + * @user_ida: Set of all users to compute small indices + * @user_namespace: User namespace, pinned at creation time + * @dentry: Root dentry of VFS mount (don't use outside of kdbusfs) + */ +struct kdbus_domain { + struct kdbus_node node; + struct mutex lock; + atomic64_t last_id; + struct idr user_idr; + struct ida user_ida; + struct user_namespace *user_namespace; + struct dentry *dentry; +}; + +/** + * struct kdbus_user - resource accounting for users + * @kref: Reference counter + * @domain: Domain of the user + * @id: Index of this user + * @uid: UID of the user + * @buses: Number of buses the user has created + * @connections: Number of connections the user has created + */ +struct kdbus_user { + struct kref kref; + struct kdbus_domain *domain; + unsigned int id; + kuid_t uid; + atomic_t buses; + atomic_t connections; +}; + +#define kdbus_domain_from_node(_node) \ + container_of((_node), struct kdbus_domain, node) + +struct kdbus_domain *kdbus_domain_new(unsigned int access); +struct kdbus_domain *kdbus_domain_ref(struct kdbus_domain *domain); +struct kdbus_domain *kdbus_domain_unref(struct kdbus_domain *domain); +int kdbus_domain_populate(struct kdbus_domain *domain, unsigned int access); + +#define KDBUS_USER_KERNEL_ID 0 /* ID 0 is reserved for kernel accounting */ + +struct kdbus_user *kdbus_user_lookup(struct kdbus_domain *domain, kuid_t uid); +struct kdbus_user *kdbus_user_ref(struct kdbus_user *u); +struct kdbus_user *kdbus_user_unref(struct kdbus_user *u); + +#endif diff --git a/include/linux/kdbus/endpoint.h b/include/linux/kdbus/endpoint.h new file mode 100644 index 0000000..d31954b --- /dev/null +++ b/include/linux/kdbus/endpoint.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUS_ENDPOINT_H +#define __KDBUS_ENDPOINT_H + +#include <linux/list.h> +#include <linux/mutex.h> +#include <linux/uidgid.h> +#include "node.h" +#include "policy.h" + +struct kdbus_bus; +struct kdbus_user; + +/** + * struct kdbus_ep - enpoint to access a bus + * @node: The kdbus node + * @lock: Endpoint data lock + * @bus: Bus behind this endpoint + * @user: Custom enpoints account against an anonymous user + * @policy_db: Uploaded policy + * @conn_list: Connections of this endpoint + * + * An enpoint offers access to a bus; the default endpoint node name is "bus". + * Additional custom endpoints to the same bus can be created and they can + * carry their own policies/filters. + */ +struct kdbus_ep { + struct kdbus_node node; + struct mutex lock; + + /* static */ + struct kdbus_bus *bus; + struct kdbus_user *user; + + /* protected by own locks */ + struct kdbus_policy_db policy_db; + + /* protected by ep->lock */ + struct list_head conn_list; +}; + +#define kdbus_ep_from_node(_node) \ + container_of((_node), struct kdbus_ep, node) + +struct kdbus_ep *kdbus_ep_new(struct kdbus_bus *bus, const char *name, + unsigned int access, kuid_t uid, kgid_t gid, + bool policy); +struct kdbus_ep *kdbus_ep_ref(struct kdbus_ep *ep); +struct kdbus_ep *kdbus_ep_unref(struct kdbus_ep *ep); + +struct kdbus_ep *kdbus_cmd_ep_make(struct kdbus_bus *bus, void __user *argp); +int kdbus_cmd_ep_update(struct kdbus_ep *ep, void __user *argp); + +#endif diff --git a/include/linux/kdbus/fs.h b/include/linux/kdbus/fs.h new file mode 100644 index 0000000..62f7d6a --- /dev/null +++ b/include/linux/kdbus/fs.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUSFS_H +#define __KDBUSFS_H + +#include <linux/kernel.h> + +struct kdbus_node; + +int kdbus_fs_init(void); +void kdbus_fs_exit(void); +void kdbus_fs_flush(struct kdbus_node *node); + +#define kdbus_node_from_inode(_inode) \ + ((struct kdbus_node *)(_inode)->i_private) + +#endif diff --git a/include/linux/kdbus/handle.h b/include/linux/kdbus/handle.h new file mode 100644 index 0000000..93a372d --- /dev/null +++ b/include/linux/kdbus/handle.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUS_HANDLE_H +#define __KDBUS_HANDLE_H + +#include <linux/fs.h> +#include <uapi/linux/kdbus.h> + +extern const struct file_operations kdbus_handle_ops; + +/** + * kdbus_arg - information and state of a single ioctl command item + * @type: item type + * @item: set by the parser to the first found item of this type + * @multiple: whether multiple items of this type are allowed + * @mandatory: whether at least one item of this type is required + * + * This structure describes a single item in an ioctl command payload. The + * caller has to pre-fill the type and flags, the parser will then use this + * information to verify the ioctl payload. @item is set by the parser to point + * to the first occurrence of the item. + */ +struct kdbus_arg { + u64 type; + struct kdbus_item *item; + bool multiple : 1; + bool mandatory : 1; +}; + +/** + * kdbus_args - information and state of ioctl command parser + * @allowed_flags: set of flags this command supports + * @argc: number of items in @argv + * @argv: array of items this command supports + * @user: set by parser to user-space location of current command + * @cmd: set by parser to kernel copy of command payload + * @items: points to item array in @cmd + * @items_size: size of @items in bytes + * + * This structure is used to parse ioctl command payloads on each invocation. + * The ioctl handler has to pre-fill the flags and allowed items before passing + * the object to kdbus_args_parse(). The parser will copy the command payload + * into kernel-space and verify the correctness of the data. + */ +struct kdbus_args { + u64 allowed_flags; + size_t argc; + struct kdbus_arg *argv; + + struct kdbus_cmd __user *user; + struct kdbus_cmd *cmd; + + struct kdbus_item *items; + size_t items_size; +}; + +int __kdbus_args_parse(struct kdbus_args *args, void __user *argp, + size_t type_size, size_t items_offset, void **out); +int kdbus_args_clear(struct kdbus_args *args, int ret); + +#define kdbus_args_parse(_args, _argp, _v) \ + ({ \ + BUILD_BUG_ON(offsetof(typeof(**(_v)), size) != \ + offsetof(struct kdbus_cmd, size)); \ + BUILD_BUG_ON(offsetof(typeof(**(_v)), flags) != \ + offsetof(struct kdbus_cmd, flags)); \ + BUILD_BUG_ON(offsetof(typeof(**(_v)), return_flags) != \ + offsetof(struct kdbus_cmd, return_flags)); \ + __kdbus_args_parse((_args), (_argp), sizeof(**(_v)), \ + offsetof(typeof(**(_v)), items), \ + (void **)(_v)); \ + }) + +#endif diff --git a/include/linux/kdbus/item.h b/include/linux/kdbus/item.h new file mode 100644 index 0000000..eeefd8b --- /dev/null +++ b/include/linux/kdbus/item.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUS_ITEM_H +#define __KDBUS_ITEM_H + +#include <linux/kernel.h> +#include <uapi/linux/kdbus.h> + +#include "util.h" + +/* generic access and iterators over a stream of items */ +#define KDBUS_ITEM_NEXT(_i) (typeof(_i))(((u8 *)_i) + KDBUS_ALIGN8((_i)->size)) +#define KDBUS_ITEMS_SIZE(_h, _is) ((_h)->size - offsetof(typeof(*_h), _is)) +#define KDBUS_ITEM_HEADER_SIZE offsetof(struct kdbus_item, data) +#define KDBUS_ITEM_SIZE(_s) KDBUS_ALIGN8(KDBUS_ITEM_HEADER_SIZE + (_s)) +#define KDBUS_ITEM_PAYLOAD_SIZE(_i) ((_i)->size - KDBUS_ITEM_HEADER_SIZE) + +#define KDBUS_ITEMS_FOREACH(_i, _is, _s) \ + for (_i = _is; \ + ((u8 *)(_i) < (u8 *)(_is) + (_s)) && \ + ((u8 *)(_i) >= (u8 *)(_is)); \ + _i = KDBUS_ITEM_NEXT(_i)) + +#define KDBUS_ITEM_VALID(_i, _is, _s) \ + ((_i)->size >= KDBUS_ITEM_HEADER_SIZE && \ + (u8 *)(_i) + (_i)->size > (u8 *)(_i) && \ + (u8 *)(_i) + (_i)->size <= (u8 *)(_is) + (_s) && \ + (u8 *)(_i) >= (u8 *)(_is)) + +#define KDBUS_ITEMS_END(_i, _is, _s) \ + ((u8 *)_i == ((u8 *)(_is) + KDBUS_ALIGN8(_s))) + +/** + * struct kdbus_item_header - Describes the fix part of an item + * @size: The total size of the item + * @type: The item type, one of KDBUS_ITEM_* + */ +struct kdbus_item_header { + u64 size; + u64 type; +}; + +int kdbus_item_validate_name(const struct kdbus_item *item); +int kdbus_item_validate(const struct kdbus_item *item); +int kdbus_items_validate(const struct kdbus_item *items, size_t items_size); +const char *kdbus_items_get_str(const struct kdbus_item *items, + size_t items_size, + unsigned int item_type); +struct kdbus_item *kdbus_item_set(struct kdbus_item *item, u64 type, + const void *data, size_t len); + +#endif diff --git a/include/linux/kdbus/limits.h b/include/linux/kdbus/limits.h new file mode 100644 index 0000000..6450f58 --- /dev/null +++ b/include/linux/kdbus/limits.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUS_DEFAULTS_H +#define __KDBUS_DEFAULTS_H + +#include <linux/kernel.h> + +/* maximum size of message header and items */ +#define KDBUS_MSG_MAX_SIZE SZ_8K + +/* maximum number of message items */ +#define KDBUS_MSG_MAX_ITEMS 128 + +/* maximum number of memfd items per message */ +#define KDBUS_MSG_MAX_MEMFD_ITEMS 16 + +/* max size of ioctl command data */ +#define KDBUS_CMD_MAX_SIZE SZ_32K + +/* maximum number of inflight fds in a target queue per user */ +#define KDBUS_CONN_MAX_FDS_PER_USER 16 + +/* maximum message payload size */ +#define KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE SZ_2M + +/* maximum size of bloom bit field in bytes */ +#define KDBUS_BUS_BLOOM_MAX_SIZE SZ_4K + +/* maximum length of well-known bus name */ +#define KDBUS_NAME_MAX_LEN 255 + +/* maximum length of bus, domain, ep name */ +#define KDBUS_SYSNAME_MAX_LEN 63 + +/* maximum number of matches per connection */ +#define KDBUS_MATCH_MAX 256 + +/* maximum number of queued messages from the same individual user */ +#define KDBUS_CONN_MAX_MSGS 256 + +/* maximum number of well-known names per connection */ +#define KDBUS_CONN_MAX_NAMES 256 + +/* maximum number of queued requests waiting for a reply */ +#define KDBUS_CONN_MAX_REQUESTS_PENDING 128 + +/* maximum number of connections per user in one domain */ +#define KDBUS_USER_MAX_CONN 1024 + +/* maximum number of buses per user in one domain */ +#define KDBUS_USER_MAX_BUSES 16 + +#endif diff --git a/include/linux/kdbus/match.h b/include/linux/kdbus/match.h new file mode 100644 index 0000000..ea42929 --- /dev/null +++ b/include/linux/kdbus/match.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUS_MATCH_H +#define __KDBUS_MATCH_H + +struct kdbus_conn; +struct kdbus_kmsg; +struct kdbus_match_db; + +struct kdbus_match_db *kdbus_match_db_new(void); +void kdbus_match_db_free(struct kdbus_match_db *db); +int kdbus_match_db_add(struct kdbus_conn *conn, + struct kdbus_cmd_match *cmd); +int kdbus_match_db_remove(struct kdbus_conn *conn, + struct kdbus_cmd_match *cmd); +bool kdbus_match_db_match_kmsg(struct kdbus_match_db *db, + struct kdbus_conn *conn_src, + struct kdbus_kmsg *kmsg); + +int kdbus_cmd_match_add(struct kdbus_conn *conn, void __user *argp); +int kdbus_cmd_match_remove(struct kdbus_conn *conn, void __user *argp); + +#endif diff --git a/include/linux/kdbus/message.h b/include/linux/kdbus/message.h new file mode 100644 index 0000000..af47758 --- /dev/null +++ b/include/linux/kdbus/message.h @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUS_MESSAGE_H +#define __KDBUS_MESSAGE_H + +#include "util.h" +#include "metadata.h" + +/** + * enum kdbus_msg_data_type - Type of kdbus_msg_data payloads + * @KDBUS_MSG_DATA_VEC: Data vector provided by user-space + * @KDBUS_MSG_DATA_MEMFD: Memfd payload + */ +enum kdbus_msg_data_type { + KDBUS_MSG_DATA_VEC, + KDBUS_MSG_DATA_MEMFD, +}; + +/** + * struct kdbus_msg_data - Data payload as stored by messages + * @type: Type of payload (KDBUS_MSG_DATA_*) + * @size: Size of the described payload + * @off: The offset, relative to the vec slice + * @start: Offset inside the memfd + * @file: Backing file referenced by the memfd + */ +struct kdbus_msg_data { + unsigned int type; + u64 size; + + union { + struct { + u64 off; + } vec; + struct { + u64 start; + struct file *file; + } memfd; + }; +}; + +/** + * struct kdbus_kmsg_resources - resources of a message + * @kref: Reference counter + * @dst_name: Short-cut to msg for faster lookup + * @fds: Array of file descriptors to pass + * @fds_count: Number of file descriptors to pass + * @data: Array of data payloads + * @vec_count: Number of VEC entries + * @memfd_count: Number of MEMFD entries in @data + * @data_count: Sum of @vec_count + @memfd_count + */ +struct kdbus_msg_resources { + struct kref kref; + const char *dst_name; + + struct file **fds; + unsigned int fds_count; + + struct kdbus_msg_data *data; + size_t vec_count; + size_t memfd_count; + size_t data_count; +}; + +struct kdbus_msg_resources * +kdbus_msg_resources_ref(struct kdbus_msg_resources *r); +struct kdbus_msg_resources * +kdbus_msg_resources_unref(struct kdbus_msg_resources *r); + +/** + * struct kdbus_kmsg - internal message handling data + * @seq: Domain-global message sequence number + * @notify_type: Short-cut for faster lookup + * @notify_old_id: Short-cut for faster lookup + * @notify_new_id: Short-cut for faster lookup + * @notify_name: Short-cut for faster lookup + * @dst_name_id: Short-cut to msg for faster lookup + * @bloom_filter: Bloom filter to match message properties + * @bloom_generation: Generation of bloom element set + * @notify_entry: List of kernel-generated notifications + * @iov: Array of iovec, describing the payload to copy + * @iov_count: Number of array members in @iov + * @pool_size: Overall size of inlined data referenced by @iov + * @proc_meta: Appended SCM-like metadata of the sending process + * @conn_meta: Appended SCM-like metadata of the sending connection + * @res: Message resources + * @msg: Message from or to userspace + */ +struct kdbus_kmsg { + u64 seq; + u64 notify_type; + u64 notify_old_id; + u64 notify_new_id; + const char *notify_name; + + u64 dst_name_id; + const struct kdbus_bloom_filter *bloom_filter; + u64 bloom_generation; + struct list_head notify_entry; + + struct iovec *iov; + size_t iov_count; + u64 pool_size; + + struct kdbus_meta_proc *proc_meta; + struct kdbus_meta_conn *conn_meta; + struct kdbus_msg_resources *res; + + /* variable size, must be the last member */ + struct kdbus_msg msg; +}; + +struct kdbus_bus; +struct kdbus_conn; + +struct kdbus_kmsg *kdbus_kmsg_new(struct kdbus_bus *bus, size_t extra_size); +struct kdbus_kmsg *kdbus_kmsg_new_from_cmd(struct kdbus_conn *conn, + struct kdbus_cmd_send *cmd_send); +void kdbus_kmsg_free(struct kdbus_kmsg *kmsg); + +#endif diff --git a/include/linux/kdbus/metadata.h b/include/linux/kdbus/metadata.h new file mode 100644 index 0000000..42c942b --- /dev/null +++ b/include/linux/kdbus/metadata.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * Copyright (C) 2014-2015 Djalal Harouni + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUS_METADATA_H +#define __KDBUS_METADATA_H + +#include <linux/kernel.h> + +struct kdbus_conn; +struct kdbus_kmsg; +struct kdbus_pool_slice; + +struct kdbus_meta_proc; +struct kdbus_meta_conn; + +extern unsigned long long kdbus_meta_attach_mask; + +struct kdbus_meta_proc *kdbus_meta_proc_new(void); +struct kdbus_meta_proc *kdbus_meta_proc_ref(struct kdbus_meta_proc *mp); +struct kdbus_meta_proc *kdbus_meta_proc_unref(struct kdbus_meta_proc *mp); +int kdbus_meta_proc_collect(struct kdbus_meta_proc *mp, u64 what); +int kdbus_meta_proc_fake(struct kdbus_meta_proc *mp, + const struct kdbus_creds *creds, + const struct kdbus_pids *pids, + const char *seclabel); + +struct kdbus_meta_conn *kdbus_meta_conn_new(void); +struct kdbus_meta_conn *kdbus_meta_conn_ref(struct kdbus_meta_conn *mc); +struct kdbus_meta_conn *kdbus_meta_conn_unref(struct kdbus_meta_conn *mc); +int kdbus_meta_conn_collect(struct kdbus_meta_conn *mc, + struct kdbus_kmsg *kmsg, + struct kdbus_conn *conn, + u64 what); + +int kdbus_meta_export_prepare(struct kdbus_meta_proc *mp, + struct kdbus_meta_conn *mc, + u64 *mask, size_t *sz); +int kdbus_meta_export(struct kdbus_meta_proc *mp, + struct kdbus_meta_conn *mc, + u64 mask, + struct kdbus_pool_slice *slice, + off_t offset, size_t *real_size); +u64 kdbus_meta_calc_attach_flags(const struct kdbus_conn *sender, + const struct kdbus_conn *receiver); + +#endif diff --git a/include/linux/kdbus/names.h b/include/linux/kdbus/names.h new file mode 100644 index 0000000..3dd2589 --- /dev/null +++ b/include/linux/kdbus/names.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUS_NAMES_H +#define __KDBUS_NAMES_H + +#include <linux/hashtable.h> +#include <linux/rwsem.h> + +/** + * struct kdbus_name_registry - names registered for a bus + * @entries_hash: Map of entries + * @lock: Registry data lock + * @name_seq_last: Last used sequence number to assign to a name entry + */ +struct kdbus_name_registry { + DECLARE_HASHTABLE(entries_hash, 8); + struct rw_semaphore rwlock; + u64 name_seq_last; +}; + +/** + * struct kdbus_name_entry - well-know name entry + * @name_id: Sequence number of name entry to be able to uniquely + * identify a name over its registration lifetime + * @flags: KDBUS_NAME_* flags + * @conn: Connection owning the name + * @activator: Connection of the activator queuing incoming messages + * @queue: List of queued connections + * @conn_entry: Entry in connection + * @hentry: Entry in registry map + * @name: The well-known name + */ +struct kdbus_name_entry { + u64 name_id; + u64 flags; + struct kdbus_conn *conn; + struct kdbus_conn *activator; + struct list_head queue; + struct list_head conn_entry; + struct hlist_node hentry; + char name[]; +}; + +bool kdbus_name_is_valid(const char *p, bool allow_wildcard); + +struct kdbus_name_registry *kdbus_name_registry_new(void); +void kdbus_name_registry_free(struct kdbus_name_registry *reg); + +struct kdbus_name_entry * +kdbus_name_lookup_unlocked(struct kdbus_name_registry *reg, const char *name); + +int kdbus_name_acquire(struct kdbus_name_registry *reg, + struct kdbus_conn *conn, const char *name, + u64 flags, u64 *return_flags); +void kdbus_name_release_all(struct kdbus_name_registry *reg, + struct kdbus_conn *conn); + +int kdbus_cmd_name_acquire(struct kdbus_conn *conn, void __user *argp); +int kdbus_cmd_name_release(struct kdbus_conn *conn, void __user *argp); +int kdbus_cmd_list(struct kdbus_conn *conn, void __user *argp); + +#endif diff --git a/include/linux/kdbus/node.h b/include/linux/kdbus/node.h new file mode 100644 index 0000000..be125ce --- /dev/null +++ b/include/linux/kdbus/node.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUS_NODE_H +#define __KDBUS_NODE_H + +#include <linux/atomic.h> +#include <linux/kernel.h> +#include <linux/mutex.h> +#include <linux/wait.h> + +struct kdbus_node; + +enum kdbus_node_type { + KDBUS_NODE_DOMAIN, + KDBUS_NODE_CONTROL, + KDBUS_NODE_BUS, + KDBUS_NODE_ENDPOINT, +}; + +typedef void (*kdbus_node_free_t) (struct kdbus_node *node); +typedef void (*kdbus_node_release_t) (struct kdbus_node *node, bool was_active); + +struct kdbus_node { + atomic_t refcnt; + atomic_t active; + wait_queue_head_t waitq; + + /* static members */ + unsigned int type; + kdbus_node_free_t free_cb; + kdbus_node_release_t release_cb; + umode_t mode; + kuid_t uid; + kgid_t gid; + + /* valid once linked */ + char *name; + unsigned int hash; + unsigned int id; + struct kdbus_node *parent; /* may be NULL */ + + /* valid iff active */ + struct mutex lock; + struct rb_node rb; + struct rb_root children; +}; + +#define kdbus_node_from_rb(_node) rb_entry((_node), struct kdbus_node, rb) + +void kdbus_node_init(struct kdbus_node *node, unsigned int type); + +int kdbus_node_link(struct kdbus_node *node, struct kdbus_node *parent, + const char *name); + +struct kdbus_node *kdbus_node_ref(struct kdbus_node *node); +struct kdbus_node *kdbus_node_unref(struct kdbus_node *node); + +bool kdbus_node_is_active(struct kdbus_node *node); +bool kdbus_node_is_deactivated(struct kdbus_node *node); +bool kdbus_node_activate(struct kdbus_node *node); +void kdbus_node_deactivate(struct kdbus_node *node); + +bool kdbus_node_acquire(struct kdbus_node *node); +void kdbus_node_release(struct kdbus_node *node); + +struct kdbus_node *kdbus_node_find_child(struct kdbus_node *node, + const char *name); +struct kdbus_node *kdbus_node_find_closest(struct kdbus_node *node, + unsigned int hash); +struct kdbus_node *kdbus_node_next_child(struct kdbus_node *node, + struct kdbus_node *prev); + +#endif diff --git a/include/linux/kdbus/notify.h b/include/linux/kdbus/notify.h new file mode 100644 index 0000000..03df464 --- /dev/null +++ b/include/linux/kdbus/notify.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUS_NOTIFY_H +#define __KDBUS_NOTIFY_H + +struct kdbus_bus; + +int kdbus_notify_id_change(struct kdbus_bus *bus, u64 type, u64 id, u64 flags); +int kdbus_notify_reply_timeout(struct kdbus_bus *bus, u64 id, u64 cookie); +int kdbus_notify_reply_dead(struct kdbus_bus *bus, u64 id, u64 cookie); +int kdbus_notify_name_change(struct kdbus_bus *bus, u64 type, + u64 old_id, u64 new_id, + u64 old_flags, u64 new_flags, + const char *name); +void kdbus_notify_flush(struct kdbus_bus *bus); +void kdbus_notify_free(struct kdbus_bus *bus); + +#endif diff --git a/include/linux/kdbus/policy.h b/include/linux/kdbus/policy.h new file mode 100644 index 0000000..15dd7bc --- /dev/null +++ b/include/linux/kdbus/policy.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUS_POLICY_H +#define __KDBUS_POLICY_H + +#include <linux/hashtable.h> +#include <linux/rwsem.h> + +struct kdbus_conn; +struct kdbus_item; + +/** + * struct kdbus_policy_db - policy database + * @entries_hash: Hashtable of entries + * @entries_rwlock: Mutex to protect the database's access entries + */ +struct kdbus_policy_db { + DECLARE_HASHTABLE(entries_hash, 6); + struct rw_semaphore entries_rwlock; +}; + +void kdbus_policy_db_init(struct kdbus_policy_db *db); +void kdbus_policy_db_clear(struct kdbus_policy_db *db); + +int kdbus_policy_query_unlocked(struct kdbus_policy_db *db, + const struct cred *cred, const char *name, + unsigned int hash); +int kdbus_policy_query(struct kdbus_policy_db *db, const struct cred *cred, + const char *name, unsigned int hash); + +void kdbus_policy_remove_owner(struct kdbus_policy_db *db, + const void *owner); +int kdbus_policy_set(struct kdbus_policy_db *db, + const struct kdbus_item *items, + size_t items_size, + size_t max_policies, + bool allow_wildcards, + const void *owner); + +#endif diff --git a/include/linux/kdbus/pool.h b/include/linux/kdbus/pool.h new file mode 100644 index 0000000..a903821 --- /dev/null +++ b/include/linux/kdbus/pool.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUS_POOL_H +#define __KDBUS_POOL_H + +#include <linux/uio.h> + +struct kdbus_pool; +struct kdbus_pool_slice; + +struct kdbus_pool *kdbus_pool_new(const char *name, size_t size); +void kdbus_pool_free(struct kdbus_pool *pool); +void kdbus_pool_accounted(struct kdbus_pool *pool, size_t *size, size_t *acc); +int kdbus_pool_mmap(const struct kdbus_pool *pool, struct vm_area_struct *vma); +int kdbus_pool_release_offset(struct kdbus_pool *pool, size_t off); +void kdbus_pool_publish_empty(struct kdbus_pool *pool, u64 *off, u64 *size); + +struct kdbus_pool_slice *kdbus_pool_slice_alloc(struct kdbus_pool *pool, + size_t size, bool accounted); +void kdbus_pool_slice_release(struct kdbus_pool_slice *slice); +void kdbus_pool_slice_publish(struct kdbus_pool_slice *slice, + u64 *out_offset, u64 *out_size); +off_t kdbus_pool_slice_offset(const struct kdbus_pool_slice *slice); +size_t kdbus_pool_slice_size(const struct kdbus_pool_slice *slice); +int kdbus_pool_slice_copy(const struct kdbus_pool_slice *slice_dst, + const struct kdbus_pool_slice *slice_src); +ssize_t kdbus_pool_slice_copy_kvec(const struct kdbus_pool_slice *slice, + loff_t off, struct kvec *kvec, + size_t kvec_count, size_t total_len); +ssize_t kdbus_pool_slice_copy_iovec(const struct kdbus_pool_slice *slice, + loff_t off, struct iovec *iov, + size_t iov_count, size_t total_len); + +#endif diff --git a/include/linux/kdbus/queue.h b/include/linux/kdbus/queue.h new file mode 100644 index 0000000..7f2db96 --- /dev/null +++ b/include/linux/kdbus/queue.h @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUS_QUEUE_H +#define __KDBUS_QUEUE_H + +struct kdbus_user; + +/** + * struct kdbus_queue - a connection's message queue + * @msg_list: List head for kdbus_queue_entry objects + * @msg_prio_queue: RB tree root for messages, sorted by priority + * @msg_prio_highest: Link to the RB node referencing the message with the + * highest priority in the tree. + */ +struct kdbus_queue { + struct list_head msg_list; + struct rb_root msg_prio_queue; + struct rb_node *msg_prio_highest; +}; + +/** + * struct kdbus_queue_entry - messages waiting to be read + * @entry: Entry in the connection's list + * @prio_node: Entry in the priority queue tree + * @prio_entry: Queue tree node entry in the list of one priority + * @slice: Slice in the receiver's pool for the message + * @attach_flags: Attach flags used during slice allocation + * @meta_offset: Offset of first metadata item in slice + * @fds_offset: Offset of FD item in slice + * @memfd_offset: Array of slice-offsets for all memfd items + * @priority: Message priority + * @dst_name_id: The sequence number of the name this message is + * addressed to, 0 for messages sent to an ID + * @msg_res: Message resources + * @proc_meta: Process metadata, captured at message arrival + * @conn_meta: Connection metadata, captured at message arrival + * @reply: The reply block if a reply to this message is expected + * @user: User used for accounting + */ +struct kdbus_queue_entry { + struct list_head entry; + struct rb_node prio_node; + struct list_head prio_entry; + + struct kdbus_pool_slice *slice; + + u64 attach_flags; + size_t meta_offset; + size_t fds_offset; + size_t *memfd_offset; + + s64 priority; + u64 dst_name_id; + + struct kdbus_msg_resources *msg_res; + struct kdbus_meta_proc *proc_meta; + struct kdbus_meta_conn *conn_meta; + struct kdbus_reply *reply; + struct kdbus_conn *conn; + struct kdbus_user *user; +}; + +struct kdbus_kmsg; + +void kdbus_queue_init(struct kdbus_queue *queue); +struct kdbus_queue_entry *kdbus_queue_peek(struct kdbus_queue *queue, + s64 priority, bool use_priority); + +struct kdbus_queue_entry *kdbus_queue_entry_new(struct kdbus_conn *conn_dst, + const struct kdbus_kmsg *kmsg, + struct kdbus_user *user); +void kdbus_queue_entry_free(struct kdbus_queue_entry *entry); +int kdbus_queue_entry_install(struct kdbus_queue_entry *entry, + u64 *return_flags, bool install_fds); +void kdbus_queue_entry_enqueue(struct kdbus_queue_entry *entry, + struct kdbus_reply *reply); +int kdbus_queue_entry_move(struct kdbus_queue_entry *entry, + struct kdbus_conn *dst); + +#endif /* __KDBUS_QUEUE_H */ diff --git a/include/linux/kdbus/reply.h b/include/linux/kdbus/reply.h new file mode 100644 index 0000000..68d5232 --- /dev/null +++ b/include/linux/kdbus/reply.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUS_REPLY_H +#define __KDBUS_REPLY_H + +/** + * struct kdbus_reply - an entry of kdbus_conn's list of replies + * @kref: Ref-count of this object + * @entry: The entry of the connection's reply_list + * @reply_src: The connection the reply will be sent from + * @reply_dst: The connection the reply will be sent to + * @queue_entry: The queue entry item that is prepared by the replying + * connection + * @deadline_ns: The deadline of the reply, in nanoseconds + * @cookie: The cookie of the requesting message + * @name_id: ID of the well-known name the original msg was sent to + * @sync: The reply block is waiting for synchronous I/O + * @waiting: The condition to synchronously wait for + * @interrupted: The sync reply was left in an interrupted state + * @err: The error code for the synchronous reply + */ +struct kdbus_reply { + struct kref kref; + struct list_head entry; + struct kdbus_conn *reply_src; + struct kdbus_conn *reply_dst; + struct kdbus_queue_entry *queue_entry; + u64 deadline_ns; + u64 cookie; + u64 name_id; + bool sync:1; + bool waiting:1; + bool interrupted:1; + int err; +}; + +struct kdbus_reply *kdbus_reply_new(struct kdbus_conn *reply_src, + struct kdbus_conn *reply_dst, + const struct kdbus_msg *msg, + struct kdbus_name_entry *name_entry, + bool sync); + +struct kdbus_reply *kdbus_reply_ref(struct kdbus_reply *r); +struct kdbus_reply *kdbus_reply_unref(struct kdbus_reply *r); + +void kdbus_reply_link(struct kdbus_reply *r); +void kdbus_reply_unlink(struct kdbus_reply *r); + +struct kdbus_reply *kdbus_reply_find(struct kdbus_conn *replying, + struct kdbus_conn *reply_dst, + u64 cookie); + +void kdbus_sync_reply_wakeup(struct kdbus_reply *reply, int err); +void kdbus_reply_list_scan_work(struct work_struct *work); + +#endif /* __KDBUS_REPLY_H */ diff --git a/include/linux/kdbus/util.h b/include/linux/kdbus/util.h new file mode 100644 index 0000000..740b198 --- /dev/null +++ b/include/linux/kdbus/util.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2013-2015 Kay Sievers + * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> + * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> + * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> + * Copyright (C) 2013-2015 Linux Foundation + * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> + * + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef __KDBUS_UTIL_H +#define __KDBUS_UTIL_H + +#include <linux/dcache.h> +#include <linux/ioctl.h> + +#include <uapi/linux/kdbus.h> + +/* all exported addresses are 64 bit */ +#define KDBUS_PTR(addr) ((void __user *)(uintptr_t)(addr)) + +/* all exported sizes are 64 bit and data aligned to 64 bit */ +#define KDBUS_ALIGN8(s) ALIGN((s), 8) +#define KDBUS_IS_ALIGNED8(s) (IS_ALIGNED(s, 8)) + +/** + * kdbus_member_set_user - write a structure member to user memory + * @_s: Variable to copy from + * @_b: Buffer to write to + * @_t: Structure type + * @_m: Member name in the passed structure + * + * Return: the result of copy_to_user() + */ +#define kdbus_member_set_user(_s, _b, _t, _m) \ +({ \ + u64 __user *_sz = \ + (void __user *)((u8 __user *)(_b) + offsetof(_t, _m)); \ + copy_to_user(_sz, _s, sizeof(((_t *)0)->_m)); \ +}) + +/** + * kdbus_strhash - calculate a hash + * @str: String + * + * Return: hash value + */ +static inline unsigned int kdbus_strhash(const char *str) +{ + unsigned long hash = init_name_hash(); + + while (*str) + hash = partial_name_hash(*str++, hash); + + return end_name_hash(hash); +} + +int kdbus_verify_uid_prefix(const char *name, struct user_namespace *user_ns, + kuid_t kuid); +int kdbus_sanitize_attach_flags(u64 flags, u64 *attach_flags); + +int kdbus_copy_from_user(void *dest, void __user *user_ptr, size_t size); +void *kdbus_memdup_user(void __user *user_ptr, size_t sz_min, size_t sz_max); + +struct kvec; + +void kdbus_kvec_set(struct kvec *kvec, void *src, size_t len, u64 *total_len); +size_t kdbus_kvec_pad(struct kvec *kvec, u64 *len); + +#endif diff --git a/ipc/kdbus/Makefile b/ipc/kdbus/Makefile index 7ee9271..6e194cd 100644 --- a/ipc/kdbus/Makefile +++ b/ipc/kdbus/Makefile @@ -20,3 +20,5 @@ kdbus-y := \ util.o obj-$(CONFIG_KDBUS) += kdbus.o + +ccflags-$(CONFIG_KDBUS) += -Iinclude/linux/kdbus diff --git a/ipc/kdbus/bus.h b/ipc/kdbus/bus.h deleted file mode 100644 index 5bea5ef..0000000 --- a/ipc/kdbus/bus.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUS_BUS_H -#define __KDBUS_BUS_H - -#include <linux/hashtable.h> -#include <linux/list.h> -#include <linux/mutex.h> -#include <linux/rwsem.h> -#include <linux/spinlock.h> -#include <uapi/linux/kdbus.h> - -#include "metadata.h" -#include "names.h" -#include "node.h" -#include "policy.h" - -struct kdbus_conn; -struct kdbus_domain; -struct kdbus_kmsg; -struct kdbus_user; - -/** - * struct kdbus_bus - bus in a domain - * @node: kdbus_node - * @id: ID of this bus in the domain - * @bus_flags: Simple pass-through flags from userspace to userspace - * @attach_flags_req: KDBUS_ATTACH_* flags required by connecting peers - * @attach_flags_owner: KDBUS_ATTACH_* flags of bus creator that other - * connections can see or query - * @id128: Unique random 128 bit ID of this bus - * @bloom: Bloom parameters - * @domain: Domain of this bus - * @creator: Creator of the bus - * @creator_meta: Meta information about the bus creator - * @policy_db: Policy database for this bus - * @name_registry: Name registry of this bus - * @conn_rwlock: Read/Write lock for all lists of child connections - * @conn_hash: Map of connection IDs - * @monitors_list: Connections that monitor this bus - * @notify_list: List of pending kernel-generated messages - * @notify_lock: Notification list lock - * @notify_flush_lock: Notification flushing lock - */ -struct kdbus_bus { - struct kdbus_node node; - - /* static */ - u64 id; - u64 bus_flags; - u64 attach_flags_req; - u64 attach_flags_owner; - u8 id128[16]; - struct kdbus_bloom_parameter bloom; - struct kdbus_domain *domain; - struct kdbus_user *creator; - struct kdbus_meta_proc *creator_meta; - - /* protected by own locks */ - struct kdbus_policy_db policy_db; - struct kdbus_name_registry *name_registry; - - /* protected by conn_rwlock */ - struct rw_semaphore conn_rwlock; - DECLARE_HASHTABLE(conn_hash, 8); - struct list_head monitors_list; - - /* protected by notify_lock */ - struct list_head notify_list; - spinlock_t notify_lock; - struct mutex notify_flush_lock; -}; - -struct kdbus_bus *kdbus_bus_ref(struct kdbus_bus *bus); -struct kdbus_bus *kdbus_bus_unref(struct kdbus_bus *bus); - -struct kdbus_conn *kdbus_bus_find_conn_by_id(struct kdbus_bus *bus, u64 id); -void kdbus_bus_broadcast(struct kdbus_bus *bus, - struct kdbus_conn *conn_src, - struct kdbus_kmsg *kmsg); -void kdbus_bus_eavesdrop(struct kdbus_bus *bus, - struct kdbus_conn *conn_src, - struct kdbus_kmsg *kmsg); - -struct kdbus_bus *kdbus_cmd_bus_make(struct kdbus_domain *domain, - void __user *argp); -int kdbus_cmd_bus_creator_info(struct kdbus_conn *conn, void __user *argp); - -#endif diff --git a/ipc/kdbus/connection.h b/ipc/kdbus/connection.h deleted file mode 100644 index d1ffe90..0000000 --- a/ipc/kdbus/connection.h +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * Copyright (C) 2014-2015 Djalal Harouni - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUS_CONNECTION_H -#define __KDBUS_CONNECTION_H - -#include <linux/atomic.h> -#include <linux/kref.h> -#include <linux/lockdep.h> -#include <linux/path.h> - -#include "limits.h" -#include "metadata.h" -#include "pool.h" -#include "queue.h" -#include "util.h" - -#define KDBUS_HELLO_SPECIAL_CONN (KDBUS_HELLO_ACTIVATOR | \ - KDBUS_HELLO_POLICY_HOLDER | \ - KDBUS_HELLO_MONITOR) - -struct kdbus_quota; -struct kdbus_kmsg; - -/** - * struct kdbus_conn - connection to a bus - * @kref: Reference count - * @active: Active references to the connection - * @id: Connection ID - * @flags: KDBUS_HELLO_* flags - * @attach_flags_send: KDBUS_ATTACH_* flags for sending - * @attach_flags_recv: KDBUS_ATTACH_* flags for receiving - * @description: Human-readable connection description, used for - * debugging. This field is only set when the - * connection is created. - * @ep: The endpoint this connection belongs to - * @lock: Connection data lock - * @hentry: Entry in ID <-> connection map - * @ep_entry: Entry in endpoint - * @monitor_entry: Entry in monitor, if the connection is a monitor - * @reply_list: List of connections this connection should - * reply to - * @work: Delayed work to handle timeouts - * activator for - * @match_db: Subscription filter to broadcast messages - * @meta: Active connection creator's metadata/credentials, - * either from the handle or from HELLO - * @pool: The user's buffer to receive messages - * @user: Owner of the connection - * @cred: The credentials of the connection at creation time - * @name_count: Number of owned well-known names - * @request_count: Number of pending requests issued by this - * connection that are waiting for replies from - * other peers - * @lost_count: Number of lost broadcast messages - * @wait: Wake up this endpoint - * @queue: The message queue associated with this connection - * @quota: Array of per-user quota indexed by user->id - * @n_quota: Number of elements in quota array - * @activator_of: Well-known name entry this connection acts as an - * @names_list: List of well-known names - * @names_queue_list: Well-known names this connection waits for - * @privileged: Whether this connection is privileged on the bus - * @faked_meta: Whether the metadata was faked on HELLO - */ -struct kdbus_conn { - struct kref kref; - atomic_t active; -#ifdef CONFIG_DEBUG_LOCK_ALLOC - struct lockdep_map dep_map; -#endif - u64 id; - u64 flags; - atomic64_t attach_flags_send; - atomic64_t attach_flags_recv; - const char *description; - struct kdbus_ep *ep; - struct mutex lock; - struct hlist_node hentry; - struct list_head ep_entry; - struct list_head monitor_entry; - struct list_head reply_list; - struct delayed_work work; - struct kdbus_match_db *match_db; - struct kdbus_meta_proc *meta; - struct kdbus_pool *pool; - struct kdbus_user *user; - const struct cred *cred; - atomic_t name_count; - atomic_t request_count; - atomic_t lost_count; - wait_queue_head_t wait; - struct kdbus_queue queue; - - struct kdbus_quota *quota; - unsigned int n_quota; - - /* protected by registry->rwlock */ - struct kdbus_name_entry *activator_of; - struct list_head names_list; - struct list_head names_queue_list; - - bool privileged:1; - bool faked_meta:1; -}; - -struct kdbus_conn *kdbus_conn_ref(struct kdbus_conn *conn); -struct kdbus_conn *kdbus_conn_unref(struct kdbus_conn *conn); -bool kdbus_conn_active(const struct kdbus_conn *conn); -int kdbus_conn_acquire(struct kdbus_conn *conn); -void kdbus_conn_release(struct kdbus_conn *conn); -int kdbus_conn_disconnect(struct kdbus_conn *conn, bool ensure_queue_empty); -bool kdbus_conn_has_name(struct kdbus_conn *conn, const char *name); -int kdbus_conn_quota_inc(struct kdbus_conn *c, struct kdbus_user *u, - size_t memory, size_t fds); -void kdbus_conn_quota_dec(struct kdbus_conn *c, struct kdbus_user *u, - size_t memory, size_t fds); -void kdbus_conn_lost_message(struct kdbus_conn *c); -int kdbus_conn_entry_insert(struct kdbus_conn *conn_src, - struct kdbus_conn *conn_dst, - const struct kdbus_kmsg *kmsg, - struct kdbus_reply *reply); -void kdbus_conn_move_messages(struct kdbus_conn *conn_dst, - struct kdbus_conn *conn_src, - u64 name_id); - -/* policy */ -bool kdbus_conn_policy_own_name(struct kdbus_conn *conn, - const struct cred *conn_creds, - const char *name); -bool kdbus_conn_policy_talk(struct kdbus_conn *conn, - const struct cred *conn_creds, - struct kdbus_conn *to); -bool kdbus_conn_policy_see_name_unlocked(struct kdbus_conn *conn, - const struct cred *curr_creds, - const char *name); -bool kdbus_conn_policy_see_notification(struct kdbus_conn *conn, - const struct cred *curr_creds, - const struct kdbus_kmsg *kmsg); - -/* command dispatcher */ -struct kdbus_conn *kdbus_cmd_hello(struct kdbus_ep *ep, bool privileged, - void __user *argp); -int kdbus_cmd_byebye_unlocked(struct kdbus_conn *conn, void __user *argp); -int kdbus_cmd_conn_info(struct kdbus_conn *conn, void __user *argp); -int kdbus_cmd_update(struct kdbus_conn *conn, void __user *argp); -int kdbus_cmd_send(struct kdbus_conn *conn, struct file *f, void __user *argp); -int kdbus_cmd_recv(struct kdbus_conn *conn, void __user *argp); -int kdbus_cmd_free(struct kdbus_conn *conn, void __user *argp); - -/** - * kdbus_conn_is_ordinary() - Check if connection is ordinary - * @conn: The connection to check - * - * Return: Non-zero if the connection is an ordinary connection - */ -static inline int kdbus_conn_is_ordinary(const struct kdbus_conn *conn) -{ - return !(conn->flags & KDBUS_HELLO_SPECIAL_CONN); -} - -/** - * kdbus_conn_is_activator() - Check if connection is an activator - * @conn: The connection to check - * - * Return: Non-zero if the connection is an activator - */ -static inline int kdbus_conn_is_activator(const struct kdbus_conn *conn) -{ - return conn->flags & KDBUS_HELLO_ACTIVATOR; -} - -/** - * kdbus_conn_is_policy_holder() - Check if connection is a policy holder - * @conn: The connection to check - * - * Return: Non-zero if the connection is a policy holder - */ -static inline int kdbus_conn_is_policy_holder(const struct kdbus_conn *conn) -{ - return conn->flags & KDBUS_HELLO_POLICY_HOLDER; -} - -/** - * kdbus_conn_is_monitor() - Check if connection is a monitor - * @conn: The connection to check - * - * Return: Non-zero if the connection is a monitor - */ -static inline int kdbus_conn_is_monitor(const struct kdbus_conn *conn) -{ - return conn->flags & KDBUS_HELLO_MONITOR; -} - -/** - * kdbus_conn_lock2() - Lock two connections - * @a: connection A to lock or NULL - * @b: connection B to lock or NULL - * - * Lock two connections at once. As we need to have a stable locking order, we - * always lock the connection with lower memory address first. - */ -static inline void kdbus_conn_lock2(struct kdbus_conn *a, struct kdbus_conn *b) -{ - if (a < b) { - if (a) - mutex_lock(&a->lock); - if (b && b != a) - mutex_lock_nested(&b->lock, !!a); - } else { - if (b) - mutex_lock(&b->lock); - if (a && a != b) - mutex_lock_nested(&a->lock, !!b); - } -} - -/** - * kdbus_conn_unlock2() - Unlock two connections - * @a: connection A to unlock or NULL - * @b: connection B to unlock or NULL - * - * Unlock two connections at once. See kdbus_conn_lock2(). - */ -static inline void kdbus_conn_unlock2(struct kdbus_conn *a, - struct kdbus_conn *b) -{ - if (a) - mutex_unlock(&a->lock); - if (b && b != a) - mutex_unlock(&b->lock); -} - -/** - * kdbus_conn_assert_active() - lockdep assert on active lock - * @conn: connection that shall be active - * - * This verifies via lockdep that the caller holds an active reference to the - * given connection. - */ -static inline void kdbus_conn_assert_active(struct kdbus_conn *conn) -{ - lockdep_assert_held(conn); -} - -#endif diff --git a/ipc/kdbus/domain.h b/ipc/kdbus/domain.h deleted file mode 100644 index 447a2bd..0000000 --- a/ipc/kdbus/domain.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUS_DOMAIN_H -#define __KDBUS_DOMAIN_H - -#include <linux/fs.h> -#include <linux/idr.h> -#include <linux/kref.h> -#include <linux/user_namespace.h> - -#include "node.h" - -/** - * struct kdbus_domain - domain for buses - * @node: Underlying API node - * @lock: Domain data lock - * @last_id: Last used object id - * @user_idr: Set of all users indexed by UID - * @user_ida: Set of all users to compute small indices - * @user_namespace: User namespace, pinned at creation time - * @dentry: Root dentry of VFS mount (don't use outside of kdbusfs) - */ -struct kdbus_domain { - struct kdbus_node node; - struct mutex lock; - atomic64_t last_id; - struct idr user_idr; - struct ida user_ida; - struct user_namespace *user_namespace; - struct dentry *dentry; -}; - -/** - * struct kdbus_user - resource accounting for users - * @kref: Reference counter - * @domain: Domain of the user - * @id: Index of this user - * @uid: UID of the user - * @buses: Number of buses the user has created - * @connections: Number of connections the user has created - */ -struct kdbus_user { - struct kref kref; - struct kdbus_domain *domain; - unsigned int id; - kuid_t uid; - atomic_t buses; - atomic_t connections; -}; - -#define kdbus_domain_from_node(_node) \ - container_of((_node), struct kdbus_domain, node) - -struct kdbus_domain *kdbus_domain_new(unsigned int access); -struct kdbus_domain *kdbus_domain_ref(struct kdbus_domain *domain); -struct kdbus_domain *kdbus_domain_unref(struct kdbus_domain *domain); -int kdbus_domain_populate(struct kdbus_domain *domain, unsigned int access); - -#define KDBUS_USER_KERNEL_ID 0 /* ID 0 is reserved for kernel accounting */ - -struct kdbus_user *kdbus_user_lookup(struct kdbus_domain *domain, kuid_t uid); -struct kdbus_user *kdbus_user_ref(struct kdbus_user *u); -struct kdbus_user *kdbus_user_unref(struct kdbus_user *u); - -#endif diff --git a/ipc/kdbus/endpoint.h b/ipc/kdbus/endpoint.h deleted file mode 100644 index d31954b..0000000 --- a/ipc/kdbus/endpoint.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUS_ENDPOINT_H -#define __KDBUS_ENDPOINT_H - -#include <linux/list.h> -#include <linux/mutex.h> -#include <linux/uidgid.h> -#include "node.h" -#include "policy.h" - -struct kdbus_bus; -struct kdbus_user; - -/** - * struct kdbus_ep - enpoint to access a bus - * @node: The kdbus node - * @lock: Endpoint data lock - * @bus: Bus behind this endpoint - * @user: Custom enpoints account against an anonymous user - * @policy_db: Uploaded policy - * @conn_list: Connections of this endpoint - * - * An enpoint offers access to a bus; the default endpoint node name is "bus". - * Additional custom endpoints to the same bus can be created and they can - * carry their own policies/filters. - */ -struct kdbus_ep { - struct kdbus_node node; - struct mutex lock; - - /* static */ - struct kdbus_bus *bus; - struct kdbus_user *user; - - /* protected by own locks */ - struct kdbus_policy_db policy_db; - - /* protected by ep->lock */ - struct list_head conn_list; -}; - -#define kdbus_ep_from_node(_node) \ - container_of((_node), struct kdbus_ep, node) - -struct kdbus_ep *kdbus_ep_new(struct kdbus_bus *bus, const char *name, - unsigned int access, kuid_t uid, kgid_t gid, - bool policy); -struct kdbus_ep *kdbus_ep_ref(struct kdbus_ep *ep); -struct kdbus_ep *kdbus_ep_unref(struct kdbus_ep *ep); - -struct kdbus_ep *kdbus_cmd_ep_make(struct kdbus_bus *bus, void __user *argp); -int kdbus_cmd_ep_update(struct kdbus_ep *ep, void __user *argp); - -#endif diff --git a/ipc/kdbus/fs.h b/ipc/kdbus/fs.h deleted file mode 100644 index 62f7d6a..0000000 --- a/ipc/kdbus/fs.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUSFS_H -#define __KDBUSFS_H - -#include <linux/kernel.h> - -struct kdbus_node; - -int kdbus_fs_init(void); -void kdbus_fs_exit(void); -void kdbus_fs_flush(struct kdbus_node *node); - -#define kdbus_node_from_inode(_inode) \ - ((struct kdbus_node *)(_inode)->i_private) - -#endif diff --git a/ipc/kdbus/handle.h b/ipc/kdbus/handle.h deleted file mode 100644 index 93a372d..0000000 --- a/ipc/kdbus/handle.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUS_HANDLE_H -#define __KDBUS_HANDLE_H - -#include <linux/fs.h> -#include <uapi/linux/kdbus.h> - -extern const struct file_operations kdbus_handle_ops; - -/** - * kdbus_arg - information and state of a single ioctl command item - * @type: item type - * @item: set by the parser to the first found item of this type - * @multiple: whether multiple items of this type are allowed - * @mandatory: whether at least one item of this type is required - * - * This structure describes a single item in an ioctl command payload. The - * caller has to pre-fill the type and flags, the parser will then use this - * information to verify the ioctl payload. @item is set by the parser to point - * to the first occurrence of the item. - */ -struct kdbus_arg { - u64 type; - struct kdbus_item *item; - bool multiple : 1; - bool mandatory : 1; -}; - -/** - * kdbus_args - information and state of ioctl command parser - * @allowed_flags: set of flags this command supports - * @argc: number of items in @argv - * @argv: array of items this command supports - * @user: set by parser to user-space location of current command - * @cmd: set by parser to kernel copy of command payload - * @items: points to item array in @cmd - * @items_size: size of @items in bytes - * - * This structure is used to parse ioctl command payloads on each invocation. - * The ioctl handler has to pre-fill the flags and allowed items before passing - * the object to kdbus_args_parse(). The parser will copy the command payload - * into kernel-space and verify the correctness of the data. - */ -struct kdbus_args { - u64 allowed_flags; - size_t argc; - struct kdbus_arg *argv; - - struct kdbus_cmd __user *user; - struct kdbus_cmd *cmd; - - struct kdbus_item *items; - size_t items_size; -}; - -int __kdbus_args_parse(struct kdbus_args *args, void __user *argp, - size_t type_size, size_t items_offset, void **out); -int kdbus_args_clear(struct kdbus_args *args, int ret); - -#define kdbus_args_parse(_args, _argp, _v) \ - ({ \ - BUILD_BUG_ON(offsetof(typeof(**(_v)), size) != \ - offsetof(struct kdbus_cmd, size)); \ - BUILD_BUG_ON(offsetof(typeof(**(_v)), flags) != \ - offsetof(struct kdbus_cmd, flags)); \ - BUILD_BUG_ON(offsetof(typeof(**(_v)), return_flags) != \ - offsetof(struct kdbus_cmd, return_flags)); \ - __kdbus_args_parse((_args), (_argp), sizeof(**(_v)), \ - offsetof(typeof(**(_v)), items), \ - (void **)(_v)); \ - }) - -#endif diff --git a/ipc/kdbus/item.h b/ipc/kdbus/item.h deleted file mode 100644 index eeefd8b..0000000 --- a/ipc/kdbus/item.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUS_ITEM_H -#define __KDBUS_ITEM_H - -#include <linux/kernel.h> -#include <uapi/linux/kdbus.h> - -#include "util.h" - -/* generic access and iterators over a stream of items */ -#define KDBUS_ITEM_NEXT(_i) (typeof(_i))(((u8 *)_i) + KDBUS_ALIGN8((_i)->size)) -#define KDBUS_ITEMS_SIZE(_h, _is) ((_h)->size - offsetof(typeof(*_h), _is)) -#define KDBUS_ITEM_HEADER_SIZE offsetof(struct kdbus_item, data) -#define KDBUS_ITEM_SIZE(_s) KDBUS_ALIGN8(KDBUS_ITEM_HEADER_SIZE + (_s)) -#define KDBUS_ITEM_PAYLOAD_SIZE(_i) ((_i)->size - KDBUS_ITEM_HEADER_SIZE) - -#define KDBUS_ITEMS_FOREACH(_i, _is, _s) \ - for (_i = _is; \ - ((u8 *)(_i) < (u8 *)(_is) + (_s)) && \ - ((u8 *)(_i) >= (u8 *)(_is)); \ - _i = KDBUS_ITEM_NEXT(_i)) - -#define KDBUS_ITEM_VALID(_i, _is, _s) \ - ((_i)->size >= KDBUS_ITEM_HEADER_SIZE && \ - (u8 *)(_i) + (_i)->size > (u8 *)(_i) && \ - (u8 *)(_i) + (_i)->size <= (u8 *)(_is) + (_s) && \ - (u8 *)(_i) >= (u8 *)(_is)) - -#define KDBUS_ITEMS_END(_i, _is, _s) \ - ((u8 *)_i == ((u8 *)(_is) + KDBUS_ALIGN8(_s))) - -/** - * struct kdbus_item_header - Describes the fix part of an item - * @size: The total size of the item - * @type: The item type, one of KDBUS_ITEM_* - */ -struct kdbus_item_header { - u64 size; - u64 type; -}; - -int kdbus_item_validate_name(const struct kdbus_item *item); -int kdbus_item_validate(const struct kdbus_item *item); -int kdbus_items_validate(const struct kdbus_item *items, size_t items_size); -const char *kdbus_items_get_str(const struct kdbus_item *items, - size_t items_size, - unsigned int item_type); -struct kdbus_item *kdbus_item_set(struct kdbus_item *item, u64 type, - const void *data, size_t len); - -#endif diff --git a/ipc/kdbus/limits.h b/ipc/kdbus/limits.h deleted file mode 100644 index 6450f58..0000000 --- a/ipc/kdbus/limits.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUS_DEFAULTS_H -#define __KDBUS_DEFAULTS_H - -#include <linux/kernel.h> - -/* maximum size of message header and items */ -#define KDBUS_MSG_MAX_SIZE SZ_8K - -/* maximum number of message items */ -#define KDBUS_MSG_MAX_ITEMS 128 - -/* maximum number of memfd items per message */ -#define KDBUS_MSG_MAX_MEMFD_ITEMS 16 - -/* max size of ioctl command data */ -#define KDBUS_CMD_MAX_SIZE SZ_32K - -/* maximum number of inflight fds in a target queue per user */ -#define KDBUS_CONN_MAX_FDS_PER_USER 16 - -/* maximum message payload size */ -#define KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE SZ_2M - -/* maximum size of bloom bit field in bytes */ -#define KDBUS_BUS_BLOOM_MAX_SIZE SZ_4K - -/* maximum length of well-known bus name */ -#define KDBUS_NAME_MAX_LEN 255 - -/* maximum length of bus, domain, ep name */ -#define KDBUS_SYSNAME_MAX_LEN 63 - -/* maximum number of matches per connection */ -#define KDBUS_MATCH_MAX 256 - -/* maximum number of queued messages from the same individual user */ -#define KDBUS_CONN_MAX_MSGS 256 - -/* maximum number of well-known names per connection */ -#define KDBUS_CONN_MAX_NAMES 256 - -/* maximum number of queued requests waiting for a reply */ -#define KDBUS_CONN_MAX_REQUESTS_PENDING 128 - -/* maximum number of connections per user in one domain */ -#define KDBUS_USER_MAX_CONN 1024 - -/* maximum number of buses per user in one domain */ -#define KDBUS_USER_MAX_BUSES 16 - -#endif diff --git a/ipc/kdbus/match.h b/ipc/kdbus/match.h deleted file mode 100644 index ea42929..0000000 --- a/ipc/kdbus/match.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUS_MATCH_H -#define __KDBUS_MATCH_H - -struct kdbus_conn; -struct kdbus_kmsg; -struct kdbus_match_db; - -struct kdbus_match_db *kdbus_match_db_new(void); -void kdbus_match_db_free(struct kdbus_match_db *db); -int kdbus_match_db_add(struct kdbus_conn *conn, - struct kdbus_cmd_match *cmd); -int kdbus_match_db_remove(struct kdbus_conn *conn, - struct kdbus_cmd_match *cmd); -bool kdbus_match_db_match_kmsg(struct kdbus_match_db *db, - struct kdbus_conn *conn_src, - struct kdbus_kmsg *kmsg); - -int kdbus_cmd_match_add(struct kdbus_conn *conn, void __user *argp); -int kdbus_cmd_match_remove(struct kdbus_conn *conn, void __user *argp); - -#endif diff --git a/ipc/kdbus/message.h b/ipc/kdbus/message.h deleted file mode 100644 index af47758..0000000 --- a/ipc/kdbus/message.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUS_MESSAGE_H -#define __KDBUS_MESSAGE_H - -#include "util.h" -#include "metadata.h" - -/** - * enum kdbus_msg_data_type - Type of kdbus_msg_data payloads - * @KDBUS_MSG_DATA_VEC: Data vector provided by user-space - * @KDBUS_MSG_DATA_MEMFD: Memfd payload - */ -enum kdbus_msg_data_type { - KDBUS_MSG_DATA_VEC, - KDBUS_MSG_DATA_MEMFD, -}; - -/** - * struct kdbus_msg_data - Data payload as stored by messages - * @type: Type of payload (KDBUS_MSG_DATA_*) - * @size: Size of the described payload - * @off: The offset, relative to the vec slice - * @start: Offset inside the memfd - * @file: Backing file referenced by the memfd - */ -struct kdbus_msg_data { - unsigned int type; - u64 size; - - union { - struct { - u64 off; - } vec; - struct { - u64 start; - struct file *file; - } memfd; - }; -}; - -/** - * struct kdbus_kmsg_resources - resources of a message - * @kref: Reference counter - * @dst_name: Short-cut to msg for faster lookup - * @fds: Array of file descriptors to pass - * @fds_count: Number of file descriptors to pass - * @data: Array of data payloads - * @vec_count: Number of VEC entries - * @memfd_count: Number of MEMFD entries in @data - * @data_count: Sum of @vec_count + @memfd_count - */ -struct kdbus_msg_resources { - struct kref kref; - const char *dst_name; - - struct file **fds; - unsigned int fds_count; - - struct kdbus_msg_data *data; - size_t vec_count; - size_t memfd_count; - size_t data_count; -}; - -struct kdbus_msg_resources * -kdbus_msg_resources_ref(struct kdbus_msg_resources *r); -struct kdbus_msg_resources * -kdbus_msg_resources_unref(struct kdbus_msg_resources *r); - -/** - * struct kdbus_kmsg - internal message handling data - * @seq: Domain-global message sequence number - * @notify_type: Short-cut for faster lookup - * @notify_old_id: Short-cut for faster lookup - * @notify_new_id: Short-cut for faster lookup - * @notify_name: Short-cut for faster lookup - * @dst_name_id: Short-cut to msg for faster lookup - * @bloom_filter: Bloom filter to match message properties - * @bloom_generation: Generation of bloom element set - * @notify_entry: List of kernel-generated notifications - * @iov: Array of iovec, describing the payload to copy - * @iov_count: Number of array members in @iov - * @pool_size: Overall size of inlined data referenced by @iov - * @proc_meta: Appended SCM-like metadata of the sending process - * @conn_meta: Appended SCM-like metadata of the sending connection - * @res: Message resources - * @msg: Message from or to userspace - */ -struct kdbus_kmsg { - u64 seq; - u64 notify_type; - u64 notify_old_id; - u64 notify_new_id; - const char *notify_name; - - u64 dst_name_id; - const struct kdbus_bloom_filter *bloom_filter; - u64 bloom_generation; - struct list_head notify_entry; - - struct iovec *iov; - size_t iov_count; - u64 pool_size; - - struct kdbus_meta_proc *proc_meta; - struct kdbus_meta_conn *conn_meta; - struct kdbus_msg_resources *res; - - /* variable size, must be the last member */ - struct kdbus_msg msg; -}; - -struct kdbus_bus; -struct kdbus_conn; - -struct kdbus_kmsg *kdbus_kmsg_new(struct kdbus_bus *bus, size_t extra_size); -struct kdbus_kmsg *kdbus_kmsg_new_from_cmd(struct kdbus_conn *conn, - struct kdbus_cmd_send *cmd_send); -void kdbus_kmsg_free(struct kdbus_kmsg *kmsg); - -#endif diff --git a/ipc/kdbus/metadata.h b/ipc/kdbus/metadata.h deleted file mode 100644 index 42c942b..0000000 --- a/ipc/kdbus/metadata.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * Copyright (C) 2014-2015 Djalal Harouni - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUS_METADATA_H -#define __KDBUS_METADATA_H - -#include <linux/kernel.h> - -struct kdbus_conn; -struct kdbus_kmsg; -struct kdbus_pool_slice; - -struct kdbus_meta_proc; -struct kdbus_meta_conn; - -extern unsigned long long kdbus_meta_attach_mask; - -struct kdbus_meta_proc *kdbus_meta_proc_new(void); -struct kdbus_meta_proc *kdbus_meta_proc_ref(struct kdbus_meta_proc *mp); -struct kdbus_meta_proc *kdbus_meta_proc_unref(struct kdbus_meta_proc *mp); -int kdbus_meta_proc_collect(struct kdbus_meta_proc *mp, u64 what); -int kdbus_meta_proc_fake(struct kdbus_meta_proc *mp, - const struct kdbus_creds *creds, - const struct kdbus_pids *pids, - const char *seclabel); - -struct kdbus_meta_conn *kdbus_meta_conn_new(void); -struct kdbus_meta_conn *kdbus_meta_conn_ref(struct kdbus_meta_conn *mc); -struct kdbus_meta_conn *kdbus_meta_conn_unref(struct kdbus_meta_conn *mc); -int kdbus_meta_conn_collect(struct kdbus_meta_conn *mc, - struct kdbus_kmsg *kmsg, - struct kdbus_conn *conn, - u64 what); - -int kdbus_meta_export_prepare(struct kdbus_meta_proc *mp, - struct kdbus_meta_conn *mc, - u64 *mask, size_t *sz); -int kdbus_meta_export(struct kdbus_meta_proc *mp, - struct kdbus_meta_conn *mc, - u64 mask, - struct kdbus_pool_slice *slice, - off_t offset, size_t *real_size); -u64 kdbus_meta_calc_attach_flags(const struct kdbus_conn *sender, - const struct kdbus_conn *receiver); - -#endif diff --git a/ipc/kdbus/names.h b/ipc/kdbus/names.h deleted file mode 100644 index 3dd2589..0000000 --- a/ipc/kdbus/names.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUS_NAMES_H -#define __KDBUS_NAMES_H - -#include <linux/hashtable.h> -#include <linux/rwsem.h> - -/** - * struct kdbus_name_registry - names registered for a bus - * @entries_hash: Map of entries - * @lock: Registry data lock - * @name_seq_last: Last used sequence number to assign to a name entry - */ -struct kdbus_name_registry { - DECLARE_HASHTABLE(entries_hash, 8); - struct rw_semaphore rwlock; - u64 name_seq_last; -}; - -/** - * struct kdbus_name_entry - well-know name entry - * @name_id: Sequence number of name entry to be able to uniquely - * identify a name over its registration lifetime - * @flags: KDBUS_NAME_* flags - * @conn: Connection owning the name - * @activator: Connection of the activator queuing incoming messages - * @queue: List of queued connections - * @conn_entry: Entry in connection - * @hentry: Entry in registry map - * @name: The well-known name - */ -struct kdbus_name_entry { - u64 name_id; - u64 flags; - struct kdbus_conn *conn; - struct kdbus_conn *activator; - struct list_head queue; - struct list_head conn_entry; - struct hlist_node hentry; - char name[]; -}; - -bool kdbus_name_is_valid(const char *p, bool allow_wildcard); - -struct kdbus_name_registry *kdbus_name_registry_new(void); -void kdbus_name_registry_free(struct kdbus_name_registry *reg); - -struct kdbus_name_entry * -kdbus_name_lookup_unlocked(struct kdbus_name_registry *reg, const char *name); - -int kdbus_name_acquire(struct kdbus_name_registry *reg, - struct kdbus_conn *conn, const char *name, - u64 flags, u64 *return_flags); -void kdbus_name_release_all(struct kdbus_name_registry *reg, - struct kdbus_conn *conn); - -int kdbus_cmd_name_acquire(struct kdbus_conn *conn, void __user *argp); -int kdbus_cmd_name_release(struct kdbus_conn *conn, void __user *argp); -int kdbus_cmd_list(struct kdbus_conn *conn, void __user *argp); - -#endif diff --git a/ipc/kdbus/node.h b/ipc/kdbus/node.h deleted file mode 100644 index be125ce..0000000 --- a/ipc/kdbus/node.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUS_NODE_H -#define __KDBUS_NODE_H - -#include <linux/atomic.h> -#include <linux/kernel.h> -#include <linux/mutex.h> -#include <linux/wait.h> - -struct kdbus_node; - -enum kdbus_node_type { - KDBUS_NODE_DOMAIN, - KDBUS_NODE_CONTROL, - KDBUS_NODE_BUS, - KDBUS_NODE_ENDPOINT, -}; - -typedef void (*kdbus_node_free_t) (struct kdbus_node *node); -typedef void (*kdbus_node_release_t) (struct kdbus_node *node, bool was_active); - -struct kdbus_node { - atomic_t refcnt; - atomic_t active; - wait_queue_head_t waitq; - - /* static members */ - unsigned int type; - kdbus_node_free_t free_cb; - kdbus_node_release_t release_cb; - umode_t mode; - kuid_t uid; - kgid_t gid; - - /* valid once linked */ - char *name; - unsigned int hash; - unsigned int id; - struct kdbus_node *parent; /* may be NULL */ - - /* valid iff active */ - struct mutex lock; - struct rb_node rb; - struct rb_root children; -}; - -#define kdbus_node_from_rb(_node) rb_entry((_node), struct kdbus_node, rb) - -void kdbus_node_init(struct kdbus_node *node, unsigned int type); - -int kdbus_node_link(struct kdbus_node *node, struct kdbus_node *parent, - const char *name); - -struct kdbus_node *kdbus_node_ref(struct kdbus_node *node); -struct kdbus_node *kdbus_node_unref(struct kdbus_node *node); - -bool kdbus_node_is_active(struct kdbus_node *node); -bool kdbus_node_is_deactivated(struct kdbus_node *node); -bool kdbus_node_activate(struct kdbus_node *node); -void kdbus_node_deactivate(struct kdbus_node *node); - -bool kdbus_node_acquire(struct kdbus_node *node); -void kdbus_node_release(struct kdbus_node *node); - -struct kdbus_node *kdbus_node_find_child(struct kdbus_node *node, - const char *name); -struct kdbus_node *kdbus_node_find_closest(struct kdbus_node *node, - unsigned int hash); -struct kdbus_node *kdbus_node_next_child(struct kdbus_node *node, - struct kdbus_node *prev); - -#endif diff --git a/ipc/kdbus/notify.h b/ipc/kdbus/notify.h deleted file mode 100644 index 03df464..0000000 --- a/ipc/kdbus/notify.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUS_NOTIFY_H -#define __KDBUS_NOTIFY_H - -struct kdbus_bus; - -int kdbus_notify_id_change(struct kdbus_bus *bus, u64 type, u64 id, u64 flags); -int kdbus_notify_reply_timeout(struct kdbus_bus *bus, u64 id, u64 cookie); -int kdbus_notify_reply_dead(struct kdbus_bus *bus, u64 id, u64 cookie); -int kdbus_notify_name_change(struct kdbus_bus *bus, u64 type, - u64 old_id, u64 new_id, - u64 old_flags, u64 new_flags, - const char *name); -void kdbus_notify_flush(struct kdbus_bus *bus); -void kdbus_notify_free(struct kdbus_bus *bus); - -#endif diff --git a/ipc/kdbus/policy.h b/ipc/kdbus/policy.h deleted file mode 100644 index 15dd7bc..0000000 --- a/ipc/kdbus/policy.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUS_POLICY_H -#define __KDBUS_POLICY_H - -#include <linux/hashtable.h> -#include <linux/rwsem.h> - -struct kdbus_conn; -struct kdbus_item; - -/** - * struct kdbus_policy_db - policy database - * @entries_hash: Hashtable of entries - * @entries_rwlock: Mutex to protect the database's access entries - */ -struct kdbus_policy_db { - DECLARE_HASHTABLE(entries_hash, 6); - struct rw_semaphore entries_rwlock; -}; - -void kdbus_policy_db_init(struct kdbus_policy_db *db); -void kdbus_policy_db_clear(struct kdbus_policy_db *db); - -int kdbus_policy_query_unlocked(struct kdbus_policy_db *db, - const struct cred *cred, const char *name, - unsigned int hash); -int kdbus_policy_query(struct kdbus_policy_db *db, const struct cred *cred, - const char *name, unsigned int hash); - -void kdbus_policy_remove_owner(struct kdbus_policy_db *db, - const void *owner); -int kdbus_policy_set(struct kdbus_policy_db *db, - const struct kdbus_item *items, - size_t items_size, - size_t max_policies, - bool allow_wildcards, - const void *owner); - -#endif diff --git a/ipc/kdbus/pool.h b/ipc/kdbus/pool.h deleted file mode 100644 index a903821..0000000 --- a/ipc/kdbus/pool.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUS_POOL_H -#define __KDBUS_POOL_H - -#include <linux/uio.h> - -struct kdbus_pool; -struct kdbus_pool_slice; - -struct kdbus_pool *kdbus_pool_new(const char *name, size_t size); -void kdbus_pool_free(struct kdbus_pool *pool); -void kdbus_pool_accounted(struct kdbus_pool *pool, size_t *size, size_t *acc); -int kdbus_pool_mmap(const struct kdbus_pool *pool, struct vm_area_struct *vma); -int kdbus_pool_release_offset(struct kdbus_pool *pool, size_t off); -void kdbus_pool_publish_empty(struct kdbus_pool *pool, u64 *off, u64 *size); - -struct kdbus_pool_slice *kdbus_pool_slice_alloc(struct kdbus_pool *pool, - size_t size, bool accounted); -void kdbus_pool_slice_release(struct kdbus_pool_slice *slice); -void kdbus_pool_slice_publish(struct kdbus_pool_slice *slice, - u64 *out_offset, u64 *out_size); -off_t kdbus_pool_slice_offset(const struct kdbus_pool_slice *slice); -size_t kdbus_pool_slice_size(const struct kdbus_pool_slice *slice); -int kdbus_pool_slice_copy(const struct kdbus_pool_slice *slice_dst, - const struct kdbus_pool_slice *slice_src); -ssize_t kdbus_pool_slice_copy_kvec(const struct kdbus_pool_slice *slice, - loff_t off, struct kvec *kvec, - size_t kvec_count, size_t total_len); -ssize_t kdbus_pool_slice_copy_iovec(const struct kdbus_pool_slice *slice, - loff_t off, struct iovec *iov, - size_t iov_count, size_t total_len); - -#endif diff --git a/ipc/kdbus/queue.h b/ipc/kdbus/queue.h deleted file mode 100644 index 7f2db96..0000000 --- a/ipc/kdbus/queue.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUS_QUEUE_H -#define __KDBUS_QUEUE_H - -struct kdbus_user; - -/** - * struct kdbus_queue - a connection's message queue - * @msg_list: List head for kdbus_queue_entry objects - * @msg_prio_queue: RB tree root for messages, sorted by priority - * @msg_prio_highest: Link to the RB node referencing the message with the - * highest priority in the tree. - */ -struct kdbus_queue { - struct list_head msg_list; - struct rb_root msg_prio_queue; - struct rb_node *msg_prio_highest; -}; - -/** - * struct kdbus_queue_entry - messages waiting to be read - * @entry: Entry in the connection's list - * @prio_node: Entry in the priority queue tree - * @prio_entry: Queue tree node entry in the list of one priority - * @slice: Slice in the receiver's pool for the message - * @attach_flags: Attach flags used during slice allocation - * @meta_offset: Offset of first metadata item in slice - * @fds_offset: Offset of FD item in slice - * @memfd_offset: Array of slice-offsets for all memfd items - * @priority: Message priority - * @dst_name_id: The sequence number of the name this message is - * addressed to, 0 for messages sent to an ID - * @msg_res: Message resources - * @proc_meta: Process metadata, captured at message arrival - * @conn_meta: Connection metadata, captured at message arrival - * @reply: The reply block if a reply to this message is expected - * @user: User used for accounting - */ -struct kdbus_queue_entry { - struct list_head entry; - struct rb_node prio_node; - struct list_head prio_entry; - - struct kdbus_pool_slice *slice; - - u64 attach_flags; - size_t meta_offset; - size_t fds_offset; - size_t *memfd_offset; - - s64 priority; - u64 dst_name_id; - - struct kdbus_msg_resources *msg_res; - struct kdbus_meta_proc *proc_meta; - struct kdbus_meta_conn *conn_meta; - struct kdbus_reply *reply; - struct kdbus_conn *conn; - struct kdbus_user *user; -}; - -struct kdbus_kmsg; - -void kdbus_queue_init(struct kdbus_queue *queue); -struct kdbus_queue_entry *kdbus_queue_peek(struct kdbus_queue *queue, - s64 priority, bool use_priority); - -struct kdbus_queue_entry *kdbus_queue_entry_new(struct kdbus_conn *conn_dst, - const struct kdbus_kmsg *kmsg, - struct kdbus_user *user); -void kdbus_queue_entry_free(struct kdbus_queue_entry *entry); -int kdbus_queue_entry_install(struct kdbus_queue_entry *entry, - u64 *return_flags, bool install_fds); -void kdbus_queue_entry_enqueue(struct kdbus_queue_entry *entry, - struct kdbus_reply *reply); -int kdbus_queue_entry_move(struct kdbus_queue_entry *entry, - struct kdbus_conn *dst); - -#endif /* __KDBUS_QUEUE_H */ diff --git a/ipc/kdbus/reply.h b/ipc/kdbus/reply.h deleted file mode 100644 index 68d5232..0000000 --- a/ipc/kdbus/reply.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUS_REPLY_H -#define __KDBUS_REPLY_H - -/** - * struct kdbus_reply - an entry of kdbus_conn's list of replies - * @kref: Ref-count of this object - * @entry: The entry of the connection's reply_list - * @reply_src: The connection the reply will be sent from - * @reply_dst: The connection the reply will be sent to - * @queue_entry: The queue entry item that is prepared by the replying - * connection - * @deadline_ns: The deadline of the reply, in nanoseconds - * @cookie: The cookie of the requesting message - * @name_id: ID of the well-known name the original msg was sent to - * @sync: The reply block is waiting for synchronous I/O - * @waiting: The condition to synchronously wait for - * @interrupted: The sync reply was left in an interrupted state - * @err: The error code for the synchronous reply - */ -struct kdbus_reply { - struct kref kref; - struct list_head entry; - struct kdbus_conn *reply_src; - struct kdbus_conn *reply_dst; - struct kdbus_queue_entry *queue_entry; - u64 deadline_ns; - u64 cookie; - u64 name_id; - bool sync:1; - bool waiting:1; - bool interrupted:1; - int err; -}; - -struct kdbus_reply *kdbus_reply_new(struct kdbus_conn *reply_src, - struct kdbus_conn *reply_dst, - const struct kdbus_msg *msg, - struct kdbus_name_entry *name_entry, - bool sync); - -struct kdbus_reply *kdbus_reply_ref(struct kdbus_reply *r); -struct kdbus_reply *kdbus_reply_unref(struct kdbus_reply *r); - -void kdbus_reply_link(struct kdbus_reply *r); -void kdbus_reply_unlink(struct kdbus_reply *r); - -struct kdbus_reply *kdbus_reply_find(struct kdbus_conn *replying, - struct kdbus_conn *reply_dst, - u64 cookie); - -void kdbus_sync_reply_wakeup(struct kdbus_reply *reply, int err); -void kdbus_reply_list_scan_work(struct work_struct *work); - -#endif /* __KDBUS_REPLY_H */ diff --git a/ipc/kdbus/util.h b/ipc/kdbus/util.h deleted file mode 100644 index 740b198..0000000 --- a/ipc/kdbus/util.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2013-2015 Kay Sievers - * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org> - * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com> - * Copyright (C) 2013-2015 Linux Foundation - * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org> - * - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef __KDBUS_UTIL_H -#define __KDBUS_UTIL_H - -#include <linux/dcache.h> -#include <linux/ioctl.h> - -#include <uapi/linux/kdbus.h> - -/* all exported addresses are 64 bit */ -#define KDBUS_PTR(addr) ((void __user *)(uintptr_t)(addr)) - -/* all exported sizes are 64 bit and data aligned to 64 bit */ -#define KDBUS_ALIGN8(s) ALIGN((s), 8) -#define KDBUS_IS_ALIGNED8(s) (IS_ALIGNED(s, 8)) - -/** - * kdbus_member_set_user - write a structure member to user memory - * @_s: Variable to copy from - * @_b: Buffer to write to - * @_t: Structure type - * @_m: Member name in the passed structure - * - * Return: the result of copy_to_user() - */ -#define kdbus_member_set_user(_s, _b, _t, _m) \ -({ \ - u64 __user *_sz = \ - (void __user *)((u8 __user *)(_b) + offsetof(_t, _m)); \ - copy_to_user(_sz, _s, sizeof(((_t *)0)->_m)); \ -}) - -/** - * kdbus_strhash - calculate a hash - * @str: String - * - * Return: hash value - */ -static inline unsigned int kdbus_strhash(const char *str) -{ - unsigned long hash = init_name_hash(); - - while (*str) - hash = partial_name_hash(*str++, hash); - - return end_name_hash(hash); -} - -int kdbus_verify_uid_prefix(const char *name, struct user_namespace *user_ns, - kuid_t kuid); -int kdbus_sanitize_attach_flags(u64 flags, u64 *attach_flags); - -int kdbus_copy_from_user(void *dest, void __user *user_ptr, size_t size); -void *kdbus_memdup_user(void __user *user_ptr, size_t sz_min, size_t sz_max); - -struct kvec; - -void kdbus_kvec_set(struct kvec *kvec, void *src, size_t len, u64 *total_len); -size_t kdbus_kvec_pad(struct kvec *kvec, u64 *len); - -#endif -- 1.9.1
| |