From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753802AbbIIXhX (ORCPT ); Wed, 9 Sep 2015 19:37:23 -0400 Received: from mail-pa0-f46.google.com ([209.85.220.46]:34376 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751055AbbIIXhV (ORCPT ); Wed, 9 Sep 2015 19:37:21 -0400 Date: Wed, 9 Sep 2015 16:37:18 -0700 From: Brian Norris To: Peng Fan Cc: dwmw2@infradead.org, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mtd: blktrans: fix integer overflow Message-ID: <20150909233718.GA11487@google.com> References: <1440169051-13891-1-git-send-email-van.freenix@gmail.com> <20150902170249.GQ81844@google.com> <20150905134224.GB17774@linux-4gyl.site> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150905134224.GB17774@linux-4gyl.site> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Sep 05, 2015 at 09:42:27PM +0800, Peng Fan wrote: > On Wed, Sep 02, 2015 at 10:02:49AM -0700, Brian Norris wrote: > > One possibility, since you only point to a single computation that > > overflows, is to just fix the overflow locally. It's not like the 'size' > > (which represents number of sectors) is actually ever overflowing a > > 32-bit integer. It's just the multiplication that overflows. So you > > could cast to 64-bit arithmetic just for the multiplication. e.g.: > > > > set_capcity(gd, ((u64)new->size * tr->blksize) >> 9); > > Yeah. It is the multiplication overflowing a 32-bit interger. My frist > implementation is this way, using u64 to do type cast. But I guess one > day the number of sectors can be larger than UINT_MAX, so I change it > to 'unsigned long long' from 'unsigned long', which is > not the right way, thanks for correcting me. > > > > Or some other creative solution. > > I think this should be a bug fix. If you need a quick fix, I can send > out the simple patch that just do (u64) cast. If not, I can take some > time to "fix all the blktrans users". I think since you've identified (and tested) a fix, we might as well include it. So I suppose the cast approach. The larger change would be more invasive and may take a while. > > > > Then, we don't have to address this problem till we start seeing 2TB > > MTDs! Brian