Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2446549yba; Mon, 15 Apr 2019 11:48:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqw48wjzy6FdBf5yRrfJKDi9g0kBVRS4ASaCEJVhakSzFkc6wgrgE+fS9dDtFX2fMYgZfAp0 X-Received: by 2002:a63:7d03:: with SMTP id y3mr71472053pgc.8.1555354138868; Mon, 15 Apr 2019 11:48:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555354138; cv=none; d=google.com; s=arc-20160816; b=Ya/qrx6uN+ra3IimxYvfKuI9M9K1VKIA8hWu+y1fGfljeqO0C4pFcGxODJZ4T4Wg6q tNPwWlz2CwP7ORy7t2MhkyK/emlnpxQk21hBI8nIai6APweb8nCdE0bhUz1sBe3Fo6Al vB1rlL5GoU14FR/FkkI2D6aP0Ho1WQqQ9ZPTJfr5CcL7ZCI0Zj1UMKdihnMm0KyRLc3c iDAKUAlk8vVGUmVET2os2EBtdWiNf22CeT8md6i4m1QnuyhCt9rtX68pL69vLEFjt+ik GDs1YynwtQvByJdknEm/85LUkR9xpY93v6I9pHqcOmlB1q8vvpsAVg+zh7t9aA3R36/X cEUg== 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=tOKwhwKn6mE48BqN1J5RCNLHYVhhLsQN+1WRo8g9RHg=; b=gMDu7LmLHVfjn2sH6gEXRi7OvBdpad+54NHXXjRYCxjG6IwGKKcE55UG+FgYIbxd9/ A2Y01asyxf6s95cp9pHnQ5GGvjv7CI2yDrJETQ/cgAKzfAVUXTL/9EshBD975iJ49Oaa epTf2HMNhP8FqfG1F1HuwkeafoUxF8FFZkIFiYX26UpmFMwrcbgWm814RksjkzdN1Y/8 h0kb3/C9H5QBLNQq8hEnd/y5I4p63SnO7FRUte+/7xbXWMX56SdxG6V8nbvJJ8sFnfc+ 6pFqI64gu8pjHhO22PUIAq15czjT4LtldNaM3qj3JOLji2o96vnTfFQfpHu7wXhNsO36 Gezg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="VB/5s80d"; 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 i1si43516015pgq.528.2019.04.15.11.48.42; Mon, 15 Apr 2019 11:48:58 -0700 (PDT) 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="VB/5s80d"; 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 S1728940AbfDOSrb (ORCPT + 99 others); Mon, 15 Apr 2019 14:47:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:50834 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728425AbfDOSr2 (ORCPT ); Mon, 15 Apr 2019 14:47:28 -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 AF42B2087C; Mon, 15 Apr 2019 18:47:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555354048; bh=C6y9KtlxXmI/CqXaNTxmOlLp3ZvmluzKVmgnf0Fx+jo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VB/5s80dhW97E0Sqb8h0j4gObAg65SuqYFx0vKagjhspOLPgbWtcwJnoA1LnG6D9V IofNfybI1zk1wraqlYDMcV2XPVVOkSL75lKUR/vwJC+O7IfHUkhTfqlKw9CgOSCgw9 MpOzgBIhgCwB/YOLuWSuoT7f0TfFUg44nftDqZnA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Darrick J. Wong" , Nikolay Borisov , Filipe Manana , David Sterba Subject: [PATCH 4.9 67/76] Btrfs: do not allow trimming when a fs is mounted with the nologreplay option Date: Mon, 15 Apr 2019 20:44:31 +0200 Message-Id: <20190415183727.653792862@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183707.712011689@linuxfoundation.org> References: <20190415183707.712011689@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: Filipe Manana commit f35f06c35560a86e841631f0243b83a984dc11a9 upstream. Whan a filesystem is mounted with the nologreplay mount option, which requires it to be mounted in RO mode as well, we can not allow discard on free space inside block groups, because log trees refer to extents that are not pinned in a block group's free space cache (pinning the extents is precisely the first phase of replaying a log tree). So do not allow the fitrim ioctl to do anything when the filesystem is mounted with the nologreplay option, because later it can be mounted RW without that option, which causes log replay to happen and result in either a failure to replay the log trees (leading to a mount failure), a crash or some silent corruption. Reported-by: Darrick J. Wong Fixes: 96da09192cda ("btrfs: Introduce new mount option to disable tree log replay") CC: stable@vger.kernel.org # 4.9+ Reviewed-by: Nikolay Borisov Signed-off-by: Filipe Manana Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/ioctl.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -385,6 +385,16 @@ static noinline int btrfs_ioctl_fitrim(s if (!capable(CAP_SYS_ADMIN)) return -EPERM; + /* + * If the fs is mounted with nologreplay, which requires it to be + * mounted in RO mode as well, we can not allow discard on free space + * inside block groups, because log trees refer to extents that are not + * pinned in a block group's free space cache (pinning the extents is + * precisely the first phase of replaying a log tree). + */ + if (btrfs_test_opt(fs_info, NOLOGREPLAY)) + return -EROFS; + rcu_read_lock(); list_for_each_entry_rcu(device, &fs_info->fs_devices->devices, dev_list) {