Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6811270rwi; Mon, 24 Oct 2022 06:27:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7K4uJWIVzOIcrk7CreThCXSVHanNdNB/jhPKb3o/j4SxB4PTZhTBvCQH3Lic/gf/znbtdk X-Received: by 2002:a05:6402:510c:b0:45d:50f:f65 with SMTP id m12-20020a056402510c00b0045d050f0f65mr30054295edd.313.1666618057135; Mon, 24 Oct 2022 06:27:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618057; cv=none; d=google.com; s=arc-20160816; b=J6DN6P2ofte4dJhno+7C3fUtZScb2IAy5iN/V+XwprRMgEiGGL72S7Yx9PXrcG4v0P tR4B8wYvrQdNa5GlncFTTTjEBWI5zi/dAJ/bIRKv1Eg93y/Dfs6kN/OO5peV8zvuUFT4 lvGIKypt/JeQXEVxbigz8lNjsFHnFmRufbDa5PHXdvaUTotaqwaOXB+Rw2Ufp4O9cbDI DsMeR8HxV/iyMA22vt7viZE+h4+PpdFg7uJ+6D8BWvu9yh3vxiXbmRLyqS8NFu1mVcHI hAM4joC7Rk+DadBcQu0IWZtkTMlxsqjvy+cTgn6sH7ILHEdagZDUD2gWmI9XHkhtEMEX g1qQ== 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=gJFOe55X+VGF0xdlQLQcUwW8/GcWmOQEZhnswYongjbXyxRz3GEAcMT5/5rzNFeumd U1o2ViU6W4tZCd5s30zegGlAI8miW4iSVqPqBvWkupAQ8090mLdqXvqF9qQCZ2bZKJh6 sleQ5aBpKvLfNY29waH1C2Bf5CCFRzB3do1bjddLqF+kdPjbKJlI10bV2g7v8NRc3eT9 ig3hdqxS8NVLqilT7a3YQHXcVLffdpllGMghy95Udhj5Do6DC0TvqdJLo+VC6b0NtKzC CHU+V2wt7dBpd3jnt4Bg5BmoRMZuNctjUgVBes7jhcxpohEO99mpV4+rV/m4RWJD929u 0+Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MLjjHABW; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z1-20020a056402274100b0045c786162f5si6254473edd.567.2022.10.24.06.27.11; Mon, 24 Oct 2022 06:27:37 -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=MLjjHABW; 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 S233495AbiJXMW3 (ORCPT + 99 others); Mon, 24 Oct 2022 08:22:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233017AbiJXMUB (ORCPT ); Mon, 24 Oct 2022 08:20:01 -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 143E77B2BA; Mon, 24 Oct 2022 04:58:51 -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 C73C3612D1; Mon, 24 Oct 2022 11:47:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9221C433D7; Mon, 24 Oct 2022 11:47:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612062; bh=Awcd/0SSmDN83dUDpNoaIq8lTcT014AjU8Qvxm5qHes=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MLjjHABWdhtW9WAWyU+HSDBLufPEEfEv9GZf6A5Wd9Ir5bT0TsVda5caUKDz53cm7 kUv7ra1VrYqq5YF+1ClkPJrOnLawctV1PYofcof9dTE7uQmuJ5qxCBj6QuPOK3iAlR h6Z0K0EAmA1Mzu1RYwtY+cWN0Gm2iHwoJrxxcTxE= 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.14 055/210] fs: dlm: fix race between test_bit() and queue_work() Date: Mon, 24 Oct 2022 13:29:32 +0200 Message-Id: <20221024112958.796344237@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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);