From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754977AbcFUHpt (ORCPT ); Tue, 21 Jun 2016 03:45:49 -0400 Received: from mx2.suse.de ([195.135.220.15]:47864 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752803AbcFUHpr (ORCPT ); Tue, 21 Jun 2016 03:45:47 -0400 Date: Tue, 21 Jun 2016 09:43:53 +0200 From: Jan Kara To: Dan Carpenter Cc: Jan Kara , "Theodore Ts'o" , Andreas Dilger , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [patch] ext4: underflow in alignment check Message-ID: <20160621074353.GB3750@quack2.suse.cz> References: <20160616070709.GC23129@mwanda> <20160620160204.GG6882@quack2.suse.cz> <20160620195325.GM32247@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160620195325.GM32247@mwanda> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 20-06-16 22:53:26, Dan Carpenter wrote: > On Mon, Jun 20, 2016 at 06:02:04PM +0200, Jan Kara wrote: > > On Thu 16-06-16 10:07:09, Dan Carpenter wrote: > > > My static checker complains that this can underflow if arg is negative > > > which is true. > > > > > > Signed-off-by: Dan Carpenter > > > > How come? (1 << 30) fits even into 32-bit signed type. So where's the > > problem? > > Bad changelog... I was talking about a different issue. I was casting > it to unsigned to take advantage of type promototion. Assume we have: > > int arg = 1 << 31; > > (arg > (1 << 30)) // <-- this is false > (arg > (1U << 30)) // <-- this is true so there is no underflow. I see, but match_int() - or more precisely match_number() returns -ERANGE when the number is > INT_MAX, subsequently we check whether the number is < 0 (Opt_inode_readahead_blks has flag MOPT_GTE0 set) and bail out if yes. So at the place you are modifying we are sure the number is in [0, INT_MAX]. So the condition (arg > (1 << 30)) is pointless - just defensive programming in case we decide e.g. to upgrade the type of 'arg' to long - but not wrong... Honza -- Jan Kara SUSE Labs, CR