Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp2969990rwb; Mon, 5 Sep 2022 04:37:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR7iiec6ZYYV1bzD7Ex90ysTuRifAeYjjN+yzd2QkHt0rUwIWh4ZFR9xxovw8zok+3pNz590 X-Received: by 2002:a17:907:1623:b0:741:9f8f:be50 with SMTP id hb35-20020a170907162300b007419f8fbe50mr23914345ejc.254.1662377850291; Mon, 05 Sep 2022 04:37:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662377850; cv=none; d=google.com; s=arc-20160816; b=CzAJWgxd7w8fRVuHmH/fuBH0UU00E4XM4fJQSUC61SO8HCejX733HMtDjo9PJj71pL SXKg6NYuHa97qIERi3n5A3435GOwS+hsWv4sZEMbZ8OZ43XGvu2cHt0Wmm/nUJTXD7R2 z8eG19pDyW4BXpWDLjfA1i32SEliqReW2KkKWYMbIUo/2YkJq5POZvBYvx7UrhbYdR6l ad9Dgr2Wwv/y7JvoA6h1+kERhkBCx/kBObdL0fX3+gpEQSo41eZEd52jBiN06FfgtVWM WBD832j1eBk/efnye6oy/z6lxurI6TU/M8op1bbOUFovMiXASAiJDj6n6uVQHdb2u4VH k5FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:user-agent:date:message-id:subject:from:cc:to; bh=JJNWDDvjTP8Ymk+IqQUqzriWJfwjvGD80NgJnq2Y1r8=; b=Y9pPnCH0FrSKn2Ldy69RzrFyRVcC9Ya3PKMhQGltVeFD4cSw8EiQd3PwQfhMX5EQ0U Yb2ygCNc7tOm/E47xyWKuyMtUtYzBbqq+XBjZ+XGc46jJUgHAzYsduAtoZQORxD1Iy+A zDcWogOsl3fnt1Sdo+8yhFyg+4P0eMXhQPPqAOVoK+cD32IsmJI0lPKDAvU/khNFiOeq zGkg9/D3Yg+zYcZG6syWGKShfKR/EJ34vJYxjEziDZbYyl3DdEZB1QR4x+I1P+B1w79X Af7ueAX6iQS+qj+yX8Hk0OAGE8FBbVxV1pcqWyIpsmk0UoDgTOnHzeUO/1XB+7HJhfir xYOw== ARC-Authentication-Results: i=1; mx.google.com; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dn21-20020a17090794d500b0072b4adf5c0fsi7788880ejc.77.2022.09.05.04.36.59; Mon, 05 Sep 2022 04:37:30 -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; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236467AbiIELQJ (ORCPT + 99 others); Mon, 5 Sep 2022 07:16:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236002AbiIELQJ (ORCPT ); Mon, 5 Sep 2022 07:16:09 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C76A5508A for ; Mon, 5 Sep 2022 04:16:07 -0700 (PDT) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MLm996zkCznTdX; Mon, 5 Sep 2022 19:13:33 +0800 (CST) Received: from kwepemm600003.china.huawei.com (7.193.23.202) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 5 Sep 2022 19:16:05 +0800 Received: from [127.0.0.1] (10.174.177.249) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 5 Sep 2022 19:16:05 +0800 To: "Theodore Y. Ts'o" , , "Ext4 Developers List" , zhanchengbin CC: wuguanghao , linfeilong From: Zhiqiang Liu Subject: [PATCH] tune2fs: fix tune2fs segfault when ext2fs_run_ext3_journal() fails Message-ID: <8e87fbc3-674a-af30-1234-54b36eb5ca5d@huawei.com> Date: Mon, 5 Sep 2022 19:16:03 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.249] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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-ext4@vger.kernel.org When ext2fs_run_ext3_journal() fails, tune2fs cmd will occur one segfault problem as follows. (gdb) bt #0 0x00007fdadad69917 in ext2fs_mmp_stop (fs=0x0) at mmp.c:405 #1 0x0000558fa5a9365a in main (argc=, argv=) at tune2fs.c:3440 misc/tune2fs.c: main() -> ext2fs_open2(&fs) -> ext2fs_mmp_start ...... -> retval = ext2fs_run_ext3_journal(&fs) -> if (retval) // if ext2fs_run_ext3_journal fails, close and free fs. -> ext2fs_close_free(&fs) -> rc = 1 -> goto closefs ...... closefs: -> if (rc) -> ext2fs_mmp_stop(fs) // fs has been set to NULL, boom!! -> (ext2fs_close_free(&fs) ? 1 : 0); // close and free fs In main() of tune2fs cmd, if ext2fs_run_ext3_journal() fails, we should set rc=1 and goto closefs tag, in which will release fs resource. Fix: a2292f8a5108 ("tune2fs: reset MMP state on error exit") Signed-off-by: Zhiqiang Liu Signed-off-by: zhanchengbin --- misc/tune2fs.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/misc/tune2fs.c b/misc/tune2fs.c index 9f0d4379..25ade2fa 100644 --- a/misc/tune2fs.c +++ b/misc/tune2fs.c @@ -3344,8 +3344,6 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n" com_err("tune2fs", retval, "while recovering journal.\n"); printf(_("Please run e2fsck -fy %s.\n"), argv[1]); - if (fs) - ext2fs_close_free(&fs); rc = 1; goto closefs; } -- 2.33.0