Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp631272iog; Mon, 13 Jun 2022 09:30:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXC3w3RKPVzml4OfjVhVVxb2X+Tnj6c+pMfGQMKaTZinlbs4awJC+uGJL7upKfNcALOLlW X-Received: by 2002:a05:6a00:24c1:b0:50d:33cf:811f with SMTP id d1-20020a056a0024c100b0050d33cf811fmr391156pfv.78.1655137833360; Mon, 13 Jun 2022 09:30:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655137833; cv=none; d=google.com; s=arc-20160816; b=t7RooJTEhftu1b9+BoYoWvEXVzJ3kRRkZCLswWBhfDCjtJ1phXXFH+CkueV3h92Gck fSe3DuX647uUO9x5sh9KxAbzncMaR+YLDB4kKVH6mZXXWcSyEpoELU3qoVOuV3O27Mut 2hWWnlpC8K/8cvvOZ3ptUAAbjcX/sT9pAcbjrk6uUhSfGMI/9+YqNHHrUjiEtXt9tp7j T3pJwbIQT69wXpw4e2+OKYaqJ9gYmqIvfJH09TF3UMTutEAhrAxUY4veQoJOtViyCo49 Ix9DlidUipKNZuQA1dzF2QwjSgyl7I5iV8JWwpWrfxxK+V1BcMlFw9qPyGuinisKE8IQ Dpmg== 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=0yJhjAkiDe1IcXLM6Msk2uOhdSexvZLA2sPd03UbSFM=; b=rRe+NrkioXePlEuhTloGT+dt6gfiZGMB64lxZl1zzF08p0SGvRcdyEleya5214fES5 e0MPjU4e10HqQn5qBCMJc5f9ryoLGgdOPqPqanq2EmBFouEs56ka+pCm7+1PxuJQ5kLd Jp+H+6V5Dq95BckSthrhWajr//tUyO5/iV7T1XcxDfDbWI1qoTUp8n6hoJCs3cTKzf9E dm0p0LFiQM3ekrHL5+ROPzwW1HgM03KfWh15Iys973w2+cOJ5XtJk/c6DzxlyTXw6XRb odTUUgk2nlk9q9MNBO9iO6EHgfe1l/sJMOQY/b61q462UKibN7DCwVejmluYqriXYFMr XsmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eeI6Y7wt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o16-20020a17090ad25000b001dfd2940a5asi12377070pjw.112.2022.06.13.09.30.20; Mon, 13 Jun 2022 09:30:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eeI6Y7wt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1354231AbiFMLbx (ORCPT + 99 others); Mon, 13 Jun 2022 07:31:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353255AbiFMLZe (ORCPT ); Mon, 13 Jun 2022 07:25:34 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E465E3CFC4; Mon, 13 Jun 2022 03:42:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3647DB80EB4; Mon, 13 Jun 2022 10:42:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83F3EC34114; Mon, 13 Jun 2022 10:42:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116947; bh=RZgDdum0msf2g8pnmfSjWw5PkHFRPMvuZw+fPrm/v+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eeI6Y7wt7y75zw4QR0uE73oaYBo7szKRrAuPyUkUqgwARwzP39JHIcLV3XJZo3ZWz phezxRGO1GzYog3UbskE4vhmBrZrATZuN6P4F00sw4XPcKvKowL4yUuAQQYYWAGptZ nXl5hyzcN41qLIKv+1L52FWT8HWXHkJgIjh2BnTM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Aring , David Teigland Subject: [PATCH 5.4 235/411] dlm: fix missing lkb refcount handling Date: Mon, 13 Jun 2022 12:08:28 +0200 Message-Id: <20220613094935.831402076@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexander Aring commit 1689c169134f4b5a39156122d799b7dca76d8ddb upstream. We always call hold_lkb(lkb) if we increment lkb->lkb_wait_count. So, we always need to call unhold_lkb(lkb) if we decrement lkb->lkb_wait_count. This patch will add missing unhold_lkb(lkb) if we decrement lkb->lkb_wait_count. In case of setting lkb->lkb_wait_count to zero we need to countdown until reaching zero and call unhold_lkb(lkb). The waiters list unhold_lkb(lkb) can be removed because it's done for the last lkb_wait_count decrement iteration as it's done in _remove_from_waiters(). This issue was discovered by a dlm gfs2 test case which use excessively dlm_unlock(LKF_CANCEL) feature. Probably the lkb->lkb_wait_count value never reached above 1 if this feature isn't used and so it was not discovered before. The testcase ended in a rsb on the rsb keep data structure with a refcount of 1 but no lkb was associated with it, which is itself an invalid behaviour. A side effect of that was a condition in which the dlm was sending remove messages in a looping behaviour. With this patch that has not been reproduced. Cc: stable@vger.kernel.org Signed-off-by: Alexander Aring Signed-off-by: David Teigland Signed-off-by: Greg Kroah-Hartman --- fs/dlm/lock.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -1551,6 +1551,7 @@ static int _remove_from_waiters(struct d lkb->lkb_wait_type = 0; lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; lkb->lkb_wait_count--; + unhold_lkb(lkb); goto out_del; } @@ -1577,6 +1578,7 @@ static int _remove_from_waiters(struct d log_error(ls, "remwait error %x reply %d wait_type %d overlap", lkb->lkb_id, mstype, lkb->lkb_wait_type); lkb->lkb_wait_count--; + unhold_lkb(lkb); lkb->lkb_wait_type = 0; } @@ -5312,11 +5314,16 @@ int dlm_recover_waiters_post(struct dlm_ lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK; lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; lkb->lkb_wait_type = 0; - lkb->lkb_wait_count = 0; + /* drop all wait_count references we still + * hold a reference for this iteration. + */ + while (lkb->lkb_wait_count) { + lkb->lkb_wait_count--; + unhold_lkb(lkb); + } mutex_lock(&ls->ls_waiters_mutex); list_del_init(&lkb->lkb_wait_reply); mutex_unlock(&ls->ls_waiters_mutex); - unhold_lkb(lkb); /* for waiters list */ if (oc || ou) { /* do an unlock or cancel instead of resending */