limit the amount of request for a reply a connection can issue
authorKay Sievers <kay@vrfy.org>
Sat, 28 Dec 2013 17:29:05 +0000 (18:29 +0100)
committerKay Sievers <kay@vrfy.org>
Sat, 28 Dec 2013 17:29:05 +0000 (18:29 +0100)
connection.c
connection.h
internal.h
kdbus.h

index d1e61f084e3609bd4e3bc20869fdaedaa4488b80..aa0fdd367c9979294a937d2bb3aca562349c4fc3 100644 (file)
@@ -90,8 +90,8 @@ struct kdbus_conn_reply_entry {
 static void kdbus_conn_reply_entry_free(struct kdbus_conn_reply_entry *reply)
 {
        atomic_dec(&reply->conn->reply_count);
-       kdbus_conn_unref(reply->conn);
        list_del(&reply->entry);
+       kdbus_conn_unref(reply->conn);
        kfree(reply);
 }
 
@@ -758,6 +758,12 @@ int kdbus_conn_kmsg_send(struct kdbus_ep *ep,
                struct kdbus_conn_reply_entry *reply;
                struct timespec ts;
 
+               if (atomic_read(&conn_src->reply_count) >
+                   KDBUS_CONN_MAX_REQUESTS_PENDING) {
+                       ret = -EMLINK;
+                       goto exit_unref;
+               }
+
                reply = kzalloc(sizeof(*reply), GFP_KERNEL);
                if (!reply) {
                        ret = -ENOMEM;
@@ -766,7 +772,6 @@ int kdbus_conn_kmsg_send(struct kdbus_ep *ep,
 
                INIT_LIST_HEAD(&reply->entry);
                reply->conn = kdbus_conn_ref(conn_dst);
-               atomic_inc(&reply->conn->reply_count);
                reply->cookie = msg->cookie;
 
                /* calculate the deadline based on the current time */
@@ -775,6 +780,7 @@ int kdbus_conn_kmsg_send(struct kdbus_ep *ep,
 
                mutex_lock(&conn_src->lock);
                list_add(&reply->entry, &conn_src->reply_list);
+               atomic_inc(&reply->conn->reply_count);
                mutex_unlock(&conn_src->lock);
 
                kdbus_conn_timeout_schedule_scan(conn_dst);
index 0a312090385ea5b6e275c21caef4dded2cdaaf3a..261804e4bc9c7aeedcfc8214f93ebff545b76122 100644 (file)
@@ -33,8 +33,8 @@
  * @names_queue_list:  Well-known names this connection waits for
  * @reply_list:                List of connections this connection expects
  *                     a reply from.
- * @reply_count:       Number of replies expected by others to be
- *                     received from this connection
+ * @reply_count:       Number of requests this connection has issued, and
+ *                     waits for replies from the peer
  * @names:             Number of owned well-known names
  * @work:              Support for poll()
  * @timer:             Message reply timeout handling
index 03f09ae38e695de1735af25422651b4896c7403d..8daffc7458c3a30a101be2c3120c18393a9353fe 100644 (file)
 
 #include "kdbus.h"
 
-/* limits enforced by the interfaces */
-#define KDBUS_MSG_MAX_SIZE             SZ_8K           /* maximum size of message header and items */
-#define KDBUS_MSG_MAX_ITEMS            128             /* maximum number of message items */
-#define KDBUS_MSG_MAX_FDS              256             /* maximum number of passed file descriptors */
-#define KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE SZ_8M           /* maximum message payload size */
+/* maximum size of message header and items */
+#define KDBUS_MSG_MAX_SIZE             SZ_8K
 
-#define KDBUS_NAME_MAX_LEN             255             /* maximum length of well-known bus name */
+/* maximum number of message items */
+#define KDBUS_MSG_MAX_ITEMS            128
 
-#define KDBUS_MAKE_MAX_LEN             63              /* maximum length of bus, ns, ep name */
-#define KDBUS_MAKE_MAX_SIZE            SZ_32K          /* maximum size of make data */
+/* maximum number of passed file descriptors */
+#define KDBUS_MSG_MAX_FDS              256
 
-#define KDBUS_HELLO_MAX_SIZE           SZ_32K          /* maximum size of hello data */
-#define KDBUS_MATCH_MAX_SIZE           SZ_32K          /* maximum size of match data */
-#define KDBUS_POLICY_MAX_SIZE          SZ_32K          /* maximum size of policy data */
+/* maximum message payload size */
+#define KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE SZ_2M
 
-#define KDBUS_CONN_MAX_MSGS            64              /* maximum number of queued messages per connection */
-#define KDBUS_CONN_MAX_NAMES           64              /* maximum number of well-known names */
-#define KDBUS_CONN_MAX_ALLOCATED_BYTES SZ_64K          /* maximum number of allocated bytes on the bus */
+/* maximum length of well-known bus name */
+#define KDBUS_NAME_MAX_LEN             255
+
+/* maximum length of bus, ns, ep name */
+#define KDBUS_MAKE_MAX_LEN             63
+
+/* maximum size of make data */
+#define KDBUS_MAKE_MAX_SIZE            SZ_32K
+
+/* maximum size of hello data */
+#define KDBUS_HELLO_MAX_SIZE           SZ_32K
+
+/* maximum size of match data */
+#define KDBUS_MATCH_MAX_SIZE           SZ_32K
+
+/* maximum size of policy data */
+#define KDBUS_POLICY_MAX_SIZE          SZ_32K
+
+/* maximum number of queued messages per connection */
+#define KDBUS_CONN_MAX_MSGS            64
+
+/* maximum number of well-known names */
+#define KDBUS_CONN_MAX_NAMES           64
+
+/* maximum number of queud requests waiting ot a reply */
+#define KDBUS_CONN_MAX_REQUESTS_PENDING        64
 
 /* all exported addresses are 64 bit */
 #define KDBUS_PTR(addr) ((void __user *)(uintptr_t)(addr))
diff --git a/kdbus.h b/kdbus.h
index c59bdd859d79f4c0aa4cd417ce3fe1fbc0900351..81f0d8e945c84836b998573029bf0748475f072d 100644 (file)
--- a/kdbus.h
+++ b/kdbus.h
@@ -789,6 +789,8 @@ enum kdbus_ioctl_type {
  *                     refused to send as KDBUS_MSG_PAYLOAD_MEMFD.
  * @EMFILE:            Too many file descriptors have been supplied with a
  *                     message.
+ * @EMLINK:            Too many requests from this connection to other peers
+ *                     are queued and waiting for a reply
  * @EMSGSIZE:          The supplied data is larger than the allowed maximum
  *                     size.
  * @ENAMETOOLONG:      The requested name is larger than the allowed maximum