Skip to content

Commit

Permalink
RDS: fix rds_sock reference bug while doing bind
Browse files Browse the repository at this point in the history
One need to take rds socket reference while using it and release it
once done with it. rds_add_bind() code path does not do that so
lets fix it.

Signed-off-by: Santosh Shilimkar <ssantosh@kernel.org>
Signed-off-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
  • Loading branch information
Santosh Shilimkar authored and Santosh Shilimkar committed Sep 30, 2015
1 parent 8b0a6b4 commit 2812695
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions net/rds/bind.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ static struct rds_sock *rds_bind_lookup(__be32 addr, __be16 port,
cmp = ((u64)be32_to_cpu(rs->rs_bound_addr) << 32) |
be16_to_cpu(rs->rs_bound_port);

if (cmp == needle)
if (cmp == needle) {
rds_sock_addref(rs);
return rs;
}
}

if (insert) {
Expand Down Expand Up @@ -94,10 +96,10 @@ struct rds_sock *rds_find_bound(__be32 addr, __be16 port)
rs = rds_bind_lookup(addr, port, NULL);
read_unlock_irqrestore(&rds_bind_lock, flags);

if (rs && !sock_flag(rds_rs_to_sk(rs), SOCK_DEAD))
rds_sock_addref(rs);
else
if (rs && sock_flag(rds_rs_to_sk(rs), SOCK_DEAD)) {
rds_sock_put(rs);
rs = NULL;
}

rdsdebug("returning rs %p for %pI4:%u\n", rs, &addr,
ntohs(port));
Expand All @@ -123,14 +125,18 @@ static int rds_add_bound(struct rds_sock *rs, __be32 addr, __be16 *port)
write_lock_irqsave(&rds_bind_lock, flags);

do {
struct rds_sock *rrs;
if (rover == 0)
rover++;
if (!rds_bind_lookup(addr, cpu_to_be16(rover), rs)) {
rrs = rds_bind_lookup(addr, cpu_to_be16(rover), rs);
if (!rrs) {
*port = rs->rs_bound_port;
ret = 0;
rdsdebug("rs %p binding to %pI4:%d\n",
rs, &addr, (int)ntohs(*port));
break;
} else {
rds_sock_put(rrs);
}
} while (rover++ != last);

Expand Down

0 comments on commit 2812695

Please sign in to comment.