From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFE85C07E9E for ; Tue, 6 Jul 2021 11:08:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A93F61A46 for ; Tue, 6 Jul 2021 11:08:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231771AbhGFLLX (ORCPT ); Tue, 6 Jul 2021 07:11:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229834AbhGFLLV (ORCPT ); Tue, 6 Jul 2021 07:11:21 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EBEDC061574; Tue, 6 Jul 2021 04:08:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ujhsZIEffiBU8YDQW2JxEemVJB22hCG0N5jEdqMO6sY=; b=oHTNsFlvR32AIvh3SJZS+oIKYM N/D7UTCrnz4Efptg6IgjxFJNuVX2VsZi7A3VcMx6bXy0bebWiNRzvO2KaS90p4FO1Qo6X+pCW1pRi DX9Uk+MWeLXpIIYqyAr7Id0a5+LVsVefLII4v9w8UX7eQfXKW4LOr+R5/Zgh8CtO3R7LyiZJruzhq fTaDV4JxeCigEKhsRnIA9gGuZmhICV/SRALP2ToY3GPALHUI7tZaVCoNvPeFPY5q1sPYom1YyjUK3 yAYq8hLUFi0BP7Oox2P6guqXozOFtzV/yaLDhqYbKtXBZM1RgraQ7udD/VaRolaydb40+hbAFZvd6 f2Y9xEWg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m0iw2-00BAUP-KO; Tue, 06 Jul 2021 11:08:17 +0000 Date: Tue, 6 Jul 2021 12:08:14 +0100 From: Matthew Wilcox To: "Leizhen (ThunderTown)" Cc: Christoph Hellwig , "Darrick J . Wong" , linux-xfs , linux-fsdevel , linux-kernel Subject: Re: [PATCH -next 1/1] iomap: Fix a false positive of UBSAN in iomap_seek_data() Message-ID: References: <20210702092109.2601-1-thunder.leizhen@huawei.com> <492c7a7b-6f2e-de45-c733-51c80422305e@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <492c7a7b-6f2e-de45-c733-51c80422305e@huawei.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 05, 2021 at 11:35:08AM +0800, Leizhen (ThunderTown) wrote: > > > On 2021/7/3 3:56, Matthew Wilcox wrote: > > On Fri, Jul 02, 2021 at 05:21:09PM +0800, Zhen Lei wrote: > >> Move the evaluation expression "size - offset" after the "if (offset < 0)" > >> judgment statement to eliminate a false positive produced by the UBSAN. > >> > >> No functional changes. > >> > >> ========================================================================== > >> UBSAN: Undefined behaviour in fs/iomap.c:1435:9 > >> signed integer overflow: > >> 0 - -9223372036854775808 cannot be represented in type 'long long int' > > > > I don't understand. I thought we defined the behaviour of signed > > integer overflow in the kernel with whatever-the-gcc-flag-is? > > -9223372036854775808 ==> 0x8000000000000000 ==> -0 > > I don't fully understand what you mean. This is triggered by explicit error > injection '-0' at runtime, which should not be detected by compilation options. We use -fwrapv on the gcc command line: '-fwrapv' This option instructs the compiler to assume that signed arithmetic overflow of addition, subtraction and multiplication wraps around using twos-complement representation. This flag enables some optimizations and disables others. > lseek(r1, 0x8000000000000000, 0x3) I'll see about adding this to xfstests ...