Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3469123imu; Sun, 11 Nov 2018 15:49:17 -0800 (PST) X-Google-Smtp-Source: AJdET5fqjeQs94PiJ2oqG+t7th1bczIkJeBBRX403YrP0MEGv4ZG8U29UpJV9J1onFIZ1HhTNpTs X-Received: by 2002:a62:4641:: with SMTP id t62-v6mr18028772pfa.200.1541980157323; Sun, 11 Nov 2018 15:49:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980157; cv=none; d=google.com; s=arc-20160816; b=W/txTZC4tlCIJyKUTrH4GDYfduCfjoViaUqBUyzJItjQ2N0+GSmhSMWGnLGkr2PRI2 cDTfTKu3wAmlG7gM7TXQpFrluy9NbqN3T8tcGYuIGerWfwsYrDRXp0ekQviN18uFAWOu 1lJPLv2tIASn27sG/S86Sxdi0X3+fHxRX3AeBjgq8fQ2YEz6vzBaBbQIOBecnRbDRcLK /kdPSxaSZQ1pbumSav/XmNfA4v9U/iUDJMgKC8NzHQxi+xa6BzI8RXSAP1CZYje5fm+9 +1fkXP/qeMIzT27d2N4Zf6PxQA4z/Nt0da7aDVyT4U633xfYs/UHH4rpKB6slKwxOGls 7efA== 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=ps5328SKsS2Z7D9/AsarLtmZf6624k2ubDLZWrWTjxE=; b=W3wAuj4CAQ6EEourEG1bbhBNxSAdhkM2hCAukrxzvVpVAH5R/CFPKZftAcMJ61iK7t RZrS9zm56Lz+t8ILu7HbCSzaUuxtds4L5BOjQU08eibsPJQxvwcswWe1xjJYphDF0Xp+ /SToAEgeqxxd+anelRHoQtkfMnsCbVrU6Tm7xtG2aerzaDCzuT8URoRhgTwPNgils4qU A7pgpFXXiUVGlrL34gTLmTt1Er45kE46GohxHQ6sUAeNemJ776A3Rcn6+hgcF/TlQ5oO 5/ELlPz+o4yPsq9QPSPQdGoE5C8SieClV+9YMPRHPKyefrbiGXaPJh0Y2jJNpROHXZ+3 SU1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gNyU5QcC; 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 f7-v6si14331157pgh.159.2018.11.11.15.49.02; Sun, 11 Nov 2018 15:49:17 -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=gNyU5QcC; 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 S2387524AbeKLJht (ORCPT + 99 others); Mon, 12 Nov 2018 04:37:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:39292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733160AbeKLISs (ORCPT ); Mon, 12 Nov 2018 03:18:48 -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 C4AED21582; Sun, 11 Nov 2018 22:28:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975331; bh=CDkNUAtlhT6VF4u168mUcWyUPJIPGhijKtHBfnTLbts=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gNyU5QcCmAO86aPFsk2tfA3rV6MS0xYEIi5T+vSfDTYN1g6rKnibnybTyc0eg+sdP rAAccU4hMqoiNPvGUfyAsA/oKwR9LRU9rSVGAFulbtF/f6rw+tUz7ZCKLxWyesN6oe Bz+h6TPi1/06+vgVpH7WDRd4VxKgCD6W9tgrGCgM= 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.19 346/361] Btrfs: fix assertion on fsync of regular file when using no-holes feature Date: Sun, 11 Nov 2018 14:21:33 -0800 Message-Id: <20181111221701.130926155@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@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.19-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 @@ -4655,7 +4655,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; }