Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6572558rwn; Tue, 13 Sep 2022 06:15:59 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Ef3rcKHeB5u5a/usiKoYYmrGHzycYrS6m2kDqnYatI0Su9Ff94Ivz32P2qWc8o/UXP9Fk X-Received: by 2002:a17:907:a48:b0:77c:51b0:5aeb with SMTP id be8-20020a1709070a4800b0077c51b05aebmr9017469ejc.61.1663074959086; Tue, 13 Sep 2022 06:15:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663074959; cv=none; d=google.com; s=arc-20160816; b=S7/8GoAqaDtdNOM87KeAcBBvWsik/8dgGBXFYwpjS7LGi6lZ7uqVQuZyQo8fNokJvg m+Ghu/nDLMRy61Sq/EIE7CCnuqWRn8RYxdu0ylVqT3HEWYvWEfMuZ+//hsIrSy0DzmMO KrYU9kNHYpDAy3S8worqjhocSiuwI51TfrS2DITUL0gxHQJBPzAGpRjGo2oEbQxXhXGl 1zxJJ3dp3L/d7uoWHmwO2+sWJoaUuXz/a2omF/NpJLSgvYnLd+EVyDmj7LwSjyqLFqpI QreEtgwRri8vkc2aoqPJF8xTGpKZyz5axDDRJG7qz5YrJ9uZeZhR9cQ0V8R9G6q6P5rf QSUQ== 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=LQjEVelW/YOl/7LU92GLGpb2O0Q5jTy2I7V0Kq37Ov8=; b=A14+E+BPuUAe+cU3I2OfEf01nvAqFhLF0mYmaihPYzafJVCyKw30r/VnbZWclmpEkR hvusBZhvQVUCdNcAvu5SJj1HPciHDFV3ecgBK1lIcYemwvjTXMwOiPTvZeL0Wrz2Ypeu cEbjyCmEy/jvuI7iGhv6Ly6/ljtJERe0HjKUAtkY1jcIO/tZa973EGBpOQIED+X4DKw9 cahoMVEjcQolBLFvzYz9j7tLvjC3tTMVZFnCCxZR+VjiBMam4NgEhe4sdaGDfxKIez78 C6j/y1Tgk0XntGSGDX2Aoyy7/2gyU1JDkYIcG/7wGaAQ2YJ0QYsts3eMNoKlGcLs3wT7 R9sQ== 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 w4-20020a50fa84000000b0044ee88a08b1si8097323edr.277.2022.09.13.06.15.30; Tue, 13 Sep 2022 06:15:59 -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 S229528AbiIMNPE (ORCPT + 99 others); Tue, 13 Sep 2022 09:15:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229876AbiIMNPD (ORCPT ); Tue, 13 Sep 2022 09:15:03 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C9C9E088 for ; Tue, 13 Sep 2022 06:14:56 -0700 (PDT) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MRkNx2Yc1zkWw0; Tue, 13 Sep 2022 21:10:57 +0800 (CST) Received: from kwepemm600003.china.huawei.com (7.193.23.202) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 13 Sep 2022 21:14:54 +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.31; Tue, 13 Sep 2022 21:14:53 +0800 To: , Ext4 Developers List CC: linfeilong , zhanchengbin , wuguanghao From: Zhiqiang Liu Subject: [PATCH] ext2fs_open2: goto cleanup tag when image_header->magic_number != EXT2_ET_MAGIC_E2IMAGE Message-ID: <703f5bf7-fd63-ad0a-fcbb-0b5affd31d53@huawei.com> Date: Tue, 13 Sep 2022 21:14:51 +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 In ext2fs_open2(), fs->image_header is assigned by calling io_channel_read_blk, successfully. If fs->image_header->magic_number is not equal to EXT2_ET_MAGIC_E2IMAGE, we should go to cleanup tag to free resouce and return errcode (EXT2_ET_MAGIC_E2IMAGE). Signed-off-by: Zhiqiang Liu --- lib/ext2fs/openfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c index 39229d7c..df73f4f2 100644 --- a/lib/ext2fs/openfs.c +++ b/lib/ext2fs/openfs.c @@ -193,8 +193,10 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, fs->image_header); if (retval) goto cleanup; - if (ext2fs_le32_to_cpu(fs->image_header->magic_number) != EXT2_ET_MAGIC_E2IMAGE) - return EXT2_ET_MAGIC_E2IMAGE; + if (ext2fs_le32_to_cpu(fs->image_header->magic_number) != EXT2_ET_MAGIC_E2IMAGE) { + retval = EXT2_ET_MAGIC_E2IMAGE; + goto cleanup; + } superblock = 1; block_size = ext2fs_le32_to_cpu(fs->image_header->fs_blocksize); } -- 2.33.0