From: Kay Sievers Date: Sat, 28 Dec 2013 17:29:05 +0000 (+0100) Subject: limit the amount of request for a reply a connection can issue X-Git-Tag: upstream/0.20140120.123719~79 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4044c9cdc1bd3a6ef963a38c4ebac690f6c6a71d;p=platform%2Fcore%2Fsystem%2Fkdbus-bus.git limit the amount of request for a reply a connection can issue --- diff --git a/connection.c b/connection.c index d1e61f0..aa0fdd3 100644 --- a/connection.c +++ b/connection.c @@ -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); diff --git a/connection.h b/connection.h index 0a31209..261804e 100644 --- a/connection.h +++ b/connection.h @@ -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 diff --git a/internal.h b/internal.h index 03f09ae..8daffc7 100644 --- a/internal.h +++ b/internal.h @@ -15,24 +15,44 @@ #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 c59bdd8..81f0d8e 100644 --- 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