Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6144802iog; Thu, 23 Jun 2022 12:16:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uMLQgCu61VCyc/NJJTYy5Xkywd9G0GvfL/q8dnViO6glxtusWI3DJM3d/xmyj8PPSZ6Yln X-Received: by 2002:a63:2a0d:0:b0:3ab:392c:f45c with SMTP id q13-20020a632a0d000000b003ab392cf45cmr8768813pgq.575.1656011778962; Thu, 23 Jun 2022 12:16:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011778; cv=none; d=google.com; s=arc-20160816; b=tGYUXJowIV0gqwlHn4T+0IJAHxbkg/kT4Okf/VfDz2CWe9YkaxgdRQU4wlaFekP1Hb wlc9MyWaX/OyAN885Mpoi2Y3MLG8x5RSsPMfU3AowFFAq9Aa9xYr6u2p0KQj8sBBaCn8 bvvsANPvAHP6XQJB/rnsEk55F3utZ2rf2c1hdzghA9wDdYIRqfrUxdwhmNGO0Vl09kit rEJe03iqmhnWyZEejtYGpgeT4Lv9kdgvHUPkqEfFH3efwEmoSaFD5O9Q7qwkylNtxgg8 ev7OZRAZEWC2qGszrjaaM9qDlDyYRWZprrVSK8fKM6SqbTwHbwUnroBK7tkUwtsg7bIT U3TA== 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=KABbt3vO2UjmPctt/amBu2kO+1uZN71zoutSkyJelp0=; b=QhEraelMiGj3aAKxkswZVrbfPpBvRgCZQj3ezQ1og/9V+Ip+2CRYA2JO2yFyx/g8Gi J3jB85tQDam9WTuJAuF/j2I9uMu+WWKdlTZaQKgGHGJmttp2uvveT7HcEmm3llDh3cJI lEyfm4dKC+b3iOALJ3zDF2O7HYt05U14bBZsG/PLeuikdvKQGPS4lVPYQ7L/J0xSK+qL ADS3NS5OPN1rpi/xALzB2hA9tS7qr9D/tIE5xoJw4hxXtdqrBtmvwj6ZNN+PlhpC8fFC 9REpgTQC2ceZR+hmFZ66R+5wWH6+qy7qLpSLUFH2hbGZqx/elOtHOs/aSIPH8D6KZ7Zh 88Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QArhG6Gi; 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 n18-20020a170902e55200b0016754f4f654si410768plf.529.2022.06.23.12.16.07; Thu, 23 Jun 2022 12:16:18 -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=QArhG6Gi; 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 S233137AbiFWRRX (ORCPT + 99 others); Thu, 23 Jun 2022 13:17:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231959AbiFWRMV (ORCPT ); Thu, 23 Jun 2022 13:12:21 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCC3C13D5A; Thu, 23 Jun 2022 09:57:56 -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 ams.source.kernel.org (Postfix) with ESMTPS id A7C1DB82495; Thu, 23 Jun 2022 16:57:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2F64C341C4; Thu, 23 Jun 2022 16:57:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656003473; bh=UHfzWZ17enTshJAv77LTshGmYK29RVb2TySaQdEy0yI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QArhG6GicHy8sTiH9PkoA6es+s1GmT3auT2qEuxDBZJ/5z5DN24vq5dKIiOOr0IGH soksgMEXHHdtsSBYCfhkIEcENf6SRbmIt08PDUEhuBW9pjA7zguRFgKPvrWeLpc4BO UJrLTHWVkN4BPY5wgNnAUE7vlDq7GdpnmRXEB3Dc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Zhang Yi , Ritesh Harjani , Jan Kara , Theodore Tso Subject: [PATCH 4.9 249/264] ext4: add reserved GDT blocks check Date: Thu, 23 Jun 2022 18:44:02 +0200 Message-Id: <20220623164351.114851003@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164344.053938039@linuxfoundation.org> References: <20220623164344.053938039@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=-7.7 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: Zhang Yi commit b55c3cd102a6f48b90e61c44f7f3dda8c290c694 upstream. We capture a NULL pointer issue when resizing a corrupt ext4 image which is freshly clear resize_inode feature (not run e2fsck). It could be simply reproduced by following steps. The problem is because of the resize_inode feature was cleared, and it will convert the filesystem to meta_bg mode in ext4_resize_fs(), but the es->s_reserved_gdt_blocks was not reduced to zero, so could we mistakenly call reserve_backup_gdb() and passing an uninitialized resize_inode to it when adding new group descriptors. mkfs.ext4 /dev/sda 3G tune2fs -O ^resize_inode /dev/sda #forget to run requested e2fsck mount /dev/sda /mnt resize2fs /dev/sda 8G ======== BUG: kernel NULL pointer dereference, address: 0000000000000028 CPU: 19 PID: 3243 Comm: resize2fs Not tainted 5.18.0-rc7-00001-gfde086c5ebfd #748 ... RIP: 0010:ext4_flex_group_add+0xe08/0x2570 ... Call Trace: ext4_resize_fs+0xbec/0x1660 __ext4_ioctl+0x1749/0x24e0 ext4_ioctl+0x12/0x20 __x64_sys_ioctl+0xa6/0x110 do_syscall_64+0x3b/0x90 entry_SYSCALL_64_after_hwframe+0x44/0xae RIP: 0033:0x7f2dd739617b ======== The fix is simple, add a check in ext4_resize_begin() to make sure that the es->s_reserved_gdt_blocks is zero when the resize_inode feature is disabled. Cc: stable@kernel.org Signed-off-by: Zhang Yi Reviewed-by: Ritesh Harjani Reviewed-by: Jan Kara Link: https://lore.kernel.org/r/20220601092717.763694-1-yi.zhang@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/resize.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c @@ -52,6 +52,16 @@ int ext4_resize_begin(struct super_block return -EPERM; /* + * If the reserved GDT blocks is non-zero, the resize_inode feature + * should always be set. + */ + if (EXT4_SB(sb)->s_es->s_reserved_gdt_blocks && + !ext4_has_feature_resize_inode(sb)) { + ext4_error(sb, "resize_inode disabled but reserved GDT blocks non-zero"); + return -EFSCORRUPTED; + } + + /* * If we are not using the primary superblock/GDT copy don't resize, * because the user tools have no way of handling this. Probably a * bad time to do it anyways.