Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2977476imb; Mon, 4 Mar 2019 20:27:10 -0800 (PST) X-Google-Smtp-Source: APXvYqynaT39dSb0cIfn/1zEfuo1xAq8xJ7DyIpDLL+swIJlTfXqPpu5AGqeWJqJDMjT9YGbeR52 X-Received: by 2002:a17:902:b115:: with SMTP id q21mr8604904plr.272.1551760030722; Mon, 04 Mar 2019 20:27:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551760030; cv=none; d=google.com; s=arc-20160816; b=OgJd9szyoe7Eps62BxTd4ZffOiz+UyVZ8Al3P//rb4LOq9lVsI2q2H27t64NgK7FgR iVZ1TAHA3bzmz5EauxYKfVemgLeCowCHdlVAWQ8kUUTPCxAB3YiROweDp9zH4/AnBsk0 1l2n/cWsFXdKPOr1Q66DdVKxmqUUJvYZzI2QHKRnBU/YW/XLIoUw0Sz6tQa3C0dLcllm nKa9X4b5O+hFzKgNTWxoxsMY2WhGdSO0p2LUgP301R68wZg3qmMZW18wG1o55TBVOb3N +a5PLC0eSF5RB5fXMlsotwdTYiIhwLNAMnrNN558+xclfpEqLJBp41xRx8Gc3GULyUG5 cv6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=JwwcttM2cWT4KB8XyzeEqi7PlaKzpJpbAYIc//MbWhM=; b=VBFFHwVslkFkcX8r9iQmW+YUUQJ0QRnJhnalNTwMmPF+Q0jMpNcnx7lLYjxdHmOk3D k4NiHyLPcSyEA7VLg9abcSJMJV3jlrr8ivFsBaEdbR0YGsHc2LZ4DzAlxBBnproN4PIU J7Y4FNf30PlCQHfubdBBFbPT4gTMM0yI6FtPAFbgfvm3XINQiJJPMak1afmTU9te32DF rGfBoHpKDA68ag+bCaxeUHrtosS9xCUDTx4NA+6lg0/PhraVqzXGK4+JyLFCZU+HgUyv Ckpr9xakdOAuh7Bsjm4KGFXN4jdMz68GwMNdwksKscWNqd0ZGTXQ98wVZ3BRxANFAl6Z 4OTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=XXDwgpRQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q17si6665866pgv.39.2019.03.04.20.26.53; Mon, 04 Mar 2019 20:27:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=XXDwgpRQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726997AbfCEE0d (ORCPT + 99 others); Mon, 4 Mar 2019 23:26:33 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:34656 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726522AbfCEE0c (ORCPT ); Mon, 4 Mar 2019 23:26:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=JwwcttM2cWT4KB8XyzeEqi7PlaKzpJpbAYIc//MbWhM=; b=XXDwgpRQQ2gcdgdzAsUszn0GB +F8s10psmzKqTr1ZWB59rBYnUQkANcv6WiNEM5n6F+kYoUrK2XSbKFLU/gwP6/psFBVD4odJGgeGt Qg1wOxnIaZOR7dmewYd6g/+0XFpNswRdYmX0G2KuXgZc0vNvOV65CEwewPxr6tqR0hpENVNMX9AE5 k1bzuUkElKrqOl9ZVggvcsr1/oQL48x+WRQGU0+BEezMFPHLOEGBH6TlVE9/8w/O4/AMWWAh7rp/n wf2LeDqMf5QN+BQULMoySGdpMkTL+VfhNnD1W7IQYfbGOTCzMD2ZzvgTrajofP72b2mHtPZT3V9Ov qJQ15CRPQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1h11er-0002Qv-FN; Tue, 05 Mar 2019 04:26:25 +0000 Date: Mon, 4 Mar 2019 20:26:25 -0800 From: Matthew Wilcox To: Hongbo Yao Cc: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linuxarm@huawei.com Subject: Re: [PATCH] fs: Avoid signed overflow UBSAN warning Message-ID: <20190305042625.GC13380@bombadil.infradead.org> References: <20190223090210.116847-1-yaohongbo@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190223090210.116847-1-yaohongbo@huawei.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Feb 23, 2019 at 05:02:10PM +0800, Hongbo Yao wrote: > I ran into this: > UBSAN: Undefined behaviour in fs/read_write.c:251:11 > signed integer overflow: > 9223372036854775805 + 9223372036854775805 cannot be represented in > type 'long long int' > > Use unsigned types to do math, it doesn't throw a UBSAN warning > when it does overflow.This patch doesn't change generated code. You don't need to be this verbose to fix it. > - offset += file->f_pos; > + offset = (u64)file->f_pos + (u64)offset; offset += (u64)file->f_pos;