From: Matthew Wilcox <willy@infradead.org>
To: Hongbo Yao <yaohongbo@huawei.com>
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
Date: Mon, 4 Mar 2019 20:26:25 -0800 [thread overview]
Message-ID: <20190305042625.GC13380@bombadil.infradead.org> (raw)
In-Reply-To: <20190223090210.116847-1-yaohongbo@huawei.com>
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;
prev parent reply other threads:[~2019-03-05 4:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-23 9:02 [PATCH] fs: Avoid signed overflow UBSAN warning Hongbo Yao
2019-03-05 4:26 ` Matthew Wilcox [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190305042625.GC13380@bombadil.infradead.org \
--to=willy@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=viro@zeniv.linux.org.uk \
--cc=yaohongbo@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).