Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4876819pjb; Mon, 27 Jul 2020 07:23:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsIr2hqJsFcFoIXU5fE+02CIjY6ym+6r3XM3j3YqP8rnSjALlDb84si0wZK8n78yLapuEh X-Received: by 2002:aa7:c0d8:: with SMTP id j24mr9488518edp.338.1595859832140; Mon, 27 Jul 2020 07:23:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595859832; cv=none; d=google.com; s=arc-20160816; b=YegKC3ifyfpzNoMTQyBt2VqV70VXQFNrF8VBHUtrjiWH5XN3MmHmlZxPtBqr0vsB+D v4uoRuOzXTd0vUGKukNouzUyAJp9aM7ZUpZuQ2XE9qsQS7LueODE9nknt3Fsl1QCkT3A 27hhVrHC5vd8CHwA7GMoE1b5I44nnq4YdQTThBsUpOLPWEe+ajQXBYZtQPgkmqymUhIl NvT1aochJIr+nYpE6zp5DTiO/m6lwzIh2Z47kJh2jOGXK5gpe7x56uoenSqR/KRACF5G pEVvI4jOEnCc9GTjiiqCWxAHDixNGEUKAXWyLRjIZfB8aCBILp+32rKkrGPcRj5jHrUm JoOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SS3zMsi2oPzYAagCmheaCJZQ7Qyb/UAOf6k1G9eQqK0=; b=RPU0tK9DrEGqNz3YvO1Qa1OXLQsY5ToifjxbWl8/hrrvGvGvCDbAhRZ63iKiD4I059 4gcgE7B0sKrrb9sQB7bKVNDTJRRjo1lZXmfBXDLCLjnPeO7Iaf1zwk/M1LpB6QOMspVd qYnPLwATAKGpxqNzcUe64gGeaA8jIEWiQBE5iQlDgXhdvmCeTfIwPYISXDRnQ4qv+C98 fCwJQ4c6Xn/neuRLmmJapRQ4AmaELcoAVCVDXmCpyiEspHaN5xv66/LAXnfWZha43Jts 0tTgMJKCyHvg79+aT8uJaVS1agneHUwmuEQYHT9cuMi4S25O2L0GDuPx4IjQmg6avbau 9WDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=THfHzLVM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j5si5773585edk.83.2020.07.27.07.23.29; Mon, 27 Jul 2020 07:23:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=THfHzLVM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729873AbgG0OUU (ORCPT + 99 others); Mon, 27 Jul 2020 10:20:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:48494 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730983AbgG0OUT (ORCPT ); Mon, 27 Jul 2020 10:20:19 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 063B72070A; Mon, 27 Jul 2020 14:20:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859619; bh=UbrhK8raAGl/tgRM7NvsEH1DQh0Hx4h2ZnCsXset6dY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=THfHzLVMSGiqdARziOxUMoZqpJFvfRvliUIvxN27TVrltCmAS8ztVf3gz8394H8+O ftlaEuQO2SVrU60utsHwAUHTuXjx2/qBNxnnX8Na4eBM8e8tVA79RU9gLinKSK54NY 02VG13TVGhg3VH1eD43CdEr+wkv8Kl4JQI2gzw+Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , Nikolay Borisov , Robbie Ko , David Sterba Subject: [PATCH 5.7 040/179] btrfs: fix page leaks after failure to lock page for delalloc Date: Mon, 27 Jul 2020 16:03:35 +0200 Message-Id: <20200727134934.628527557@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134932.659499757@linuxfoundation.org> References: <20200727134932.659499757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Robbie Ko commit 5909ca110b29aa16b23b52b8de8d3bb1035fd738 upstream. When locking pages for delalloc, we check if it's dirty and mapping still matches. If it does not match, we need to return -EAGAIN and release all pages. Only the current page was put though, iterate over all the remaining pages too. CC: stable@vger.kernel.org # 4.14+ Reviewed-by: Filipe Manana Reviewed-by: Nikolay Borisov Signed-off-by: Robbie Ko Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/extent_io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -1999,7 +1999,8 @@ static int __process_pages_contig(struct if (!PageDirty(pages[i]) || pages[i]->mapping != mapping) { unlock_page(pages[i]); - put_page(pages[i]); + for (; i < ret; i++) + put_page(pages[i]); err = -EAGAIN; goto out; }