gfs2: Don't skip dlm unlock if glock has an lvb
authorBob Peterson <rpeterso@redhat.com>
Fri, 5 Feb 2021 18:50:41 +0000 (13:50 -0500)
committerAndreas Gruenbacher <agruenba@redhat.com>
Fri, 5 Feb 2021 19:08:47 +0000 (20:08 +0100)
commit78178ca844f0eb88f21f31c7fde969384be4c901
treeb689277ee124a8f91a94f79ba7bf697dd570c893
parent834ec3e1ee65029029225a86c12337a6cd385af7
gfs2: Don't skip dlm unlock if glock has an lvb

Patch fb6791d100d1 was designed to allow gfs2 to unmount quicker by
skipping the step where it tells dlm to unlock glocks in EX with lvbs.
This was done because when gfs2 unmounts a file system, it destroys the
dlm lockspace shortly after it destroys the glocks so it doesn't need to
unlock them all: the unlock is implied when the lockspace is destroyed
by dlm.

However, that patch introduced a use-after-free in dlm: as part of its
normal dlm_recoverd process, it can call ls_recovery to recover dead
locks. In so doing, it can call recover_rsbs which calls recover_lvb for
any mastered rsbs. Func recover_lvb runs through the list of lkbs queued
to the given rsb (if the glock is cached but unlocked, it will still be
queued to the lkb, but in NL--Unlocked--mode) and if it has an lvb,
copies it to the rsb, thus trying to preserve the lkb. However, when
gfs2 skips the dlm unlock step, it frees the glock and its lvb, which
means dlm's function recover_lvb references the now freed lvb pointer,
copying the freed lvb memory to the rsb.

This patch changes the check in gdlm_put_lock so that it calls
dlm_unlock for all glocks that contain an lvb pointer.

Fixes: fb6791d100d1 ("GFS2: skip dlm_unlock calls in unmount")
Cc: stable@vger.kernel.org # v3.8+
Signed-off-by: Bob Peterson <rpeterso@redhat.com>
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
fs/gfs2/lock_dlm.c