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=-6.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,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 E5AE1C10F0E for ; Mon, 15 Apr 2019 18:47:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B3AEF218DA for ; Mon, 15 Apr 2019 18:47:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555354050; bh=C6y9KtlxXmI/CqXaNTxmOlLp3ZvmluzKVmgnf0Fx+jo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=y7oPNpdvcCz2wGZ5bvwD99dm3B/5WLKR2xzkAjjrZDc4e1Ej39IlLUJt+wgB5l1JO jjyFA6JWZUv3z6u0P/chvVR1CykZvQU2Di2e1iP+gahajyKFyF/9oVkMFUxtbSgtn5 r/AeGhQTfpueIVNzMTOLF9eBWIHgEZg+6wLD6vrk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728918AbfDOSr3 (ORCPT ); Mon, 15 Apr 2019 14:47:29 -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: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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) {