summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKay Sievers <kay@vrfy.org>2013-12-03 17:22:56 +0100
committerKay Sievers <kay@vrfy.org>2013-12-03 17:22:56 +0100
commiteb378bd7f0c9291908b13ad42c5cc171c4809f28 (patch)
treec778ae7d3597f5ce68d3291801af9730d53b5639
parent4e5cf4dc21da61df6872123320be355dc162d1b7 (diff)
downloadkdbus-bus-eb378bd7f0c9291908b13ad42c5cc171c4809f28.tar.gz
kdbus-bus-eb378bd7f0c9291908b13ad42c5cc171c4809f28.tar.bz2
kdbus-bus-eb378bd7f0c9291908b13ad42c5cc171c4809f28.zip
endpoint: simplify creation logic
-rw-r--r--bus.h2
-rw-r--r--endpoint.c33
-rw-r--r--endpoint.h55
-rw-r--r--handle.c17
-rw-r--r--kdbus.txt2
5 files changed, 61 insertions, 48 deletions
diff --git a/bus.h b/bus.h
index 07ec0c3a5e4..60d9edd801e 100644
--- a/bus.h
+++ b/bus.h
@@ -18,7 +18,7 @@
#include "internal.h"
/**
- * kdbus_bus - bus instance
+ * kdbus_bus - bus in a namespace
* @kref reference count
* @disconnected invalidated data
* @uid_owner the uid of the owner of the bus
diff --git a/endpoint.c b/endpoint.c
index 9d758e15d76..cc7dc99a9ac 100644
--- a/endpoint.c
+++ b/endpoint.c
@@ -216,11 +216,13 @@ int kdbus_ep_remove(struct kdbus_ep *ep)
return 0;
}
-int kdbus_ep_kmake_user(void __user *buf, struct kdbus_cmd_ep_kmake **kmake)
+int kdbus_ep_make_user(void __user *buf,
+ struct kdbus_cmd_ep_make **make, char **name)
{
u64 size;
- struct kdbus_cmd_ep_kmake *km;
+ struct kdbus_cmd_ep_make *m;
const struct kdbus_item *item;
+ const char *n = NULL;
int ret;
if (kdbus_size_get_user(&size, buf, struct kdbus_cmd_ep_make))
@@ -229,25 +231,21 @@ int kdbus_ep_kmake_user(void __user *buf, struct kdbus_cmd_ep_kmake **kmake)
if (size < sizeof(struct kdbus_cmd_ep_make) || size > KDBUS_MAKE_MAX_SIZE)
return -EMSGSIZE;
- km = kmalloc(sizeof(struct kdbus_cmd_ep_kmake) + size, GFP_KERNEL);
- if (!km)
- return -ENOMEM;
-
- memset(km, 0, offsetof(struct kdbus_cmd_ep_kmake, make));
- if (copy_from_user(&km->make, buf, size)) {
- ret = -EFAULT;
+ m = memdup_user(buf, size);
+ if (IS_ERR(m)) {
+ ret = PTR_ERR(m);
goto exit;
}
- KDBUS_PART_FOREACH(item, &km->make, items) {
- if (!KDBUS_PART_VALID(item, &km->make)) {
+ KDBUS_PART_FOREACH(item, m, items) {
+ if (!KDBUS_PART_VALID(item, m)) {
ret = -EINVAL;
goto exit;
}
switch (item->type) {
case KDBUS_MAKE_NAME:
- if (km->name) {
+ if (n) {
ret = -EEXIST;
goto exit;
}
@@ -268,7 +266,7 @@ int kdbus_ep_kmake_user(void __user *buf, struct kdbus_cmd_ep_kmake **kmake)
goto exit;
}
- km->name = item->str;
+ n = item->str;
continue;
default:
@@ -277,18 +275,19 @@ int kdbus_ep_kmake_user(void __user *buf, struct kdbus_cmd_ep_kmake **kmake)
}
}
- if (!KDBUS_PART_END(item, &km->make))
+ if (!KDBUS_PART_END(item, m))
return -EINVAL;
- if (!km->name) {
+ if (!n) {
ret = -EBADMSG;
goto exit;
}
- *kmake = km;
+ *make = m;
+ *name = (char *)n;
return 0;
exit:
- kfree(km);
+ kfree(m);
return ret;
}
diff --git a/endpoint.h b/endpoint.h
index 5b52fc66c8d..1937a4e94b7 100644
--- a/endpoint.h
+++ b/endpoint.h
@@ -15,33 +15,45 @@
#include "internal.h"
/*
- * kdbus endpoint
- * - offers access to a bus, the default device node name is "bus"
- * - additional endpoints can carry a specific policy/filters
+ * kdbus endpoint - enpoint to access a bus
+ * @kref reference count
+ * @disconnected invalidated data
+ * @bus bus behind this endpoint
+ * @name name of the endpoint
+ * @id id of this endpoint on the bus
+ * @minor minor of this endpoint in the namespace major
+ * @dev device node of this endpoint
+ * @mode file mode of this endpoint device node
+ * @uid uid owning this endpoint
+ * @gid gid owning this endpoint
+ * @bus_entry bus' endpoints
+ * @wait wake up this endpoint
+ * @lock endpoint data lock
+ * @policy_db uploaded policy
+ * @policy_open default endpoint policy
+ *
+ * An enpoint offers access to a bus; the default device 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 kref kref; /* reference count */
- bool disconnected; /* invalidated data */
- struct kdbus_bus *bus; /* bus behind this endpoint */
- const char *name; /* name, prefixed with uid */
- u64 id; /* id of this endpoint on the bus */
- unsigned int minor; /* minor of this endpoint in the namespace major */
- struct device *dev; /* device node of this endpoint */
- umode_t mode; /* file mode of this endpoint device node */
- kuid_t uid; /* uid owning this endpoint */
- kgid_t gid; /* gid owning this endpoint */
- struct list_head bus_entry; /* bus' endpoints */
- wait_queue_head_t wait; /* wake up this endpoint */
+ struct kref kref;
+ bool disconnected;
+ struct kdbus_bus *bus;
+ const char *name;
+ u64 id;
+ unsigned int minor;
+ struct device *dev;
+ umode_t mode;
+ kuid_t uid;
+ kgid_t gid;
+ struct list_head bus_entry;
+ wait_queue_head_t wait;
struct mutex lock;
struct kdbus_policy_db *policy_db;
bool policy_open:1;
};
-struct kdbus_cmd_ep_kmake {
- const char *name;
- struct kdbus_cmd_ep_make make;
-};
-
struct kdbus_ep *kdbus_ep_ref(struct kdbus_ep *ep);
void kdbus_ep_unref(struct kdbus_ep *ep);
@@ -49,5 +61,6 @@ int kdbus_ep_new(struct kdbus_bus *bus, const char *name,
umode_t mode, kuid_t uid, kgid_t gid, bool policy);
int kdbus_ep_remove(struct kdbus_ep *ep);
void kdbus_ep_disconnect(struct kdbus_ep *ep);
-int kdbus_ep_kmake_user(void __user *buf, struct kdbus_cmd_ep_kmake **kmake);
+int kdbus_ep_make_user(void __user *buf,
+ struct kdbus_cmd_ep_make **make, char **name);
#endif
diff --git a/handle.c b/handle.c
index 846b7358237..5597e5a58ef 100644
--- a/handle.c
+++ b/handle.c
@@ -277,7 +277,7 @@ static long kdbus_handle_ioctl_ep(struct file *file, unsigned int cmd,
void __user *buf)
{
struct kdbus_handle *handle = file->private_data;
- struct kdbus_cmd_ep_kmake *kmake = NULL;
+ struct kdbus_cmd_ep_make *m = NULL;
struct kdbus_cmd_hello *hello = NULL;
long ret = 0;
@@ -285,31 +285,32 @@ static long kdbus_handle_ioctl_ep(struct file *file, unsigned int cmd,
case KDBUS_CMD_EP_MAKE: {
umode_t mode = 0;
kgid_t gid = KGIDT_INIT(0);
+ char *n;
if (!KDBUS_IS_ALIGNED8((uintptr_t)buf)) {
ret = -EFAULT;
break;
}
- ret = kdbus_ep_kmake_user(buf, &kmake);
+ ret = kdbus_ep_make_user(buf, &m, &n);
if (ret < 0)
break;
- if (!kdbus_check_flags(kmake->make.flags)) {
+ if (!kdbus_check_flags(m->flags)) {
ret = -ENOTSUPP;
break;
}
- if (kmake->make.flags & KDBUS_MAKE_ACCESS_WORLD) {
+ if (m->flags & KDBUS_MAKE_ACCESS_WORLD) {
mode = 0666;
- } else if (kmake->make.flags & KDBUS_MAKE_ACCESS_GROUP) {
+ } else if (m->flags & KDBUS_MAKE_ACCESS_GROUP) {
mode = 0660;
gid = current_fsgid();
}
- ret = kdbus_ep_new(handle->ep->bus, kmake->name, mode,
+ ret = kdbus_ep_new(handle->ep->bus, n, mode,
current_fsuid(), gid,
- kmake->make.flags & KDBUS_MAKE_POLICY_OPEN);
+ m->flags & KDBUS_MAKE_POLICY_OPEN);
handle->type = KDBUS_HANDLE_EP_OWNER;
break;
@@ -373,7 +374,7 @@ static long kdbus_handle_ioctl_ep(struct file *file, unsigned int cmd,
break;
}
- kfree(kmake);
+ kfree(m);
kfree(hello);
return ret;
diff --git a/kdbus.txt b/kdbus.txt
index f12261d85ea..a07ec38627b 100644
--- a/kdbus.txt
+++ b/kdbus.txt
@@ -450,7 +450,7 @@ ECOMM
A peer does not accept the file descriptors addressed to it.
EDESTADDRREQ
- The well-known bus name is missing, to address the destination.
+ The well-known bus name is required but missing.
EDOM
The size of data does not match the expectations. Used for the