]> git.ipfire.org Git - thirdparty/qemu.git/commit
qht: fix unlock-after-free segfault upon resizing
authorEmilio G. Cota <cota@braap.org>
Wed, 5 Oct 2016 22:34:39 +0000 (18:34 -0400)
committerMichael Roth <mdroth@linux.vnet.ibm.com>
Wed, 2 Nov 2016 22:15:30 +0000 (17:15 -0500)
commitaf29bd3193015865f6b2ca6f5c9e79aad1df3e28
tree445cf017eaac944937c3d9b51a50df265910b562
parentf72ca1ac6f7513537a4e8f2032aa0c4ca4013b72
qht: fix unlock-after-free segfault upon resizing

The old map's bucket locks are being unlocked *after*
that same old map has been passed to RCU for destruction.
This is a bug that can cause a segfault, since there's
no guarantee that the deletion will be deferred (e.g.
there may be no concurrent readers).

The segfault is easily triggered in RHEL6/CentOS6 with qht-test,
particularly on a single-core system or by pinning qht-test
to a single core.

Fix it by unlocking the map's bucket locks right after having
published the new map, and (crucially) before marking the map
for deletion via call_rcu().

While at it, expand qht_do_resize() to atomically do (1) a reset,
(2) a resize, or (3) a reset+resize. This simplifies the calling
code, since the new function (qht_do_resize_reset()) acquires
and releases the buckets' locks.

Note that no qht_do_reset inline is provided, since it would have
no users--qht_reset() already performs a reset without taking
ht->lock.

Reported-by: Peter Maydell <peter.maydell@linaro.org>
Reported-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Emilio G. Cota <cota@braap.org>
Message-Id: <1475706880-10667-3-git-send-email-cota@braap.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 76b553b308dc8671eb672b889b38889b1231cf1e)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
util/qht.c