From patchwork Mon Nov 21 02:44:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhen Lei X-Patchwork-Id: 23519 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1362482wrr; Sun, 20 Nov 2022 19:02:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Xf42L+I2QPie+HUa7fGnHoesd0cE5uOhawupPHtufh+F+zaFqefR+rHbPXgqHbz+/u0wG X-Received: by 2002:a17:902:c286:b0:176:a880:6d72 with SMTP id i6-20020a170902c28600b00176a8806d72mr9642272pld.127.1668999763167; Sun, 20 Nov 2022 19:02:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668999763; cv=none; d=google.com; s=arc-20160816; b=iFXbQb4cIlKmJI+yaxPRY7Fo2F5UF2o2pApZRoJeoZ7eSqHA34TR4XEYZjVzHSQK40 wqG5rG0IlvIMZUFdAInHRFPWW5G4lsKSGiMko4Nga4PF3mOJZ3DUamDkH5K72a6mGBwV +naLXqVSpjOLyhX+OH7du7tk1mPOKGm619hmCvwS5k2gfgEaRHuWKt5MGPiVNqSeTj74 AKEcd4OBXQ+bssk7zakk2AUYhTlkQx19RZ8ul1SJw70FV/ckoeB0VCiqR1Bx1OmDvkdM sv/u0h4ilc5B8tGtvuHhWwMTsDMCIAOJ/E6CS2PqLvMgDsXWBbjGltL5/MTPRDH26BCx cICA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z14-20020a6553ce000000b0046f57b135c9si11658264pgr.182.2022.11.20.19.02.21; Sun, 20 Nov 2022 19:02:43 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750072975424618879?= X-GMAIL-MSGID: =?utf-8?q?1750073095856243139?= 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 Reviewed-by: Eric Biggers --- 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);