From patchwork Sat Oct 22 07:18:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7188 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1089254wrr; Sat, 22 Oct 2022 00:42:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4xBSoabXXxSkbTbyflJPDinSxmjEOk7SnDIzefdFG7Aq1WR7P6DPum5iVaa3mxwTcD0oJn X-Received: by 2002:a17:90a:4594:b0:20b:23d5:8ead with SMTP id v20-20020a17090a459400b0020b23d58eadmr61194029pjg.127.1666424549248; Sat, 22 Oct 2022 00:42:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666424549; cv=none; d=google.com; s=arc-20160816; b=F1gUZWa054szyX2N9aaQknHQi5e7W9aN8VNUjRVsGyY/KcB3h8ljUPy9ZgLZcLCmG9 CpzJMbBbPdSG71QQjNprUsvvQMSazoUiCkXWMnOYYbE7nWgepeGgLQ6JfD9hp6HcIE3e 4VgWp4P0lWSDkQFRnjpZXppvnHBxVXIVTQOELlxW3BuIgCBEsh4eEqYoB/FQkJ/oTVwK FwDhvOfaHCaasrCH0ZXnYC/kDhcdcAJWNrZlqe+qotI1d0DdOizeRbvTNjJ/82Ria0F7 K296xW4dX1PJc9KSL2oLa1glyUFFqYk9U7WV7g+8up5kzjj1b5j7sWQ0ZTUfLLpolUDp hO6A== 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=j8Xomj0fQuqTrEPYs85LyPIT2S8pL5SEO58O73gA53g=; b=gL9JicuhWV6VRshN7+whE9QXH+vXe6tKMVhi61c+bV7Jl5mULZU3QL7fItFw8+ESPh 8LHY/G3ui9KRJUlZUoWmvT9Crm742cBQMSt1wFOvL1phx61H0w3tDdpPCoPpRS9gazHS y35h1GWnNroWAruP0sOQq0DANeBh5Dkbh5fFet47H/Fhg0THGO+Dz7fORF8nR4eC+wTq S+Sv6TXWToQ48Mbd5Se7Jev9f7CP3p6fZ3gu1eitv3HyCCmWTZbCACwK07LOer8nX/ln PFLW7lwamDAWkw04gBvZNrlHbGHTBRZKR11sotkRVmt76hHrpI1CgeXCUshWMOtkofTK +kfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TZV78V4v; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cn15-20020a056a00340f00b005655fc278f3si24079209pfb.201.2022.10.22.00.42.17; Sat, 22 Oct 2022 00:42:29 -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=TZV78V4v; 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 S231210AbiJVHlz (ORCPT + 99 others); Sat, 22 Oct 2022 03:41:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230519AbiJVHl3 (ORCPT ); Sat, 22 Oct 2022 03:41:29 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C97002D762; Sat, 22 Oct 2022 00:39:26 -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 1BADAB82DB2; Sat, 22 Oct 2022 07:37:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BC9AC433D6; Sat, 22 Oct 2022 07:36:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424219; bh=jBoTbudxBixvFylnCwkGubpi1p23EEKMHTLT51gJ8yc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TZV78V4vEcacLNqVOteInxngf0sBchFvD3o6EC965Uq5kPflbJFWVWB/gdBnhrTIG lxnzjkFaddwXFWYRLS0jKUzx0X7gyIRiWfw243xy+tdse1ebRxIcPfG7YIJ/2Si0yK kNlGnOKRDk1lOueTEoiszkwzdskaWLFA4PnkZKzw= 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.19 036/717] fs: dlm: fix race between test_bit() and queue_work() Date: Sat, 22 Oct 2022 09:18:35 +0200 Message-Id: <20221022072421.521048689@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747372788243186739?= X-GMAIL-MSGID: =?utf-8?q?1747372788243186739?= From: Alexander Aring commit eef6ec9bf390e836a6c4029f3620fe49528aa1fe upstream. This patch fixes a race by using ls_cb_mutex around the bit operations and conditional code blocks for LSFL_CB_DELAY. The function dlm_callback_stop() expects to stop all callbacks and flush all currently queued onces. The set_bit() is not enough because there can still be queue_work() after the workqueue was flushed. To avoid queue_work() after set_bit(), surround both by ls_cb_mutex. Cc: stable@vger.kernel.org Signed-off-by: Alexander Aring Signed-off-by: David Teigland Signed-off-by: Greg Kroah-Hartman --- fs/dlm/ast.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/fs/dlm/ast.c +++ b/fs/dlm/ast.c @@ -200,13 +200,13 @@ void dlm_add_cb(struct dlm_lkb *lkb, uin if (!prev_seq) { kref_get(&lkb->lkb_ref); + mutex_lock(&ls->ls_cb_mutex); if (test_bit(LSFL_CB_DELAY, &ls->ls_flags)) { - mutex_lock(&ls->ls_cb_mutex); list_add(&lkb->lkb_cb_list, &ls->ls_cb_delay); - mutex_unlock(&ls->ls_cb_mutex); } else { queue_work(ls->ls_callback_wq, &lkb->lkb_cb_work); } + mutex_unlock(&ls->ls_cb_mutex); } out: mutex_unlock(&lkb->lkb_cb_mutex); @@ -288,7 +288,9 @@ void dlm_callback_stop(struct dlm_ls *ls void dlm_callback_suspend(struct dlm_ls *ls) { + mutex_lock(&ls->ls_cb_mutex); set_bit(LSFL_CB_DELAY, &ls->ls_flags); + mutex_unlock(&ls->ls_cb_mutex); if (ls->ls_callback_wq) flush_workqueue(ls->ls_callback_wq);