Skip to content

Commit

Permalink
sunrpc: svc_sock_names should hold ref to socket being closed.
Browse files Browse the repository at this point in the history
Currently svc_sock_names calls svc_close_xprt on a svc_sock to
which it does not own a reference.
As soon as svc_close_xprt sets XPT_CLOSE, the socket could be
freed by a separate thread (though this is a very unlikely race).

It is safer to hold a reference while calling svc_close_xprt.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
  • Loading branch information
NeilBrown authored and J. Bruce Fields committed Dec 17, 2010
1 parent 7c96aef commit 3942302
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions net/sunrpc/svcsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,21 @@ int svc_sock_names(struct svc_serv *serv, char *buf, const size_t buflen,
len = onelen;
break;
}
if (toclose && strcmp(toclose, buf + len) == 0)
if (toclose && strcmp(toclose, buf + len) == 0) {
closesk = svsk;
else
svc_xprt_get(&closesk->sk_xprt);
} else
len += onelen;
}
spin_unlock_bh(&serv->sv_lock);

if (closesk)
if (closesk) {
/* Should unregister with portmap, but you cannot
* unregister just one protocol...
*/
svc_close_xprt(&closesk->sk_xprt);
else if (toclose)
svc_xprt_put(&closesk->sk_xprt);
} else if (toclose)
return -ENOENT;
return len;
}
Expand Down

0 comments on commit 3942302

Please sign in to comment.