Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp443187iog; Mon, 13 Jun 2022 06:06:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyFR4lfnVF24WzkdLgPhLvG8HGnJwHamBVQfLQRuFdQ9ATh91e0mNUUiiF12AcwjNVSFqe X-Received: by 2002:a17:906:fc12:b0:711:d2e9:99d9 with SMTP id ov18-20020a170906fc1200b00711d2e999d9mr35576290ejb.734.1655125590608; Mon, 13 Jun 2022 06:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125590; cv=none; d=google.com; s=arc-20160816; b=gE4lZzjuu+b2Be91DsCKCZkN6BzLo789ypcYpjDaZU2kwts1/wpL4kNzoH/J8Afb/f g67wa1iuh7cjIDf50W6n99AlNiYC63C/dmkI8qBsujskm28eeAdqm/3B2FFqQISoSB5b yNOhL8+KN5evGHF9N4kKpGckRtgH2A1oMioobk1Zex8jkvW83cbEskxaYRnpViXK+e9+ tnLs3YMCo8Sktl3DBnrA0D0ZbK9/0Nwd8Xyb8gA32jSekSLVUo0Mp9XYtpFl5DzVSlqs mjo+uMnaDRurJMPeckqxOjS785IZ3XDf5KEsngn0K+9cZa3fT5894nWqwPp0bEdJm8NW U8yA== 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=GmUY0zh4x2HnquS/bpg2ee5mF/WwrOAU8ynWFQ54by8=; b=YoceMqWd1rq0MsjsJiQ6ijVUpi8p3DqWisu7lKxs/lJl3et9LUPrqU9EISYqClAC1D 5eHQK2yHy6XQ+XHQdrw+/vo1+ENykt2kVU7s5uW/0zsykAUQqFuxIrAYI5ypt6oB2sKX 1oUEtJD8JbkCnXVH2CjGRtwyHVROe6VFdK/ul4AFucHHGvpxV3lhJEEcaoJ5Omz4Cwt/ btjUFySvhdbFpFzzj9ghIN3BocimZmOEh0L4+KJFNlpK6Ldf61p1hgylypng1jfsfTgf Zy8lFGCO7pCwk8YqxCnkVIt8CE/ALAmsOU7KivEI3yNiONXYyHpFqrRC7fR0KD8QyFec hY1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tD43jJmz; 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 ht9-20020a170907608900b006f445fe1697si8569892ejc.35.2022.06.13.06.05.54; Mon, 13 Jun 2022 06:06:30 -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=tD43jJmz; 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 S1345321AbiFMKug (ORCPT + 99 others); Mon, 13 Jun 2022 06:50:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347098AbiFMKsv (ORCPT ); Mon, 13 Jun 2022 06:48:51 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C5542CE12; Mon, 13 Jun 2022 03:26:21 -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 7AEE2B80E93; Mon, 13 Jun 2022 10:26:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD66BC34114; Mon, 13 Jun 2022 10:26:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655115979; bh=lhGVzRPR4WaH1VyZpBkjH0HY2CZB+piN8LsuqvOHiVo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tD43jJmzI1eWgS3Vr/WDAvPxZegeOo1Q7eZ0xQerdsHOqJf29NvUuxR6T9mYgchIU Rkk77jAC/PC2domxT0v98GELZt1xd4+4ZkQHHGf+QKbWu+XUyPxXxsZ/weUV/hcX36 w6A65U3zx/D1MS7Di3s7fAltXpMhtPJAchzYC934= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Aring , David Teigland Subject: [PATCH 4.14 110/218] dlm: fix missing lkb refcount handling Date: Mon, 13 Jun 2022 12:09:28 +0200 Message-Id: <20220613094923.898470540@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094908.257446132@linuxfoundation.org> References: <20220613094908.257446132@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 @@ -1554,6 +1554,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; } @@ -1580,6 +1581,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; } @@ -5311,11 +5313,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 */