]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/commit
MFC: r227059
authorrmacklem <rmacklem@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Thu, 17 Nov 2011 16:08:46 +0000 (16:08 +0000)
committerrmacklem <rmacklem@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Thu, 17 Nov 2011 16:08:46 +0000 (16:08 +0000)
commit97b6ce4d259d6c44de18230aaabdce8abecb5a0b
tree33e82f88841c2bac23eee870fe97e9b718eb2455
parent5b93a15a3157d44425296aaa196dc658828c3cc5
MFC: r227059
Both a crash reported on freebsd-current on Oct. 18 under the
subject heading "mtx_lock() of destroyed mutex on NFS" and
PR# 156168 appear to be caused by clnt_dg_destroy() closing
down the socket prematurely. When to close down the socket
is controlled by a reference count (cs_refs), but clnt_dg_create()
checks for sb_upcall being non-NULL to decide if a new socket
is needed. I believe the crashes were caused by the following race:
  clnt_dg_destroy() finds cs_refs == 0 and decides to delete socket
  clnt_dg_destroy() then loses race with clnt_dg_create() for
    acquisition of the SOCKBUF_LOCK()
  clnt_dg_create() finds sb_upcall != NULL and increments cs_refs to 1
  clnt_dg_destroy() then acquires SOCKBUF_LOCK(), sets sb_upcall to
    NULL and destroys socket

This patch fixes the above race by changing clnt_dg_destroy() so
that it acquires SOCKBUF_LOCK() before testing cs_refs.

Tested by: bz
Reviewed by: dfr
Approved by: re (kib)

git-svn-id: svn://svn.freebsd.org/base/stable/9@227630 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
sys/rpc/clnt_dg.c