Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3706053pxp; Tue, 15 Mar 2022 04:48:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZmjP2iQ8BqAdc1SBP+sKMElfGEh+TK5CxfDgXMgnNeZk5pdaOMZHsiouDbzNcB86mjgay X-Received: by 2002:a05:6a00:1501:b0:4f7:5773:f3f6 with SMTP id q1-20020a056a00150100b004f75773f3f6mr28503729pfu.31.1647344924737; Tue, 15 Mar 2022 04:48:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647344924; cv=none; d=google.com; s=arc-20160816; b=ZRXXsuGCRNLCO1dVOttMUXDLDhIyvGhIB1BKuLO5fF007j8xr6FSecDjtJdAUEpE1g ftrVi+CTWzc5HKB4HNI5A5RJduY+Xrtx7ASOioeg90u/V3Yj+AVn5YdtX0y3Tq62cMpL y+dGakn+bwLjT5hl/W2OpENW8TE6AepkFZdelfhbLgu/9TaDFFmrODMNdXlMCQkFXXOw IIToWQ4d4OFKO2LWq1nBOt8MdiWf/mz7xbFMZNlduppAvH8cZVdc/iQxTsM6KIbXPwpJ W+pNqawZ+0zF4K51Ex1ezA/3UWSloMZ5O3hZRMvtMi/05cSkRRqWWc+6lZ4qWLZ/qn0h 0ThA== 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=ABHlOOJPkefEpvH3ARM7vDziIJjCnKOyRKPafDabbpw=; b=PmBSd0Txctr5EZRBPbf4ZUc/XfpuLex+KR0tJOGtw44oebKAVp7KvKD435YM5FcRx/ iL0RAOhqWz78mSRbB5vzA2Iog7sbSKHFGfOz/CvjBZ4oLjOntmJYTfUpnWsSuxVZriR/ iYKjtGnV6yIY365sN3sQLGx6ErFXS7aiI+y71XHQsGmp8Si97e8slYRPBxGeCOZALAM2 Y1cQs3ctzSnp+uDfEYO65VJTe/+2/6ZoZRJbNhBdJdvYp4iU94ZRGVNJYUI0FdY4K7Ji KHVfjZ3cAPhHWctGW+hKSxCMRuE9OaNX9r+cfmUE+so/GkY5U2bLjo5viE9Vo5flFAe5 7wTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=u1CxWxz+; 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 i15-20020a17090ad34f00b001bd14e01f23si1621228pjx.17.2022.03.15.04.48.31; Tue, 15 Mar 2022 04:48:44 -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=u1CxWxz+; 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 S239696AbiCNLm5 (ORCPT + 99 others); Mon, 14 Mar 2022 07:42:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239472AbiCNLmh (ORCPT ); Mon, 14 Mar 2022 07:42:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAD1349F80; Mon, 14 Mar 2022 04:40:03 -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 B08176117C; Mon, 14 Mar 2022 11:39:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7CB22C340F8; Mon, 14 Mar 2022 11:39:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647257987; bh=M8ax33quUGmZY4WEvx5nH5KNIApyPzylG8aYXe9hmrg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u1CxWxz+x+PIdUPP/J6r40Lu2J6h7FXpI8XhfqC7RJHswjDZko7Nr2kwv5LKcEiet N1vLwKsMqdVD3UdP0MWZL1cNSNbgHuGGRD4NILFtbEhZ5fJvytSyH5yyGUbAh9WMbX 9wJq/9QrQ3bv0Tbu0gKs7M4VhUyet1J8mNCR7mjA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josh Triplett , Theodore Tso Subject: [PATCH 4.19 26/30] ext4: add check to prevent attempting to resize an fs with sparse_super2 Date: Mon, 14 Mar 2022 12:34:44 +0100 Message-Id: <20220314112732.532033976@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112731.785042288@linuxfoundation.org> References: <20220314112731.785042288@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.6 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: Josh Triplett commit b1489186cc8391e0c1e342f9fbc3eedf6b944c61 upstream. The in-kernel ext4 resize code doesn't support filesystem with the sparse_super2 feature. It fails with errors like this and doesn't finish the resize: EXT4-fs (loop0): resizing filesystem from 16640 to 7864320 blocks EXT4-fs warning (device loop0): verify_reserved_gdb:760: reserved GDT 2 missing grp 1 (32770) EXT4-fs warning (device loop0): ext4_resize_fs:2111: error (-22) occurred during file system resize EXT4-fs (loop0): resized filesystem to 2097152 To reproduce: mkfs.ext4 -b 4096 -I 256 -J size=32 -E resize=$((256*1024*1024)) -O sparse_super2 ext4.img 65M truncate -s 30G ext4.img mount ext4.img /mnt python3 -c 'import fcntl, os, struct ; fd = os.open("/mnt", os.O_RDONLY | os.O_DIRECTORY) ; fcntl.ioctl(fd, 0x40086610, struct.pack("Q", 30 * 1024 * 1024 * 1024 // 4096), False) ; os.close(fd)' dmesg | tail e2fsck ext4.img The userspace resize2fs tool has a check for this case: it checks if the filesystem has sparse_super2 set and if the kernel provides /sys/fs/ext4/features/sparse_super2. However, the former check requires manually reading and parsing the filesystem superblock. Detect this case in ext4_resize_begin and error out early with a clear error message. Signed-off-by: Josh Triplett Link: https://lore.kernel.org/r/74b8ae78405270211943cd7393e65586c5faeed1.1623093259.git.josh@joshtriplett.org Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/resize.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c @@ -74,6 +74,11 @@ int ext4_resize_begin(struct super_block return -EPERM; } + if (ext4_has_feature_sparse_super2(sb)) { + ext4_msg(sb, KERN_ERR, "Online resizing not supported with sparse_super2"); + return -EOPNOTSUPP; + } + if (test_and_set_bit_lock(EXT4_FLAGS_RESIZING, &EXT4_SB(sb)->s_ext4_flags)) ret = -EBUSY;