From patchwork Mon Oct 24 11:29:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8669 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp421952wru; Mon, 24 Oct 2022 05:21:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4uB0BUr9PkRf1Q6tHyg2UeyhpSEcdwWz+CPJdGQxYIK0SOaJB8ePW5xI8pwrMNwVjRUjZi X-Received: by 2002:a17:906:9b92:b0:791:9355:cb89 with SMTP id dd18-20020a1709069b9200b007919355cb89mr26694593ejc.498.1666614093121; Mon, 24 Oct 2022 05:21:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666614093; cv=none; d=google.com; s=arc-20160816; b=Dhgkk1QKJlk3Tr4J1JvOkPU2y+hCBHVu65ZkspqRuZi81+r9WnnZFVsE+jwRrhvwon +EB12S8UF68YaIgqwkazoGvcCYxZeiWKwp5+6pJEmV2NPdvO2l7Vt5VDgEmx8NRHTF6r OuBKDTRiYcYBQ4fy74JXE2L7fWL6oMihIKRSpJZsVrzi6z1uiKyAlMR6Yrm0iPTPA1ll dVmAbrRjZuabPWXuI0HTDFikemteUWW0jbFvXH8zojyLAf3Uk+w/jaMuujWRHypAX7+M yS45j7DxzIS6GBOH/XQ/N+iw1AeD1eqJ93pyIrjXrPwm/RhLEmVrHWcVbUA8B6Big78l 4J/Q== 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=4ozSGrHq2HexpDjX+TcJUPeuPXRXEDV+ZvAEWFSK+Yc=; b=OPY2vTnXf+8oCsEOXlWv892ur3jaZq89TiZ5So3yguIsQTrDMB38fo52WZIKJOjq3U kp62gKO73enRBRDbk9aBOTpgERmmGa7ebG71LBJUGymx0p/5numiq82vOIPDwtMTKofV Y5i/RksMEruj4v4CPEaKtOCkG9epUfnJjncNbJ34lLTTKq3oUtnJ+AGI/50/Vy7RoteL GRP1pAI9Bd2oyC0O+VwYh5VBBDZ46p5xfVULxNcCmxY3qEaWs+tgJa6j5Uw8es7pUyqz ZeuE0Q7/qU2GP3uflRkx4HJQr4LXAQmMYNsCRlOuEs+CODiDtkjl/Yx3BWLGE/gcz5+7 +kfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sr0v2DSN; 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 qh3-20020a170906eca300b007763cc7093csi22703157ejb.884.2022.10.24.05.21.08; Mon, 24 Oct 2022 05:21: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=sr0v2DSN; 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 S233221AbiJXMSX (ORCPT + 99 others); Mon, 24 Oct 2022 08:18:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233129AbiJXMQ2 (ORCPT ); Mon, 24 Oct 2022 08:16:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02F238111F; Mon, 24 Oct 2022 04:56: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 dfw.source.kernel.org (Postfix) with ESMTPS id BA9AB61257; Mon, 24 Oct 2022 11:56:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCEF1C433C1; Mon, 24 Oct 2022 11:56:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612590; bh=XvMEixgT9BGjJ6ja9ttKqMsTyosvpjjoTnATBzIPtLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sr0v2DSNSuxlRxTLOlpgk/J2JaZ9qHC/KlC4qrXAUsZpo8RCUTbPwBMWtvbORqCob mLu7pnJjPX8jy4hm4I0tawz2JsBcn6v0DtF73WfrgQQt8D7TIXcAq/5rbX02ZQyE0/ 9sx4wsqVX2ItyQVEfk1nHA0xGHVi1oZoEzKsnRSA= 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.19 044/229] fs: dlm: fix race between test_bit() and queue_work() Date: Mon, 24 Oct 2022 13:29:23 +0200 Message-Id: <20221024113000.523018503@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@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?1747571539457162833?= X-GMAIL-MSGID: =?utf-8?q?1747571539457162833?= 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); @@ -286,7 +286,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);