This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Cluster Project".
The branch, master has been updated
via d7387dedf8cf77f3a4156eb5a5264cca15e4e5bd (commit)
from 2f419450985f7bbc069a5be4443757f35450655c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
This commit imposes a limit on the number of outstanding replies
that a connection can have. This is to prevent a DoS attack that
causes cman to eat all available memory by sending lots of requests
and not reading the replies.
The deafult is 128, it can be set in cluster.conf as
<cman max_queued="1000"/>
int num_connections = 0;
poll_handle ais_poll_handle;
+uint32_t max_outstanding_messages = 128;
static int process_client(poll_handle handle, int fd, int revent, void *data);
+static void remove_client(poll_handle handle, struct connection *con);
/* Send it, or queue it for later if the socket is busy */
static int send_reply_message(struct connection *con, struct sock_header *msg)
@@ -83,6 +85,14 @@ static int send_reply_message(struct connection *con, struct sock_header *msg)
if ((ret > 0 && ret != msg->length) ||
(ret == -1 && errno == EAGAIN)) {
+
+ /* Have we exceeded the allowed number of queued messages ? */
+ if (con->num_write_msgs > max_outstanding_messages) {
+ P_DAEMON("Disconnecting. client has more that %d replies outstanding (%d)
", max_outstanding_messages, con->num_write_msgs);
+ remove_client(ais_poll_handle, con);
+ return -1;
+ }
+
/* Queue it */
struct queued_reply *qm = malloc(sizeof(struct queued_reply) + msg->length);
if (!qm)
@@ -96,7 +106,8 @@ static int send_reply_message(struct connection *con, struct sock_header *msg)
else
qm->offset = 0;
list_add(&con->write_msgs, &qm->list);
- P_DAEMON("queued last message
");
+ con->num_write_msgs++;
+ P_DAEMON("queued last message, count is %d
", con->num_write_msgs);
poll_dispatch_modify(ais_poll_handle, con->fd, POLLIN | POLLOUT, process_client);
}
return 0;
@@ -145,6 +156,7 @@ static void send_queued_reply(struct connection *con)
{
list_del(&qm->list);
free(qm);
+ con->num_write_msgs--;
}
else
{
@@ -330,6 +342,7 @@ static int process_rendezvous(poll_handle handle, int fd, int revent, void *data
newcon->type = con->type;
newcon->port = 0;
newcon->events = 0;
+ newcon->num_write_msgs = 0;
list_init(&newcon->write_msgs);
fcntl(client_fd, F_SETFL, fcntl(client_fd, F_GETFL, 0) | O_NONBLOCK);
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Cluster Project".
The branch, master has been updated
via d7387dedf8cf77f3a4156eb5a5264cca15e4e5bd (commit)
from 2f419450985f7bbc069a5be4443757f35450655c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
This commit imposes a limit on the number of outstanding replies
that a connection can have. This is to prevent a DoS attack that
causes cman to eat all available memory by sending lots of requests
and not reading the replies.
The deafult is 128, it can be set in cluster.conf as
<cman max_queued="1000"/>
int num_connections = 0;
poll_handle ais_poll_handle;
+uint32_t max_outstanding_messages = 128;
static int process_client(poll_handle handle, int fd, int revent, void *data);
+static void remove_client(poll_handle handle, struct connection *con);
/* Send it, or queue it for later if the socket is busy */
static int send_reply_message(struct connection *con, struct sock_header *msg)
@@ -83,6 +85,14 @@ static int send_reply_message(struct connection *con, struct sock_header *msg)
if ((ret > 0 && ret != msg->length) ||
(ret == -1 && errno == EAGAIN)) {
+
+ /* Have we exceeded the allowed number of queued messages ? */
+ if (con->num_write_msgs > max_outstanding_messages) {
+ P_DAEMON("Disconnecting. client has more that %d replies outstanding (%d)
", max_outstanding_messages, con->num_write_msgs);
+ remove_client(ais_poll_handle, con);
+ return -1;
+ }
+
/* Queue it */
struct queued_reply *qm = malloc(sizeof(struct queued_reply) + msg->length);
if (!qm)
@@ -96,7 +106,8 @@ static int send_reply_message(struct connection *con, struct sock_header *msg)
else
qm->offset = 0;
list_add(&con->write_msgs, &qm->list);
- P_DAEMON("queued last message
");
+ con->num_write_msgs++;
+ P_DAEMON("queued last message, count is %d
", con->num_write_msgs);
poll_dispatch_modify(ais_poll_handle, con->fd, POLLIN | POLLOUT, process_client);
}
return 0;
@@ -145,6 +156,7 @@ static void send_queued_reply(struct connection *con)
{
list_del(&qm->list);
free(qm);
+ con->num_write_msgs--;
}
else
{
@@ -330,6 +342,7 @@ static int process_rendezvous(poll_handle handle, int fd, int revent, void *data
newcon->type = con->type;
newcon->port = 0;
newcon->events = 0;
+ newcon->num_write_msgs = 0;
list_init(&newcon->write_msgs);
fcntl(client_fd, F_SETFL, fcntl(client_fd, F_GETFL, 0) | O_NONBLOCK);