Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3658062rwb; Sun, 20 Nov 2022 19:16:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf7beaWmjsIIbka4PrIkuk7CemL/ll9KBEwt2IuQwlpLqYJnDwRRDnfykGXI42oUcP28Eq1y X-Received: by 2002:a17:90a:de0f:b0:213:1143:9886 with SMTP id m15-20020a17090ade0f00b0021311439886mr18751258pjv.236.1669000562273; Sun, 20 Nov 2022 19:16:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669000562; cv=none; d=google.com; s=arc-20160816; b=l4a5CVhMQejtVbHF/MWMU0oOL3LOj+9uNfZ6V7cj43/y5z8E+FkaxXdFCUGS0sgCf7 OG0xQqjBIBdGSLP1A7rNKFs00hNJhGZpG6FYkmI0qEwHEl4JgFGRzZ/KYPvy4XUJ4els DYoQi2retLv+CvFZF6l3F9VSgMZqwsAtrAE+RMQ5b27zHQX++tQkAbUL2cqBqVnFp9Uz /nlWNjpq7K85ZtakGBhCIJMeYz178PU8Qw5E69vJyy0hoTE8Ywn7XIqRA8Ygpk1GKUPH FG9Mdh+80FGW5ELiL/XYXrqwSBNwjXfl0ZTppm/bWpznEQWjxEMLluK/8/Y9iEfaBU0W GCzA== 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; bh=HefxJzy24NEfQavoA+7yfcvFbKGOA7WBh01PrcPjSSY=; b=Jeu4pMy85zStqVQIGaaTmMwJmbQ1iFJlSu5Y9UyWeC8GMU/RP5mr1mNk6bvzcBiJ+b 1sZAhVAJDZDSHG4Uo+JIc/TbENuMD8fTZ3aRG0esJmiB5LAnUHuoe8TJlmB+0iP8ish/ eCoQ0wyjgWpsqtyGuq9nU7Fj+a8/qgmnMCyVxLN+J0yzjiTq0Hz4aw/+qt2xJ9crcpaY HYjApkldTc9MwGyGwm9AtjXtgPPILqx9cQnjgkErhEx8cOdNHsHyqycRbgcJTF+2vWTC tFWpHVlOz6cXmIg+d22O13PYYujLncyFCbts851CctczDl7TpRVOLfBy6/GTeEqByDkt FUZQ== ARC-Authentication-Results: i=1; mx.google.com; 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=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 d19-20020a170903209300b001865f8637a8si9092681plc.334.2022.11.20.19.15.50; Sun, 20 Nov 2022 19:16:02 -0800 (PST) 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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229924AbiKUCos (ORCPT + 90 others); Sun, 20 Nov 2022 21:44:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229790AbiKUCok (ORCPT ); Sun, 20 Nov 2022 21:44:40 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA7B02036B; Sun, 20 Nov 2022 18:44:39 -0800 (PST) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NFsCv2NvtzRpNr; Mon, 21 Nov 2022 10:44:11 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 21 Nov 2022 10:44:37 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 21 Nov 2022 10:44:37 +0800 From: Zhen Lei To: Alexander Viro , Eric Biggers , , Chris Mason , Josef Bacik , David Sterba , , CC: Zhen Lei Subject: [PATCH v2 2/2] fs: clear a UBSAN shift-out-of-bounds warning Date: Mon, 21 Nov 2022 10:44:18 +0800 Message-ID: <20221121024418.1800-3-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20221121024418.1800-1-thunder.leizhen@huawei.com> References: <20221121024418.1800-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500006.china.huawei.com (7.185.36.236) 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-kernel@vger.kernel.org UBSAN: shift-out-of-bounds in fs/locks.c:2572:16 left shift of 1 by 63 places cannot be represented in type 'long long int' Switch the calculation method to type_max() can help us eliminate this false positive. On the other hand, the old implementation has problems with char and short types, although not currently involved. printf("%d: %x\n", sizeof(char), INT_LIMIT(char)); printf("%d: %x\n", sizeof(short), INT_LIMIT(short)); 1: ffffff7f 2: ffff7fff Suggested-by: Eric Biggers Signed-off-by: Zhen Lei --- include/linux/fs.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index e654435f16512c1..a384741b1449457 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1131,9 +1131,8 @@ struct file_lock_context { /* The following constant reflects the upper bound of the file/locking space */ #ifndef OFFSET_MAX -#define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1))) -#define OFFSET_MAX INT_LIMIT(loff_t) -#define OFFT_OFFSET_MAX INT_LIMIT(off_t) +#define OFFSET_MAX type_max(loff_t) +#define OFFT_OFFSET_MAX type_max(off_t) #endif extern void send_sigio(struct fown_struct *fown, int fd, int band); -- 2.25.1