Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3426695imu; Sun, 11 Nov 2018 14:50:47 -0800 (PST) X-Google-Smtp-Source: AJdET5c4bovZvifYQ+X/E7ylk9gWpUHbDB4gA9QkRzHffApzuptpysM2/FhzgYtSk3Xu89x48hWu X-Received: by 2002:a17:902:9b83:: with SMTP id y3-v6mr17282022plp.113.1541976647818; Sun, 11 Nov 2018 14:50:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541976647; cv=none; d=google.com; s=arc-20160816; b=C3XCni1sUpLfiVL9WTPf/xiryWYvCS+/P/6gctlWwX6nwg/QWfTEV9ha+rwg7Sb05p 7T5+dqSFqlvrDQQTjOqM7ocfMULU5+2dHRnWYUMRIpI5BJcc5F4hT2nCuTbD69o6xhUa B0NHq7OE2ovXyqT8fcs/BlAOWxdRbsYgBMUzK0gwdpwomyb3TJaQSaysMpaEmpbpwdzb c2FcM73tyaBjd+QhzcG78RA6MWjQf6lcMeZ9bnvEfWlvWC0jOZAOXEjdUbFAoUJg/wzg kVcnY6k4n7CQL2l0vQ1iZe/0LsvDnfTZFPyvgWrBOp90tT1xrzHlZ/A3tUQcJUjS3n5L EQow== 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=Pal6O5nfrjNCUY2twbXnXcf2RuBjbzp47ISj2hYdmOo=; b=pI+ppXf8JhnFj3NI5g2R3fSjr+4D3NhSodQm/a3+z8QuhYHIKzhmLOmn9wpegUKKNb B6mhQxw4tGIbzh4QgXpJp9ficnsmG6gXKWRuFzo57kfVbuc9tt4dQdvNgRTD124qc5fg XWbXy6NwLr4uZVvTdwJjw2Yf1YqKVjAyu1PD5SstK0JOs5Vqk07XVbqCsqmPR1K7Ibv2 726vnXYUv/mUJxWj7vlC8I4pIO3rCUf2yU1gxJI1iA04kHRKMBDs2goHlMQ/sdOb0Wc+ yeeHHlacSYLn+5pJGencer+e4fsu1g9ZGwbQP1SwlpWYMadr2WdcWWxRr5eK0cKvoRpw AzlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="2MD6rw/z"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y19-v6si15269377plp.61.2018.11.11.14.50.33; Sun, 11 Nov 2018 14:50:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="2MD6rw/z"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390979AbeKLIkN (ORCPT + 99 others); Mon, 12 Nov 2018 03:40:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:54620 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404247AbeKLIXL (ORCPT ); Mon, 12 Nov 2018 03:23:11 -0500 Received: from localhost (unknown [206.108.79.134]) (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 56D03224B3; Sun, 11 Nov 2018 22:33:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975594; bh=pVXAkM+zZjyqIDBXnILz50kWum4ytewBfNzekbPNoGM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2MD6rw/z1iT2FZ+hMTyaIEdaLWqtfiOnzActjbxIkon/XqypJFIVSsGhjhs6UPo0D 8KexB3q1wvk6UxGgQD8ceCwbA153riPFH3PrlGjnqT8z9XNwCnIuVQPn7gNh0WXaG9 MTK7Qo1EMiiYjMGfH6NrjoIIql54UN5dOdOjbf+0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anatoly Trosinenko , Filipe Manana , David Sterba Subject: [PATCH 4.14 212/222] Btrfs: fix assertion on fsync of regular file when using no-holes feature Date: Sun, 11 Nov 2018 14:25:09 -0800 Message-Id: <20181111221705.478284189@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Filipe Manana commit 7ed586d0a8241e81d58c656c5b315f781fa6fc97 upstream. When using the NO_HOLES feature and logging a regular file, we were expecting that if we find an inline extent, that either its size in RAM (uncompressed and unenconded) matches the size of the file or if it does not, that it matches the sector size and it represents compressed data. This assertion does not cover a case where the length of the inline extent is smaller than the sector size and also smaller the file's size, such case is possible through fallocate. Example: $ mkfs.btrfs -f -O no-holes /dev/sdb $ mount /dev/sdb /mnt $ xfs_io -f -c "pwrite -S 0xb60 0 21" /mnt/foobar $ xfs_io -c "falloc 40 40" /mnt/foobar $ xfs_io -c "fsync" /mnt/foobar In the above example we trigger the assertion because the inline extent's length is 21 bytes while the file size is 80 bytes. The fallocate() call merely updated the file's size and did not touch the existing inline extent, as expected. So fix this by adjusting the assertion so that an inline extent length smaller than the file size is valid if the file size is smaller than the filesystem's sector size. A test case for fstests follows soon. Reported-by: Anatoly Trosinenko Fixes: a89ca6f24ffe ("Btrfs: fix fsync after truncate when no_holes feature is enabled") CC: stable@vger.kernel.org # 4.14+ Link: https://lore.kernel.org/linux-btrfs/CAE5jQCfRSBC7n4pUTFJcmHh109=gwyT9mFkCOL+NKfzswmR=_Q@mail.gmail.com/ Signed-off-by: Filipe Manana Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/tree-log.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -4641,7 +4641,8 @@ static int btrfs_log_trailing_hole(struc ASSERT(len == i_size || (len == fs_info->sectorsize && btrfs_file_extent_compression(leaf, extent) != - BTRFS_COMPRESS_NONE)); + BTRFS_COMPRESS_NONE) || + (len < i_size && i_size < fs_info->sectorsize)); return 0; }