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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <431b212d-e55d-4936-9318-a3fcf64b69af@rowland.harvard.edu>
Date: Thu, 20 Nov 2025 09:39:05 -0500
From: Alan Stern <stern@...land.harvard.edu>
To: David Laight <david.laight.linux@...il.com>
Cc: linux-kernel@...r.kernel.org, linux-usb@...r.kernel.org,
	usb-storage@...ts.one-eyed-alien.net,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Subject: Re: [usb-storage] Re: [PATCH 28/44] drivers/usb/storage: use min()
 instead of min_t()

On Thu, Nov 20, 2025 at 09:18:02AM +0000, David Laight wrote:
> On Wed, 19 Nov 2025 21:59:42 -0500
> Alan Stern <stern@...land.harvard.edu> wrote:
> 
> > On Wed, Nov 19, 2025 at 10:41:24PM +0000, david.laight.linux@...il.com wrote:
> > > From: David Laight <david.laight.linux@...il.com>
> > > 
> > > min_t(unsigned int, a, b) casts an 'unsigned long' to 'unsigned int'.
> > > Use min(a, b) instead as it promotes any 'unsigned int' to 'unsigned long'
> > > and so cannot discard significant bits.
> > > 
> > > In this case the 'unsigned long' value is small enough that the result
> > > is ok.
> > > 
> > > Detected by an extra check added to min_t().  
> > 
> > In fact, min_t(T, a, b) cannot go wrong as long as all the types are 
> > unsigned and at least one of a, b has type T or smaller.
> 
> That is backwards, both a and b have to have types at least as large
> as T (or rather values that will fit in T).
> - which is exactly what people keep getting wrong.
> Consider:
> 	u32 a = 4;
> 	u64 b = 0x100000001ull;
> then:
> 	min_t(u32, a, b)
> has value 1 not 4.

You are right.  For some reason I was thinking that the comparison took 
place before the casts, which doesn't make any sense.

Alan Stern

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ