From patchwork Mon Oct 24 11:30:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8467 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp403028wru; Mon, 24 Oct 2022 04:51:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4u/DvNAoks/KmnHXrYZj7UYe0vNYVl7tjBae6Z/qC7ipsMv3naWPPClkSdoWzBScvNKYq2 X-Received: by 2002:a17:90b:1c0c:b0:213:1455:131f with SMTP id oc12-20020a17090b1c0c00b002131455131fmr4679613pjb.129.1666612266385; Mon, 24 Oct 2022 04:51:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666612266; cv=none; d=google.com; s=arc-20160816; b=I1W22xKkPEFZgpdl+ABsR2sAw2wfpi750lwSXzZhqvnOq54j/FBSIoVT+hOD5Vac69 Nqk+6MAw0gze9v7MR7ffNr+L+buhx7N41MT/gDm+5u6UHP5rTYOxmNSa1nifckepC+00 W0JIvkEFDX95a+Oq8u8GyBPDIp+mJ6fGPlFcjwQntOI99QDVQRRG64o+qmxuL+U33gvz zNVFZmrQ8hFaubIieru9PScGs07IndABrQ6Ue8HYkXZh/9J1uhrn3U42H00eQJNezggB zlBrmn+KXSmPjwpFhNeyckF9fnVwz/I2bBqR5icT7VwrT/zmNr6zDZRuSMSrKsFqg4fM 9HLA== 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=hmXdpMxOmd4MJuzvpU/cDsAiYsy+E2+329gIPH+Djks=; b=hBvk3P4U5mjyVcqlM4PQe7SAhRrry7FMBFuPfvfrcfTbl1bWdmpYqdZkXf8T+DElrQ UTtXAIwY+qiLEt249LsCGK9dJjuurdh669PSSD08a6SPAUqCEf4wUMArksxIQLSwkg1E MriADd5PQxSVXk0Ga1TRzaVajUADCpMRusCceN2Bq8ek+CymMMY/kBM+25FINbNjJ/wz SpdZ9JwloWz7R3xHUSqbzxQyeyLhaxnevmWM2afjgJacvh6OV4/tr+p6mXT71IaRqN3M gtdxXIYgJy+XAb2CYe0cqS6wbN5M2vKKz+No7cfMXP4adALd3ERbMoJFm6XE0vTUx9sv 28XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lB0PLDXm; 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 k15-20020a170902d58f00b00176806795b7si33757805plh.351.2022.10.24.04.50.53; Mon, 24 Oct 2022 04:51:06 -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=lB0PLDXm; 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 S231847AbiJXLui (ORCPT + 99 others); Mon, 24 Oct 2022 07:50:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231844AbiJXLtF (ORCPT ); Mon, 24 Oct 2022 07:49:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAABA2125A; Mon, 24 Oct 2022 04:43:41 -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 ED2B4B8117A; Mon, 24 Oct 2022 11:40:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49C69C43470; Mon, 24 Oct 2022 11:40:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611620; bh=Awcd/0SSmDN83dUDpNoaIq8lTcT014AjU8Qvxm5qHes=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lB0PLDXmDESahme5pgsy4l0Wc/sPAcCEp8E4tdpmG0zYIzFfBoKVOL59vM5yC3Zln S1o7FIIJA4PSHJr94s2T1xCCwn/SLaPLmtxf6A94KvgaitB5EKrsVryccH3SRYUyRn lMFemW9uT4bGNqodO4VATkvuaVQMFNrk+Hc0mf48= 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.9 046/159] fs: dlm: fix race between test_bit() and queue_work() Date: Mon, 24 Oct 2022 13:30:00 +0200 Message-Id: <20221024112951.076208775@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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?1747569623886812333?= X-GMAIL-MSGID: =?utf-8?q?1747569623886812333?= 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 @@ -198,13 +198,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); @@ -284,7 +284,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);