Permalink
Browse files

consolidate most memdup_user to handle.c

  • Loading branch information...
1 parent e7b49ee commit 3093474c95a0ce8a46d759fbb1acc7b97f7b75e4 @zonque zonque committed Jan 22, 2014
Showing with 251 additions and 281 deletions.
  1. +13 −57 connection.c
  2. +5 −4 connection.h
  3. +3 −0 defaults.h
  4. +150 −26 handle.c
  5. +28 −63 match.c
  6. +4 −2 match.h
  7. +32 −87 names.c
  8. +3 −3 names.h
  9. +12 −38 policy.c
  10. +1 −1 policy.h
View
@@ -950,16 +950,15 @@ static int kdbus_conn_recv_msg(struct kdbus_conn *conn,
}
/**
- * kdbus_conn_recv_msg_user - receive a message from the queue
+ * kdbus_cmd_msg_recv - receive a message from the queue
* @conn: Connection to work on
- * @recv_buf: A struct kdbus_cmd_recv containing the command details
+ * @recv: The command as passed in by the ioctl
*
* Return: 0 on success, negative errno on failure
*/
-int kdbus_conn_recv_msg_user(struct kdbus_conn *conn,
- struct kdbus_cmd_recv __user *recv_buf)
+int kdbus_cmd_msg_recv(struct kdbus_conn *conn,
+ struct kdbus_cmd_recv *recv)
{
- struct kdbus_cmd_recv recv;
int ret;
mutex_lock(&conn->lock);
@@ -973,24 +972,15 @@ int kdbus_conn_recv_msg_user(struct kdbus_conn *conn,
goto exit_unlock;
}
- if (copy_from_user(&recv, recv_buf, sizeof(struct kdbus_cmd_recv))) {
- ret = -EFAULT;
- goto exit_unlock;
- }
-
- if (recv.offset > 0) {
+ if (recv->offset > 0) {
ret = -EINVAL;
goto exit_unlock;
}
- ret = kdbus_conn_recv_msg(conn, &recv);
+ ret = kdbus_conn_recv_msg(conn, recv);
if (ret < 0)
goto exit_unlock;
- /* return the address of the next message in the pool */
- if (copy_to_user(&recv_buf->offset, &recv.offset, sizeof(__u64)))
- ret = -EFAULT;
-
exit_unlock:
mutex_unlock(&conn->lock);
return ret;
@@ -1496,37 +1486,23 @@ int kdbus_conn_move_messages(struct kdbus_conn *conn_dst,
/**
* kdbus_cmd_conn_info() - retrieve info about a connection
* @conn: Connection
- * @buf: The returned offset to the message in the pool
+ * @cmd_info: The cómmand as passed in by the ioctl
*
* Return: 0 on success, negative errno on failure.
*/
int kdbus_cmd_conn_info(struct kdbus_conn *conn,
- void __user *buf)
+ struct kdbus_cmd_conn_info *cmd_info,
+ size_t size)
{
- struct kdbus_cmd_conn_info *cmd_info;
struct kdbus_conn_info info = {};
struct kdbus_conn *owner_conn = NULL;
size_t off, pos;
char *name = NULL;
struct kdbus_meta *meta = NULL;
u64 flags;
- u64 size;
u32 hash;
int ret = 0;
- if (kdbus_size_get_user(&size, buf, struct kdbus_cmd_conn_info))
- return -EFAULT;
-
- if (size < sizeof(struct kdbus_cmd_conn_info))
- return -EINVAL;
-
- if (size > sizeof(struct kdbus_cmd_conn_info) + KDBUS_NAME_MAX_LEN + 1)
- return -EMSGSIZE;
-
- cmd_info = memdup_user(buf, size);
- if (IS_ERR(cmd_info))
- return PTR_ERR(cmd_info);
-
if (cmd_info->id == 0) {
if (size == sizeof(struct kdbus_cmd_conn_info)) {
ret = -EINVAL;
@@ -1629,10 +1605,8 @@ int kdbus_cmd_conn_info(struct kdbus_conn *conn,
pos += meta->size;
}
- if (kdbus_offset_set_user(&off, buf, struct kdbus_cmd_conn_info)) {
- ret = -EFAULT;
- goto exit_free;
- }
+ /* write back the offset */
+ cmd_info->offset = off;
exit_free:
if (ret < 0)
@@ -1641,37 +1615,21 @@ int kdbus_cmd_conn_info(struct kdbus_conn *conn,
exit:
kdbus_meta_free(meta);
kdbus_conn_unref(owner_conn);
- kfree(cmd_info);
return ret;
}
/**
* kdbus_conn_update() - update flags for a connection
* @conn: Connection
- * @buf: The struct containing the new flags
+ * @cmd_update: The command as passed in by the ioctl
*
* Return: 0 on success, negative errno on failure.
*/
int kdbus_cmd_conn_update(struct kdbus_conn *conn,
- void __user *buf)
+ struct kdbus_cmd_conn_update *cmd_update)
{
- struct kdbus_cmd_conn_update *cmd_update;
struct kdbus_item *item;
- u64 size;
-
- if (kdbus_size_get_user(&size, buf, struct kdbus_cmd_conn_update))
- return -EFAULT;
-
- if (size < sizeof(struct kdbus_cmd_conn_update))
- return -EINVAL;
-
- if (size > KDBUS_HELLO_MAX_SIZE)
- return -EMSGSIZE;
-
- cmd_update = memdup_user(buf, size);
- if (IS_ERR(cmd_update))
- return PTR_ERR(cmd_update);
KDBUS_ITEM_FOREACH(item, cmd_update, items) {
switch (item->type) {
@@ -1681,8 +1639,6 @@ int kdbus_cmd_conn_update(struct kdbus_conn *conn,
}
}
- kfree(cmd_update);
-
return 0;
}
View
@@ -93,12 +93,13 @@ struct kdbus_conn *kdbus_conn_unref(struct kdbus_conn *conn);
int kdbus_conn_disconnect(struct kdbus_conn *conn, bool ensure_msg_list_empty);
bool kdbus_conn_active(struct kdbus_conn *conn);
-int kdbus_conn_recv_msg_user(struct kdbus_conn *conn,
- struct kdbus_cmd_recv __user *recv);
+int kdbus_cmd_msg_recv(struct kdbus_conn *conn,
+ struct kdbus_cmd_recv *recv);
int kdbus_cmd_conn_info(struct kdbus_conn *conn,
- void __user *buf);
+ struct kdbus_cmd_conn_info *cmd_info,
+ size_t size);
int kdbus_cmd_conn_update(struct kdbus_conn *conn,
- void __user *buf);
+ struct kdbus_cmd_conn_update *cmd_update);
int kdbus_conn_kmsg_send(struct kdbus_ep *ep,
struct kdbus_conn *conn_src,
struct kdbus_kmsg *kmsg);
View
@@ -37,6 +37,9 @@
/* maximum size of hello data */
#define KDBUS_HELLO_MAX_SIZE SZ_32K
+/* maximum size for connection update */
+#define KDBUS_CONN_UPDATE_MAX_SIZE SZ_32K
+
/* maximum size of match data */
#define KDBUS_MATCH_MAX_SIZE SZ_32K
Oops, something went wrong.

0 comments on commit 3093474

Please sign in to comment.