From patchwork Mon Oct 24 11:27: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: 9025 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp441551wru; Mon, 24 Oct 2022 06:06:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6bjOVu/2wF2WXCHKpOwV/x0jFh5w1oaE3g/vluoWMC836kDN2RvLpWjnKJKkyK/beiq0Dq X-Received: by 2002:a17:903:186:b0:182:ecf9:6227 with SMTP id z6-20020a170903018600b00182ecf96227mr33868263plg.70.1666616763092; Mon, 24 Oct 2022 06:06:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666616763; cv=none; d=google.com; s=arc-20160816; b=GX2KaULf3fk4hwsxiOofc3XCm5K2o6Ho09KfIcyDH/VNtxiUdgokMDnBXLR6S6K7aP wuvikbB9gQ2mR+iu2nNaIeBA/SmOWIOrgSxkD7yjwCKyULaKV+6xW1fXuOG+LmkSdh1x MUxN4+zrKmhNs83EqYoAqlortj+x5VDmqHVdmLZBwixMONibPFFoWUUHU1DO5Rfre5L2 gc0l61GGCof1QM+Cz9KOqsB5Ld8ownUhNaEy6Zrv6M7sN20t9wJVRu53a4Wjz+cEBgDq 3cpN5Ytn5n1Bhk18TKJn09DU/+5APuAKGpiAWB8nWHzztwLeehFlYLQgy3HR/uUX8fcc xcmA== 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=ViLFRyJjUhkY+N7uH347J7uACmwNAk52A55gtuPvvA61beGPW5XfX+m8HFs1zceKXe gpUumAlykmD4mnBl9XbKi/YmNeX+ukMHcpjBLWZafazdR+gk+f2htc0YZUf1KY40yQf8 q6QMjthDIs9GlLydUaR66VuoYRKg3xDZmSFyFCMJ0TitIe2dqiUcgh+r3dJFAVG4zOZP Jed8ABXjRxFzRBdsoRpWVhG32TxEceaCeD4cb56jJJI96j5gMfgjsjPa6EEZcKk4hbO7 aEHF3prZSmDGzFuwuLivKxXUODtQMcvSnYjhSS940iZGSgto9/x3gZngW5pMWKQ5obWf mKIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fgOdXZXW; 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 mg22-20020a17090b371600b002131849ea4esi2514659pjb.140.2022.10.24.06.05.39; Mon, 24 Oct 2022 06:06:03 -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=fgOdXZXW; 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 S235018AbiJXNE6 (ORCPT + 99 others); Mon, 24 Oct 2022 09:04:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235113AbiJXNBZ (ORCPT ); Mon, 24 Oct 2022 09:01:25 -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 D4FBE2613F; Mon, 24 Oct 2022 05:19:46 -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 67B7F6129B; Mon, 24 Oct 2022 12:18:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C032C433C1; Mon, 24 Oct 2022 12:18:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613889; bh=Awcd/0SSmDN83dUDpNoaIq8lTcT014AjU8Qvxm5qHes=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fgOdXZXWvmuZEbsVKqvaoxIjR2SiFephtXXyEYO/34tlZP0q1IRVWx/dfZiYZCBmv bU2gu+otncjJ2YkVfGEHSDWbSSqqHPlN0IGiN2cB9GCtHmj1eME0k9nrAZSz8kRlr7 kCKfylLA3AihoiUPN15r/v+++a7nCBZw8z7+Vd3o= 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.10 023/390] fs: dlm: fix race between test_bit() and queue_work() Date: Mon, 24 Oct 2022 13:27:00 +0200 Message-Id: <20221024113023.535702880@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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?1747574339122091259?= X-GMAIL-MSGID: =?utf-8?q?1747574339122091259?= 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);