From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52413C433DF for ; Fri, 19 Jun 2020 16:31:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24F322100A for ; Fri, 19 Jun 2020 16:31:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592584294; bh=4N8wtzWv9c/QUTi9qkJFY+daci7BxXq2OJdDmp6Ojjg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=q/fXvFshTkSxkl2eUVKwMASCPhNVJtZNLY1Qf/sYK+y6VpXgB7jGavwLK6R4+grpx q1PQxWYF8DrhzvEJMQbnG9DnPLhxRQVotePKcG8ktRy6BLEp+qI6Wbro1nbKuCcJJ3 hK1qVkMCBOYhTWjLADCt6M4Oxlc3e641JOvcJuCI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389637AbgFSQbd (ORCPT ); Fri, 19 Jun 2020 12:31:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:47020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389243AbgFSOwv (ORCPT ); Fri, 19 Jun 2020 10:52:51 -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 CECD321556; Fri, 19 Jun 2020 14:52:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592578371; bh=4N8wtzWv9c/QUTi9qkJFY+daci7BxXq2OJdDmp6Ojjg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PDMYyxNCbj/KncgDhiJAO3W8BTidkL6m9UTwvZ6WKpQgredVQJ4V2UDVsVlFYs1zZ OhlFS2wtgey+In81+2o7wAL14GGL9dRWzvj7kBcXo8FU1aVQ29L8jZyq1NGQt3Fqy/ fW3VUglObvve7mq3KhWvcZNtoRJilJbdsQ9WEVDs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , David Sterba , Sasha Levin Subject: [PATCH 4.14 160/190] btrfs: fix wrong file range cleanup after an error filling dealloc range Date: Fri, 19 Jun 2020 16:33:25 +0200 Message-Id: <20200619141641.747839926@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141633.446429600@linuxfoundation.org> References: <20200619141633.446429600@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Filipe Manana [ Upstream commit e2c8e92d1140754073ad3799eb6620c76bab2078 ] If an error happens while running dellaloc in COW mode for a range, we can end up calling extent_clear_unlock_delalloc() for a range that goes beyond our range's end offset by 1 byte, which affects 1 extra page. This results in clearing bits and doing page operations (such as a page unlock) outside our target range. Fix that by calling extent_clear_unlock_delalloc() with an inclusive end offset, instead of an exclusive end offset, at cow_file_range(). Fixes: a315e68f6e8b30 ("Btrfs: fix invalid attempt to free reserved space on failure to cow range") CC: stable@vger.kernel.org # 4.14+ Signed-off-by: Filipe Manana Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 3e65ac2d4869..ad138f0b0ce1 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1139,8 +1139,8 @@ static noinline int cow_file_range(struct inode *inode, */ if (extent_reserved) { extent_clear_unlock_delalloc(inode, start, - start + cur_alloc_size, - start + cur_alloc_size, + start + cur_alloc_size - 1, + start + cur_alloc_size - 1, locked_page, clear_bits, page_ops); -- 2.25.1