Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3087801rwb; Mon, 15 Aug 2022 17:49:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Vz6t3Yfqs+Px2D+ErlY/WyNfJe15bz7e8qrzIIKIIN5gPtJWysawOkH1xwLEtnFbVBTvF X-Received: by 2002:a05:6402:190d:b0:43d:f64f:9a0e with SMTP id e13-20020a056402190d00b0043df64f9a0emr16957140edz.346.1660610993497; Mon, 15 Aug 2022 17:49:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660610993; cv=none; d=google.com; s=arc-20160816; b=Z7yV5EF6MhrZYmQFF1SW34uFBjryOVW/pUEIm0KTk4XRv3mBfEurXo//gZGOKRXTz7 3eG77uet7nKhqc4FAv0xTrHtPmT+519vw70Klj5+jJMwauOprP0EqtbQdRniAloMvEZY jXEXVZQquioWhlPs7x1YhuY0wBeAFMc1QddYCBciWkVFJoU6SPmmdM3Ov3bZan4W4A0u JekvdqJqP9KuGjlnvVVN/uZI+1wa20aCWmtOkZ+soTPogDaA3B5zxPlNIFOXadSLdsJo cR9S0MINrAJN68MSBiSpVcRaRW7AOMa2yv6cX1SecUxSDlNLNKczb6UVGGX2/pEq7zrk VL+A== 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=fFPXJo+s9gdJskhwT9cw9wboWxDV3VetIJXcAs2Ip1M=; b=DdVlGItbXpC8z3+7BZtPDP6XBz7fxc9OOXL2MvVvp3q2n+tOq4lp+4xcK2TNlNSZjh aSvmJxR0YMpm4PWIf4dPPqbeOZj/gvhRZdUbH9/h5T9y2TOz42qmx1kM623ozg3EqNHs lyusJI7UCMp2Ww6F58mnzOhjK45p+KE5FAUyq0AJrTnQ9n7G8+wUnJtJJcQvqHy+RhUr Mdn4zPKjAjSMGZOazM2/hbnUioOGRvsm2YS5Ly1Bs8xCq0GmoFPYM/OYK9srqO2H8FKd i11HJLGiIxCdQdn8nIRiWqvwDTpXi1A963vMsgCZehmTnA3z98gDvIuwZwbM4/Pt/mkC Df6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wZs76aDA; 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 ji14-20020a170907980e00b0072a7935544dsi9182319ejc.325.2022.08.15.17.49.27; Mon, 15 Aug 2022 17:49:53 -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=wZs76aDA; 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 S244798AbiHOW7B (ORCPT + 99 others); Mon, 15 Aug 2022 18:59:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352778AbiHOW44 (ORCPT ); Mon, 15 Aug 2022 18:56:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F0E945F62; Mon, 15 Aug 2022 12:56:05 -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 55DE0B80EB1; Mon, 15 Aug 2022 19:56:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F696C433D6; Mon, 15 Aug 2022 19:56:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660593363; bh=RZkPGZ2e1SCCI60hBb5F8OR1n6Td6wIz5Aoc5W4Umt4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wZs76aDAWLNk5iB6fHXAPGzYIl5V1oYj2s0tsFrIl45XfouzeFZyAvOpxVDl/QFGe Im0MXRIhWanwgLqudprswmt+HF/I+125xAobp8KSeBFIixLZFRRZKKhdArXKg1b+JW obyTExyqIIatmEOZxHbeceUOoz3FHoqQMw+rhbmc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Howells , Jeff Layton , "Matthew Wilcox (Oracle)" , Steve French , Sasha Levin Subject: [PATCH 5.18 0935/1095] cifs: Fix memory leak when using fscache Date: Mon, 15 Aug 2022 20:05:34 +0200 Message-Id: <20220815180507.891590000@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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: Matthew Wilcox (Oracle) [ Upstream commit c6f62f81b488d00afaa86bae26c6ce9ab12c709e ] If we hit the 'index == next_cached' case, we leak a refcount on the struct page. Fix this by using readahead_folio() which takes care of the refcount for you. Fixes: 0174ee9947bd ("cifs: Implement cache I/O by accessing the cache directly") Cc: David Howells Cc: Jeff Layton Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/cifs/file.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 58dce567ceaf..3d475f1847a4 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -4456,10 +4456,10 @@ static void cifs_readahead(struct readahead_control *ractl) * TODO: Send a whole batch of pages to be read * by the cache. */ - page = readahead_page(ractl); - last_batch_size = 1 << thp_order(page); + struct folio *folio = readahead_folio(ractl); + last_batch_size = folio_nr_pages(folio); if (cifs_readpage_from_fscache(ractl->mapping->host, - page) < 0) { + &folio->page) < 0) { /* * TODO: Deal with cache read failure * here, but for the moment, delegate @@ -4467,7 +4467,7 @@ static void cifs_readahead(struct readahead_control *ractl) */ caching = false; } - unlock_page(page); + folio_unlock(folio); next_cached++; cache_nr_pages--; if (cache_nr_pages == 0) -- 2.35.1