Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp527114pxb; Wed, 3 Mar 2021 08:55:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJymX6yMMekHoOIdd4sCvS40KpT/dLD23BrHVN89VJuL5gEmClE1usagxleC51DNFOO87UY4 X-Received: by 2002:aa7:c5c4:: with SMTP id h4mr135895eds.375.1614790525597; Wed, 03 Mar 2021 08:55:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614790525; cv=none; d=google.com; s=arc-20160816; b=Ky1YIYqbuMJwuEdkyTNOxjUteMuCxzoeBa8peWtKwtKcW2qWXcCNrghNnWUpdly7HW kLGB8LLkB6Q7Kp7aogaloffaDL9I3vf705CvuiGKTNOchiYTKtTJQ50+KRC0/8KcNNYB gruHuP7QIHNp+OGGQYxHuh6McVH51Q+oY9TAXmE4HaERZbRBsZBx230P0Xh0+thKDOsB 8ePJq9e89AKPAPg+ujN9m4JSnk6vAJMIGxjl+OSlC8DJroZD3aUxivs1/QTiTuP5O3hL 7PSDOUdwUsarfhVA0+cBsl20lTKEyLTIa3NypF8QB3MFx4/Hn+yLnaiYREpV86kenZao O21g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QG/telOF+BFKWfD3uXQwjyELlGE0FS7DYWFbCk1HTZE=; b=V0dDPGbo5mut5kLspr3rav1ITSDB28fjSDi4FPWB7X/LLZx9D/ZXWkDh6yozg54oU2 kPB10MT8ZI5nI8LVJYmKzaXsWcuKgeUaPNDYVmBaM77XTyI7tnOGcl9XhpHLDN93q9N5 aeCfBZo5VBhysyqCDv1WH3Yaac3b2AnQ6i+A+jfu0a0+AzrU57rLpFTvx4u6LSjoOPqS O6/n7NOd7/0FKUU+MlSjP0tONGjkqtQXG8EzjpeDxGgeveneoDabLGISMhMvUPKKsfsq J3G2xrB9Dtw9patsBtPvphBE732rMalmTdJ7o3BVnRquaP7ecxGM8tN3akqUM/GAGbzd TVfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DLkXqo2U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t16si16667566edi.281.2021.03.03.08.54.34; Wed, 03 Mar 2021 08:55:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DLkXqo2U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348117AbhCBA2j (ORCPT + 99 others); Mon, 1 Mar 2021 19:28:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:43158 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234882AbhCAS3J (ORCPT ); Mon, 1 Mar 2021 13:29:09 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7E3F46528D; Mon, 1 Mar 2021 17:32:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614619944; bh=xOWbgxp3vEq+RDS7HFsY+tPWOzL+E97JnpPwj0+LSvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DLkXqo2UCuRfWxJvHcDStf+qiq7tQQ1TnrciBJ1ycKPaGQvitdCGKOK4CYAqS3ta/ Au4hrJlgK02bVP7cOCqSFgvwwGX7f/7QdP+aQ7dxpovzim6k9TmHaImcmkZEuXm9rP C3yXH6qMvE30F+C70VlpcFeoxeL9OB81J4KblCMk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bob Peterson , Andreas Gruenbacher Subject: [PATCH 5.10 638/663] gfs2: Dont skip dlm unlock if glock has an lvb Date: Mon, 1 Mar 2021 17:14:46 +0100 Message-Id: <20210301161213.422467223@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bob Peterson commit 78178ca844f0eb88f21f31c7fde969384be4c901 upstream. 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 Signed-off-by: Andreas Gruenbacher Signed-off-by: Greg Kroah-Hartman --- fs/gfs2/lock_dlm.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) --- a/fs/gfs2/lock_dlm.c +++ b/fs/gfs2/lock_dlm.c @@ -284,7 +284,6 @@ static void gdlm_put_lock(struct gfs2_gl { struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; struct lm_lockstruct *ls = &sdp->sd_lockstruct; - int lvb_needs_unlock = 0; int error; if (gl->gl_lksb.sb_lkid == 0) { @@ -297,13 +296,10 @@ static void gdlm_put_lock(struct gfs2_gl gfs2_sbstats_inc(gl, GFS2_LKS_DCOUNT); gfs2_update_request_times(gl); - /* don't want to skip dlm_unlock writing the lvb when lock is ex */ - - if (gl->gl_lksb.sb_lvbptr && (gl->gl_state == LM_ST_EXCLUSIVE)) - lvb_needs_unlock = 1; + /* don't want to skip dlm_unlock writing the lvb when lock has one */ if (test_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags) && - !lvb_needs_unlock) { + !gl->gl_lksb.sb_lvbptr) { gfs2_glock_free(gl); return; }