Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The limit max_conns_per_ip is broken #62

Closed
ShikChen opened this issue Nov 4, 2017 · 1 comment
Closed

The limit max_conns_per_ip is broken #62

ShikChen opened this issue Nov 4, 2017 · 1 comment

Comments

@ShikChen
Copy link
Contributor

ShikChen commented Nov 4, 2017

nsjail/net.c

Lines 165 to 178 in e2529ce

unsigned int cnt = 0;
struct pids_t* p;
TAILQ_FOREACH(p, &nsjconf->pids, pointers) {
if (memcmp(addr.sin6_addr.s6_addr, p->remote_addr.sin6_addr.s6_addr,
sizeof(*p->remote_addr.sin6_addr.s6_addr)) == 0) {
cnt++;
}
}
if (cnt >= nsjconf->max_conns_per_ip) {
LOG_W("Rejecting connection from '%s', max_conns_per_ip limit reached: %u", cs_addr,
nsjconf->max_conns_per_ip);
return false;
}

There is a redundant dereference operator in the sizeof(...) of memcmp, so it would only compare the first byte of address and reject new connections too aggressively.

The relevant structures:

struct sockaddr_in6 {
    sa_family_t     sin6_family;   /* AF_INET6 */
    in_port_t       sin6_port;     /* port number */
    uint32_t        sin6_flowinfo; /* IPv6 flow information */
    struct in6_addr sin6_addr;     /* IPv6 address */
    uint32_t        sin6_scope_id; /* Scope ID (new in 2.4) */
};

struct in6_addr {
    unsigned char   s6_addr[16];   /* IPv6 address */
};
@ShikChen ShikChen changed the title The limit max_conns_per_ip is broken The limit max_conns_per_ip is broken Nov 4, 2017
@robertswiecki
Copy link
Collaborator

Thanks for the report - fixed with 9e355cb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants