Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp181534rwi; Sun, 30 Oct 2022 22:59:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5WieaV5uhwKgi4iXyVHsMdZ15epXYDtNnK1328NIOqwQxDcA07XKQhyScK49VpcbDpUsYO X-Received: by 2002:a05:6402:194d:b0:461:8982:52b8 with SMTP id f13-20020a056402194d00b00461898252b8mr11857685edz.49.1667195992113; Sun, 30 Oct 2022 22:59:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667195992; cv=none; d=google.com; s=arc-20160816; b=aGk7fohTet9RBSHX0XhWwYfFd/Tl6comV6BDBUWrePOJYIY2J5o+5l4YBjpq3XvIiF HPnijrAOBB47mG31YUIlXQE31RTCLiCorKh5DQLw6+HbApC+L5fs94ZrZoWxgPPYGv1n 9FhV8P6YS4aHJDhiLXJ0D2/WYDaBGMBj43sc5nBD0e+Phk1SeU1ol0RFcAsnKThRBvSP 5oEqL+DRd7LVxBpyy/FkmfKj3JwRkvwvJ/flD33Q5legVlwp/IqSZLE4aKhuzgEyLg0y 7bWPsKBvMV+IRGlLPFPQ0nHuYWUG8qM9TC1y0Jnq4CVJB2gVpNRxrWAC1Vp8F7jLA8Jv 9jNQ== 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 :message-id:date:subject:cc:to:from; bh=afofl6H70RXG9mgHjyUsem+k3V6KGJP+zSE3ns7IZy8=; b=T59pC5Da1md3bNiT1Kyb6D+5xnKz9cdqh7ATNFBHLM6M2pLreHs3v6viUgCOM4Zl87 P8Kjbg/86i9GcxmdOJSdjlso1QfzuFFnR3CIjTAwNPPxp98SOG4fM4Jr1jY7+Y6ffhRo dyHilppSHS1yEWwwkvNjqmpsaNCz/fZC0ZzwwG5++qHvu2oSrFT1jBsnfcOdj83vlOql SzijSa+0zot6GjUJDZMoCt1jmxA5EUMiTY5th9s/NakBQY5qEPOMa5vIEcbwu8SnflcH HgHfxNnlRjsWb+Ca18aWftyN3auu/Wag0qVSepuE7yJ4X1V1bGqZkOefjB0mb827As8p idTA== 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 r11-20020aa7c14b000000b00458cbb6b6easi6330867edp.167.2022.10.30.22.59.20; Sun, 30 Oct 2022 22:59:52 -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 S229457AbiJaF6j (ORCPT + 99 others); Mon, 31 Oct 2022 01:58:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbiJaF6i (ORCPT ); Mon, 31 Oct 2022 01:58:38 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0610E2678 for ; Sun, 30 Oct 2022 22:58:35 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N12Q63yjdzmVbf; Mon, 31 Oct 2022 13:53:34 +0800 (CST) Received: from cgs.huawei.com (10.244.148.83) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 31 Oct 2022 13:58:33 +0800 From: Gaosheng Cui To: , , , CC: Subject: [PATCH] ext4: fix undefined behavior in bit shift for ext4_check_flag_values Date: Mon, 31 Oct 2022 13:58:33 +0800 Message-ID: <20221031055833.3966222-1-cuigaosheng1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.244.148.83] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500012.china.huawei.com (7.221.188.12) 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 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 Shifting signed 32-bit value by 31 bits is undefined, so changing significant bit to unsigned. The UBSAN warning calltrace like below: UBSAN: shift-out-of-bounds in fs/ext4/ext4.h:591:2 left shift of 1 by 31 places cannot be represented in type 'int' Call Trace: dump_stack_lvl+0x7d/0xa5 dump_stack+0x15/0x1b ubsan_epilogue+0xe/0x4e __ubsan_handle_shift_out_of_bounds+0x1e7/0x20c ext4_init_fs+0x5a/0x277 do_one_initcall+0x76/0x430 kernel_init_freeable+0x3b3/0x422 kernel_init+0x24/0x1e0 ret_from_fork+0x1f/0x30 Fixes: 9a4c80194713 ("ext4: ensure Inode flags consistency are checked at build time") Signed-off-by: Gaosheng Cui --- fs/ext4/ext4.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 8d5453852f98..e2d12e6c998d 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -558,7 +558,7 @@ enum { * * It's not paranoia if the Murphy's Law really *is* out to get you. :-) */ -#define TEST_FLAG_VALUE(FLAG) (EXT4_##FLAG##_FL == (1 << EXT4_INODE_##FLAG)) +#define TEST_FLAG_VALUE(FLAG) (EXT4_##FLAG##_FL == (1U << EXT4_INODE_##FLAG)) #define CHECK_FLAG_VALUE(FLAG) BUILD_BUG_ON(!TEST_FLAG_VALUE(FLAG)) static inline void ext4_check_flag_values(void) -- 2.25.1