Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3563994pxb; Mon, 1 Mar 2021 13:29:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJxrLijRqijhNtTCy2E609SDOwucPk8FOgRSIcTTS4D52dHagGp5c3NDbyo8FWZB/m1kZAEM X-Received: by 2002:a17:906:5d05:: with SMTP id g5mr2082959ejt.489.1614634171577; Mon, 01 Mar 2021 13:29:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614634171; cv=none; d=google.com; s=arc-20160816; b=DyS0/MAg/zo0TINKkSkzkZpggsEJw26f8R3E+6eUleuXbvSy6dWV6lbR9tJcXmF/Dl QDMqDR+S6aiFQwbd3hWpDPociqI/zhcr4iJKm1Cuhf2/5Tq8NUAjpEVeo0RL36Pxxhtl RfPMEwmYTmydfRV3vKG7QhiEb9jIH5Sac0YQ2tjNYnL/HPC6F8ulqZZn3umWO8T3UX3U Lgzy2su1i6S8c4k9ciG146YgnbmDJfmr6fqa535TPqcwWw408qbbX3peB515NiS9Ds6e OmxMGZafckldgV+4cV/I3rb7M/t0ufxkslxHuNIAG1aHWZN4SrnUmwyDXRjC0h9o5paC dwDw== 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=4gYnkyFNvsTSPPvkI/BwD6qCb3DL7jT6ceWx5klLYKE=; b=GvgpchLyPzw04jdPG//OwW/7TmLUwdhCQfmCrRxUSrE2SgnuO6xlfE6ZEo+2ZpiZpX 5yhqXXgZCaiQA9+SoqscgvXXV6BswL/kWElJs8F4MN9dwl0uygTWpD4s1RhuLajdg1eV UTykpG7unHp+8AwuCADnC3fOt3P27louSYvhQgqVrKB6cLIQtJEJpM2zRIgcw7Bdig2g DBlTEuZQ02wZo9rkJpiZc8lG1zGWsjAlYpaLGPxATxQKlzO7Xb4fpOQMg7pO+GYonc5s PAqwvv77vDPzSdsgP+OThnR/gWMblN15uYEVVzhm+aUC74mD+t1/OpVU5Rsf6uFjah96 j3pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wisY97FH; 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 o26si12088143edw.74.2021.03.01.13.29.08; Mon, 01 Mar 2021 13:29:31 -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=wisY97FH; 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 S240589AbhCAVWW (ORCPT + 99 others); Mon, 1 Mar 2021 16:22:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:52648 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237775AbhCARQE (ORCPT ); Mon, 1 Mar 2021 12:16:04 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id EEEB46504C; Mon, 1 Mar 2021 16:46:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614617179; bh=QkMUxZuax3MyLf9HVncaHyyNn/dTLBWh9vVXAEoTsZI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wisY97FHcFOySiYhHaaqlN0/jNZKrJ4qN8/ZSSpqlvWjTXxeq0pIYZN+hNSi+UHUJ w5nhlUwqj4Ymo8l17GD+KXN9+r8do772yABtpxq8+CyDge/NIWEtMkbj6oBJGUg+Lz l6nN0Pe26Wq85ebUjyo0zYETCbNQOw4oXgOEHwD0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bob Peterson , Andreas Gruenbacher Subject: [PATCH 4.19 231/247] gfs2: Dont skip dlm unlock if glock has an lvb Date: Mon, 1 Mar 2021 17:14:11 +0100 Message-Id: <20210301161043.006492951@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@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 @@ -283,7 +283,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) { @@ -296,13 +295,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; }