lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200117044216.GC21151@kadam>
Date:   Fri, 17 Jan 2020 07:42:16 +0300
From:   Dan Carpenter <dan.carpenter@...cle.com>
To:     Colin King <colin.king@...onical.com>
Cc:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        "Rafael J . Wysocki" <rafael@...nel.org>,
        Simon Schwartz <kern.simon@...schwartz.xyz>,
        kernel-janitors@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH][next] driver core: platform: fix u32 greater or equal to
 zero comparison

On Thu, Jan 16, 2020 at 05:57:58PM +0000, Colin King wrote:
> From: Colin Ian King <colin.king@...onical.com>
> 
> Currently the check that a u32 variable i is >= 0 is always true because
> the unsigned variable will never be negative, causing the loop to run
> forever.  Fix this by changing the pre-decrement check to a zero check on
> i followed by a decrement of i.
> 
> Addresses-Coverity: ("Unsigned compared against 0")
> Fixes: 39cc539f90d0 ("driver core: platform: Prevent resouce overflow from causing infinite loops")

A better fix would be to revert this patch.  It doesn't fix a real bug.
The ->num_resources is typically under 5.  It's not going to overflow
INT_MAX any time soon.  There are "architectures with smaller ints."

It should always be "int i" unless there is a valid real life reason.
People think that declaring everything as u32 will fix bugs but it
normally just introduces bugs as it does here.  u32 makes the code
harder to read.

This is a sore spot for me because apparently there is a static
analysis tool which tells people to use "u32 i;" everywhere.  It's bad
advice.  I have asked around but I haven't found which tool it is, but
which  we should find the tool and delete it to prevent this kind of
stuff in the future.

regards,
dan carpenter

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ