Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3468010rwa; Tue, 23 Aug 2022 05:22:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR7yqmbXhlxioc7KMiSnHGj+LM1TWIlC6cNUmh6Q6n3/+MU4zpRq/xtlNPCaF30gpoHHclnw X-Received: by 2002:a17:902:d403:b0:172:9f0a:e591 with SMTP id b3-20020a170902d40300b001729f0ae591mr24580697ple.109.1661257366527; Tue, 23 Aug 2022 05:22:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661257366; cv=none; d=google.com; s=arc-20160816; b=QbPJqQgeZZE4in3U9HGIKCUAu+guU4cDSUPwMUwWVj4EWy4N7yX1a7FESUxd93DLmR GbJSBrULWAkuLnO9CvybEzQkLfdLRqB4s4WDVD/7a9+lHtikh2Gbbh7n49Sh7Es99vfY hVRBgWaTNYLEMCXqpmazHt5VfIxACpSBOEiYJrt0BTmyHYi2yijdXcA7SwFHjARRcXr9 RncgJdIclGOJA1N/Cs33SRgpyYwKfF+B6Yx1Et99NctHY6sqinTNL+1y2cFWHKb/z9H1 pqQM9gKjuY+uUIEaErki0E/LejyUkI8tv+1X+CXhwiwBWOfTwBFKxaIOQDbcJmIh9jhQ q/IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Xq765q7exAkMV77bBrFPtam5XR9ehTGMmkGfWYacR90=; b=h5YsSxMwljn1MgkK95pz50+o9M8kt7D8bNWMeRFmkQugBTxid0HhMdACMBWyhTkNPT E/jSn13FkhK2tsCHbhWKCRDCinb+PEtsv4bZZ3iQFlETmxxQis+CW4PinlwMqm+W4jjw U3dXykBaaBewtCmAabAA76gfVphr0XGUwNa7fcWtJha3phgdBI4y3aZYsw/JqIkc42bP fjglQzltbxhCgal1/hCHw1j6UDVunCfMVAqAyPBuU7/iaFs1ZAyuKNdhIjj6RgZjwGjC ZkwivbzLXBuzyVho/AKkyf+MmL6fGauTgZFIHXpYBmxz3kc5dds1s9XvE8EDKpAfKVDc UNgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hAJXefLt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e16-20020a17090301d000b0016c06a16953si16978537plh.2.2022.08.23.05.22.35; Tue, 23 Aug 2022 05:22:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hAJXefLt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352835AbiHWKJM (ORCPT + 99 others); Tue, 23 Aug 2022 06:09:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352633AbiHWKCO (ORCPT ); Tue, 23 Aug 2022 06:02:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CBC97C509; Tue, 23 Aug 2022 01:50:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 94BA56123D; Tue, 23 Aug 2022 08:50:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DCF4C433D6; Tue, 23 Aug 2022 08:50:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244617; bh=fqxtpDYui42e3oAumHWuDp8Hl2ILf0kVXWlvW13h+cU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hAJXefLtUpO2qMYr4yPCTqAC0g07eg7rXihZ7o/Yt5ZyZyKSa5jjrTWCwLYchyTMk 3XC3X0UtnWrySS+0nO5XiMftoC5AT/1rpxzlHgk6VZhr+ONxUzM7Hnddw53YyhOQjJ HOt+6ctP+gifysQX0OCSOQ03mYAZ17YVKzV8vYes= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , David Sterba Subject: [PATCH 4.14 165/229] btrfs: reject log replay if there is unsupported RO compat flag Date: Tue, 23 Aug 2022 10:25:26 +0200 Message-Id: <20220823080059.557577359@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080053.202747790@linuxfoundation.org> References: <20220823080053.202747790@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qu Wenruo commit dc4d31684974d140250f3ee612c3f0cab13b3146 upstream. [BUG] If we have a btrfs image with dirty log, along with an unsupported RO compatible flag: log_root 30474240 ... compat_flags 0x0 compat_ro_flags 0x40000003 ( FREE_SPACE_TREE | FREE_SPACE_TREE_VALID | unknown flag: 0x40000000 ) Then even if we can only mount it RO, we will still cause metadata update for log replay: BTRFS info (device dm-1): flagging fs with big metadata feature BTRFS info (device dm-1): using free space tree BTRFS info (device dm-1): has skinny extents BTRFS info (device dm-1): start tree-log replay This is definitely against RO compact flag requirement. [CAUSE] RO compact flag only forces us to do RO mount, but we will still do log replay for plain RO mount. Thus this will result us to do log replay and update metadata. This can be very problematic for new RO compat flag, for example older kernel can not understand v2 cache, and if we allow metadata update on RO mount and invalidate/corrupt v2 cache. [FIX] Just reject the mount unless rescue=nologreplay is provided: BTRFS error (device dm-1): cannot replay dirty log with unsupport optional features (0x40000000), try rescue=nologreplay instead We don't want to set rescue=nologreply directly, as this would make the end user to read the old data, and cause confusion. Since the such case is really rare, we're mostly fine to just reject the mount with an error message, which also includes the proper workaround. CC: stable@vger.kernel.org #4.9+ Signed-off-by: Qu Wenruo Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/disk-io.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2718,6 +2718,20 @@ int open_ctree(struct super_block *sb, err = -EINVAL; goto fail_alloc; } + /* + * We have unsupported RO compat features, although RO mounted, we + * should not cause any metadata write, including log replay. + * Or we could screw up whatever the new feature requires. + */ + if (unlikely(features && btrfs_super_log_root(disk_super) && + !btrfs_test_opt(fs_info, NOLOGREPLAY))) { + btrfs_err(fs_info, +"cannot replay dirty log with unsupported compat_ro features (0x%llx), try rescue=nologreplay", + features); + err = -EINVAL; + goto fail_alloc; + } + max_active = fs_info->thread_pool_size;