Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3397137rwa; Tue, 23 Aug 2022 04:13:15 -0700 (PDT) X-Google-Smtp-Source: AA6agR7SK2vPFS8AuJRFpN7TJGtHpBVU8ueFqIwAwRLkc3A2neATkwom92Ff1dsGoMuq9OrLYisJ X-Received: by 2002:a17:90a:fe1:b0:1fb:28b9:3f13 with SMTP id 88-20020a17090a0fe100b001fb28b93f13mr2803253pjz.88.1661253195149; Tue, 23 Aug 2022 04:13:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253195; cv=none; d=google.com; s=arc-20160816; b=j1J4klaQRL4ZHCaiehEF9IbRhpzgyoaflrNc8z06hf5g5FFSW65mLaYtvYNnxM0Ezi Ms0oSW+B/JJN3dZBFvCfpb1GdOQWJyt2KbDNSW9PokxGcVeMWoZNTRTO45aOV1UHTIrW qFCt85bl35x6jhlK85/qaKVO0QSXyYRpmwa7sPvENalgPEidKj2OXl58tsgt9B1xBzxu ZeZ/0jPICdKGS95O/zHjBwFk3pg+0CJWq6zU+otV4Z1SlyxFAMLG0ePcIkKvGCzupLtv wOelHUpWOoeQJWvd1nLG1VYzBy06o+B39El1F7nIlsb4ijKYnQhqHNspcK8bhTk2f5DQ /Nlw== 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=/I/wrMx5cjR/6tsaq9k1IodiE8uTlYsO+DwDTBk/KAM=; b=0je51fAIJIe7TFxQDloYboJGYdq9ziNpMQsY+Rx/xkaEYxvZFQeSzNhP9CEsDP1XOL 3/Oi56FPK4Ycscd/Rd3cPvLSEQtPJHl6XuH6uiw1FlCjr3SM5+Ch2/YoXIn1GTn5Ey1d X/FW5L0hJYeyfYWbdQW3L0OhXKSUw9ApCh3vC04VM3PINtITfqRi1Z3U7qxgChdO0GCO 9zuf+nGDMoczkZdoZHNob45VygfqFag6d4R/7JaG6t/7/j8Vv2lPxE4wBFVJPRmRBUKH yanJNWHd5jsi604Wg5D5KUdZ9wm8++URYbvaG08yCSHSC7BJGYz4tpjQgLIqlGRGVtp1 oUJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mHs0RuaF; 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 z9-20020a63d009000000b00429cf28b83dsi15258182pgf.396.2022.08.23.04.13.02; Tue, 23 Aug 2022 04:13:15 -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=mHs0RuaF; 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 S1345281AbiHWIoD (ORCPT + 99 others); Tue, 23 Aug 2022 04:44:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346705AbiHWIk3 (ORCPT ); Tue, 23 Aug 2022 04:40:29 -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 5E1785F23F; Tue, 23 Aug 2022 01:18:49 -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 2F22161321; Tue, 23 Aug 2022 08:17:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1ABFCC433C1; Tue, 23 Aug 2022 08:17:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661242645; bh=GOO6yS8sqZfWknrUvzaIwJRwSqyMq+57shxE+fO7O2Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mHs0RuaFD73IhUymSU4FpXwCBmPlN8B4ESMLOPvyLlais20CycC2UrVqA4XN3AZvL dJd8h/J+GxanPbPe0KFFwt/GPe4KDKYKzaH74w71xEpV8ulkUrf793SIE/OVbdA90K OBcP8s4E6a0kYdTs7P5su//a4jytK+tmrvtO21Kw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Howells , Jeff Layton Subject: [PATCH 5.19 152/365] fscache: dont leak cookie access refs if invalidation is in progress or failed Date: Tue, 23 Aug 2022 10:00:53 +0200 Message-Id: <20220823080124.585754011@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@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.1 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,T_SCC_BODY_TEXT_LINE 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: Jeff Layton commit fb24771faf72a2fd62b3b6287af3c610c3ec9cf1 upstream. It's possible for a request to invalidate a fscache_cookie will come in while we're already processing an invalidation. If that happens we currently take an extra access reference that will leak. Only call __fscache_begin_cookie_access if the FSCACHE_COOKIE_DO_INVALIDATE bit was previously clear. Also, ensure that we attempt to clear the bit when the cookie is "FAILED" and put the reference to avoid an access leak. Fixes: 85e4ea1049c7 ("fscache: Fix invalidation/lookup race") Suggested-by: David Howells Signed-off-by: Jeff Layton Signed-off-by: David Howells Signed-off-by: Greg Kroah-Hartman --- fs/fscache/cookie.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c index 74920826d8f6..26a6d395737a 100644 --- a/fs/fscache/cookie.c +++ b/fs/fscache/cookie.c @@ -739,6 +739,9 @@ static void fscache_cookie_state_machine(struct fscache_cookie *cookie) fallthrough; case FSCACHE_COOKIE_STATE_FAILED: + if (test_and_clear_bit(FSCACHE_COOKIE_DO_INVALIDATE, &cookie->flags)) + fscache_end_cookie_access(cookie, fscache_access_invalidate_cookie_end); + if (atomic_read(&cookie->n_accesses) != 0) break; if (test_bit(FSCACHE_COOKIE_DO_RELINQUISH, &cookie->flags)) { @@ -1063,8 +1066,8 @@ void __fscache_invalidate(struct fscache_cookie *cookie, return; case FSCACHE_COOKIE_STATE_LOOKING_UP: - __fscache_begin_cookie_access(cookie, fscache_access_invalidate_cookie); - set_bit(FSCACHE_COOKIE_DO_INVALIDATE, &cookie->flags); + if (!test_and_set_bit(FSCACHE_COOKIE_DO_INVALIDATE, &cookie->flags)) + __fscache_begin_cookie_access(cookie, fscache_access_invalidate_cookie); fallthrough; case FSCACHE_COOKIE_STATE_CREATING: spin_unlock(&cookie->lock); -- 2.37.2