Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2257916rwb; Sat, 19 Nov 2022 12:04:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf5SjDFaZhEMLlLgqkEOv+M6f3vyGA8ad5rwCBwI7/FRQD2eTZaVhfYQ67l1Ty0HO0GB0W99 X-Received: by 2002:a17:906:c34f:b0:78e:17ad:ba62 with SMTP id ci15-20020a170906c34f00b0078e17adba62mr10372903ejb.719.1668888286408; Sat, 19 Nov 2022 12:04:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668888286; cv=none; d=google.com; s=arc-20160816; b=tvyBHzWEUEkWL8m6ZmS9OXOn9xSCmpEddcAuglid/4zMJ2ZCy0ro8agKcEY0P6SWR6 C3KLaKQMkLJhPxEJPyfN0+QVaL9nibdf/dpMMuIHe0xqQG/0258WC4iWxaTSbj9Cx8/z 78NbFmLngRuYIx8m/0OJYhoktXM0iJs6o8qOWbITIkVpvZvy7alsV2A85NInOD+t88/I Kx52JbHarmmmjQHVnn78QFUD9g910ZLcrNUla5nCr8FTLVyNXK1kiG0Cn21HFrKZepxB 5JnsvrEKpzIvlpuSTOrEl7vfeka4v8eqIZrROQIlWGLqeP3KnkwwlgrtGq30kZDWvLNj P14A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=miEtXaGtXh8MNRVcfCM+p2f9bCc/04MDKxzKq07h7pg=; b=hYCqcbLk3ZySsOXu9JxilLXjLBv88QFMzQF/qgzhyLNdY50m2hJPZgSb/xHqJWTOHZ 7+mrKqPFHccmbtsFXEAQv3RlJkmo4+pN6cyI6nESlj2v18Coarxv95Y+KP0EOv/odJa8 PlqML0xk7wseudJmOcJZpxKjIX3CiLQ3gL/5a+nEJ9qnsEVXgsdm24mZ8luiZ2Z/C6/P V0ry9Tt9yKyj6UKcgF+Qn3d8Q46DzI6isQ/Quh5Dd9pNvtlcMKnFbgqB1OwovmQ8J55L xCz1XqQMATZtlxT86/P7RehU/xO7DAQK72FSH+TGcRYa6UBFsWKHImI/4qofTdQG/CMD UcUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WONmlaT9; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 17-20020a170906059100b007a1084820f6si4874743ejn.230.2022.11.19.12.04.18; Sat, 19 Nov 2022 12:04:46 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WONmlaT9; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234179AbiKSTjx (ORCPT + 91 others); Sat, 19 Nov 2022 14:39:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233757AbiKSTjv (ORCPT ); Sat, 19 Nov 2022 14:39:51 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCA1010548; Sat, 19 Nov 2022 11:39:50 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 89382B80764; Sat, 19 Nov 2022 19:39:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05D66C433C1; Sat, 19 Nov 2022 19:39:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668886788; bh=+C+DiIjfUNvrIUtozO8tzaUQ95kuqAMyl5Xq7IgDY2Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WONmlaT9hsYTSDq8NULSBTZUyBsKljuUiElU7Bl4o+SCNVRp3YIId0DskwQ5jXd2T 69dFw+5fhoAa69Dk+fAfTHMCI0lqTJ3ahMkYu5bmFnY6pqQX2GO9ARtAx19j1Z92Ga n8xrTatWiOUCzSmLbSyf2d85sQp3su6D8vdS/6/Lm4PUXiNUEednzYzucPs7XKueBC qVqoXvxmQyx7d0a8yU6lOZOxn6iHTQ1ILmn9TUpPPEZ+/aCIJZ1IxPUfiqzl2/C++J 1k/WSgOwmNnTmC9BAlHWi2fy1T6DJlIsoCSsb3EptDLeXutiL7vIhPDuveCAlfYNVm 52aAvG3OmCd/g== Date: Sat, 19 Nov 2022 11:39:43 -0800 From: Eric Biggers To: Zhen Lei Cc: Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] fs: Clear a UBSAN shift-out-of-bounds warning Message-ID: References: <20221110031024.204-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221110031024.204-1-thunder.leizhen@huawei.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 On Thu, Nov 10, 2022 at 11:10:24AM +0800, Zhen Lei wrote: > 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 ((quarter - 1) * 2 + 1) 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 > > Signed-off-by: Zhen Lei > --- > include/linux/fs.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/linux/fs.h b/include/linux/fs.h > index e654435f16512c1..88d42e2daed9f6c 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -1131,7 +1131,7 @@ 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 INT_LIMIT(x) ((((x)1 << (sizeof(x) * 8 - 2)) - 1) * 2 + 1) > #define OFFSET_MAX INT_LIMIT(loff_t) > #define OFFT_OFFSET_MAX INT_LIMIT(off_t) > #endif This problem has already been solved by type_max() in include/linux/overflow.h. How about removing INT_LIMIT() and using type_max() instead? - Eric