From patchwork Wed Oct 19 08:22:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4522 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp203369wrs; Wed, 19 Oct 2022 01:42:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM479J4Bdn+nUeXhRsDOYLAbpyFI7djJy+7ZYgXKV5oVWgDokX2RgsJmfPrpQle6MfYcv4kc X-Received: by 2002:a17:907:2672:b0:781:dc01:6c5a with SMTP id ci18-20020a170907267200b00781dc016c5amr6008216ejc.191.1666168978002; Wed, 19 Oct 2022 01:42:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666168977; cv=none; d=google.com; s=arc-20160816; b=LbkcQZFUE89E7CcpjlMhouUsrUmRIVB2QB/nyn9OSbKRAwBs2Pachl7VbgebqqVkgh WFyawA2X1JIHLTljBpmtn32GnDrES0KACKWVnIknAEcbSD+zfGSO5b4tmz4DjtaQJyeK 3nwpHjreF0zbatkxQfaRTrUgOEyrvbexCGAYZswOvRZofw6GsALH45VRiut84szEWbFU EsHlccV9b9DvdWqdU9gl4jVmRcXRoNhQ/HKXqVI5BJbYnglZ7pF8GQLFN8gijVbPxugN /z1DjKgSLwvFMiFb85wkpgC01ESXPXAnIPCNBZZL8KK9Dgc2V+7/+QMtvnZaVtweAsJY 8TAw== 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=beQ5xwVOQa1mgGiZ0l1JCvcMt6y0k2gEADuQr2W0T+drxnTHIuUi+wtE8X8SRfq2qE E3kIyor3g60oeQTApyoE0IImoctcAyNFqX4FgaXdJj+X5lLJRvygmoc/Y2U7CZhw00iw WLR1l2kgdMQKd6A3OR9ZWU6oqaeNSO/zQtbjS/ZAXhKbmbe9H/di7hOWa+q/czBV73Dw Q3UHe1ED4cCSh/5plW9wuV3/z1oT8DDnApoR+aTdepbmAYZm8gyccCR2NvrqWMP/RSTv igCzfJBHLSAGcgixFJjETic4KEGMA1FwoyZqRN+SPWTyjSEBOsjYj52ef71ZalgMmBvA eLXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wrffrh7X; 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 gs41-20020a1709072d2900b0078e030224fdsi16238162ejc.768.2022.10.19.01.42.32; Wed, 19 Oct 2022 01:42:57 -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=wrffrh7X; 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 S231153AbiJSImI (ORCPT + 99 others); Wed, 19 Oct 2022 04:42:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230408AbiJSIku (ORCPT ); Wed, 19 Oct 2022 04:40:50 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1939680F7D; Wed, 19 Oct 2022 01:39:13 -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 86E12B822D1; Wed, 19 Oct 2022 08:39:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE511C433D7; Wed, 19 Oct 2022 08:39:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666168747; bh=jBoTbudxBixvFylnCwkGubpi1p23EEKMHTLT51gJ8yc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wrffrh7X06cksoPcc86hWA3se0axooEjBP8G1e6B0cXxnbQBoMrKbKURE2UTyWdMJ AH1vIvL5p5hU16p32zzCTkcDPCyved0+6RyXAUVF5jjDzdwyjZR1HeFTUYLBM7tXTh XZ8LCWr3+gqgRtYXO8YsTOD3Ve6KjY+U048cT24w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Aring , David Teigland Subject: [PATCH 6.0 041/862] fs: dlm: fix race between test_bit() and queue_work() Date: Wed, 19 Oct 2022 10:22:08 +0200 Message-Id: <20221019083251.817711321@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747104802542021842?= X-GMAIL-MSGID: =?utf-8?q?1747104802542021842?= 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);