Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp1223899iof; Tue, 7 Jun 2022 00:47:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoCdtriK/u6E4TFvNt4J4OTy5+/6uLAgmZo2EEfjhZe4OnlOD5bnJnvOmLiAG3WlWARB8r X-Received: by 2002:a63:4964:0:b0:3fc:a87a:bd8d with SMTP id y36-20020a634964000000b003fca87abd8dmr24737326pgk.257.1654588053423; Tue, 07 Jun 2022 00:47:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654588053; cv=none; d=google.com; s=arc-20160816; b=HnvD8Zuc10U9YRCd6RkEIhE0ai55JjsLTpyXbkv7ahx8Btu6WIcqAfjnSIP4fUQA+u G9JQYLxvsLkV3PdkaH2829R4wOeE9+Jhrel7hiIgAZB+o8/TU8tTDBAAeMe0+lxjn9LS az6ViAmAeXupnsHFgUieZ/43GQHyz5eYyqVGywIC65WkFETMzpcZjuYfxJ+yfSj0NjTO PxtpleGlHMLaOYpCbOiCVFCQ3dcJhMckaBkDoc8XRJHGW2s1x/9PuY4c6u7wsicknbFh VWJQN8aw56Me+ucmvf4MaXGmyOgZZrSdrH5y1wjzFKIdIfxVB0aGEKIbcHJh34MB187V nstw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CsokmL2EFFwkPts+K9i7MBBVQEKp451vpopb4oYRdhg=; b=a8N/gXKMRervruLpUYGa77kwzLt4Iedj7OLGSdgD3UwP6L6e3wEwQ92EjMKzw2J4hh 8HOZPvaqZiglzkwGSBOc9r8hgrSfonbn8c18kvA2B3IHUNnSkxQW1nhhEVRSyWA8nZzB S+M39mXu8ZHDYJ7ZgTb4AxrQqQnArASfPTPT9ioXAfiqjl3NkEc/Hh4wtOe8c9pyv1Y4 mZf5CTTIFk9eOBw2S1fqjerPuwHMG4MDb57PATrxiLXclb0lWEUyp1dwrv6N3PnpiVOM jVPPJOPq9W2hAYMr3ZfQMvbhPrUHFcqHrRgwNyuqhimKrk3fVthRxZVAZ7f0OIMLB3hh uCuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mit.edu header.s=outgoing header.b=lfd2354Y; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g126-20020a636b84000000b003fd55609127si14004358pgc.524.2022.06.07.00.47.17; Tue, 07 Jun 2022 00:47:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=fail header.i=@mit.edu header.s=outgoing header.b=lfd2354Y; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236548AbiFGEZs (ORCPT + 99 others); Tue, 7 Jun 2022 00:25:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236550AbiFGEZo (ORCPT ); Tue, 7 Jun 2022 00:25:44 -0400 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAC39B82CC for ; Mon, 6 Jun 2022 21:25:42 -0700 (PDT) Received: from cwcc.thunk.org (pool-108-7-220-252.bstnma.fios.verizon.net [108.7.220.252]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 2574PTMj005595 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 7 Jun 2022 00:25:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mit.edu; s=outgoing; t=1654575931; bh=CsokmL2EFFwkPts+K9i7MBBVQEKp451vpopb4oYRdhg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lfd2354YhAKuCLcY1zaVoAEmEC2XoDx25q3+uiK7Zp8uwdU4f2KzIFLO2kGoBnuIj NdH/bRhbC+1x7WpVDaKJgxVL9TCovhVv4509cUrfN7diw/S0bUYVnBN+3TVBb7XjU1 YmJf04NwpBReE/TWvbXaPPHzdC+wFqwsYSKtpJkuHP6qcl71VaWsznZRbmWfhq8Xmu /fXtquOipPytTjU8UxtxJKytgF7+BRATKebtgFHo65nwGs5M0t4Up0XDOR+ItaHDC0 lzoa1d3MKLx2/CBL6cHNGF2XifZGfDsmmxrz87FoI+ST9uZU6/vsUENiQFs4bX9pZh PgrM1P6xR4bfQ== Received: by cwcc.thunk.org (Postfix, from userid 15806) id CACA115C3EC2; Tue, 7 Jun 2022 00:25:27 -0400 (EDT) From: "Theodore Ts'o" To: Ext4 Developers List Cc: Nils Bars , =?UTF-8?q?Moritz=20Schl=C3=B6gel?= , Nico Schiller , "Theodore Ts'o" Subject: [PATCH 7/7] libext2fs: check for invalid blocks in ext2fs_punch_blocks() Date: Tue, 7 Jun 2022 00:24:44 -0400 Message-Id: <20220607042444.1798015-8-tytso@mit.edu> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20220607042444.1798015-1-tytso@mit.edu> References: <20220607042444.1798015-1-tytso@mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE, 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-ext4@vger.kernel.org If the extent tree has out-of-range physical block numbers, don't try to release them. Also add a similar check in ext2fs_block_alloc_stats2() to avoid a NULL pointer dereference. Reported-by: Nils Bars Reported-by: Moritz Schlögel Reported-by: Nico Schiller Signed-off-by: Theodore Ts'o --- lib/ext2fs/alloc_stats.c | 3 ++- lib/ext2fs/punch.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ext2fs/alloc_stats.c b/lib/ext2fs/alloc_stats.c index 3949f618..6f98bcc7 100644 --- a/lib/ext2fs/alloc_stats.c +++ b/lib/ext2fs/alloc_stats.c @@ -62,7 +62,8 @@ void ext2fs_block_alloc_stats2(ext2_filsys fs, blk64_t blk, int inuse) { int group = ext2fs_group_of_blk2(fs, blk); - if (blk >= ext2fs_blocks_count(fs->super)) { + if (blk < fs->super->s_first_data_block || + blk >= ext2fs_blocks_count(fs->super)) { #ifndef OMIT_COM_ERR com_err("ext2fs_block_alloc_stats", 0, "Illegal block number: %lu", (unsigned long) blk); diff --git a/lib/ext2fs/punch.c b/lib/ext2fs/punch.c index effa1e2d..e2543e1e 100644 --- a/lib/ext2fs/punch.c +++ b/lib/ext2fs/punch.c @@ -200,6 +200,10 @@ static errcode_t punch_extent_blocks(ext2_filsys fs, ext2_ino_t ino, __u32 cluster_freed; errcode_t retval = 0; + if (free_start < fs->super->s_first_data_block || + (free_start + free_count) >= ext2fs_blocks_count(fs->super)) + return EXT2_ET_BAD_BLOCK_NUM; + /* No bigalloc? Just free each block. */ if (EXT2FS_CLUSTER_RATIO(fs) == 1) { *freed += free_count; -- 2.31.0