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] [day] [month] [year] [list]
Message-ID: <20260113094226.144973b2@pumpkin>
Date: Tue, 13 Jan 2026 09:42:26 +0000
From: David Laight <david.laight.linux@...il.com>
To: Brian Masney <bmasney@...hat.com>
Cc: linux-kernel@...r.kernel.org, linux-ext4@...r.kernel.org,
 linux-fsdevel@...r.kernel.org, linux-mm@...ck.org, Alexander Viro
 <viro@...iv.linux.org.uk>, Andreas Dilger <adilger.kernel@...ger.ca>,
 Christian Brauner <brauner@...nel.org>, Kees Cook <kees@...nel.org>, Miklos
 Szeredi <miklos@...redi.hu>, OGAWA Hirofumi <hirofumi@...l.parknet.co.jp>,
 Theodore Ts'o <tytso@....edu>
Subject: Re: [PATCH 30/44] fs: use min() or umin() instead of min_t()

On Mon, 12 Jan 2026 16:51:22 -0500
Brian Masney <bmasney@...hat.com> wrote:

> Hi David,
> 
> On Wed, Nov 19, 2025 at 10:41:26PM +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.
> > 
> > A couple of places need umin() because of loops like:
> > 	nfolios = DIV_ROUND_UP(ret + start, PAGE_SIZE);
> > 
> > 	for (i = 0; i < nfolios; i++) {
> > 		struct folio *folio = page_folio(pages[i]);
> > 		...
> > 		unsigned int len = umin(ret, PAGE_SIZE - start);
> > 		...
> > 		ret -= len;
> > 		...
> > 	}
> > where the compiler doesn't track things well enough to know that
> > 'ret' is never negative.
> > 
> > The alternate loop:
> >         for (i = 0; ret > 0; i++) {
> >                 struct folio *folio = page_folio(pages[i]);
> >                 ...
> >                 unsigned int len = min(ret, PAGE_SIZE - start);
> >                 ...
> >                 ret -= len;
> >                 ...
> >         }
> > would be equivalent and doesn't need 'nfolios'.
> > 
> > Most of the 'unsigned long' actually come from PAGE_SIZE.
> > 
> > Detected by an extra check added to min_t().
> > 
> > Signed-off-by: David Laight <david.laight.linux@...il.com>  
> 
> When doing a mips cross compile from an arm64 host
> (via ARCH=mips CROSS_COMPILE=mips64-linux-gnu- make), the following
> build error occurs in linux-next and goes away when I revert this
> commit.

I've looked at this one before.
I think there is another patch lurking to fix it.

> In file included from <command-line>:                                                                                               
> In function ‘fuse_wr_pages’,                                                                                                        
>     inlined from ‘fuse_perform_write’ at fs/fuse/file.c:1347:27:                                                                    
> ././include/linux/compiler_types.h:667:45: error: call to ‘__compiletime_assert_405’ declared with attribute error: min(((pos + len 
> - 1) >> 12) - (pos >> 12) + 1, max_pages) signedness error                                                                          
...
> fs/fuse/file.c:1326:16: note: in expansion of macro ‘min’
>  1326 |         return min(((pos + len - 1) >> PAGE_SHIFT) - (pos >> PAGE_SHIFT) + 1,
				max_pages);

'len' is 'unsigned long' and the expression is unsigned on 64bit.
But 'pos' is s64 so the expression is signed on 32bit.
IIRC the final version might have been (equivalent to):
	len += pos & (PAGE_SIZE - 1);
	return min(DIV_ROUND_UP(len, PAGE_SIZE), max_pages);
which generates much better code as well (no 64bit maths).
I don't think len can overflow, read/write are limited to INT_MAX - PAGE_SIZE
bytes in the syscall interface.

	David

> 
> This is on a cento-stream-10 host running
> gcc version 14.3.1 20250617 (Red Hat 14.3.1-2) (GCC). I didn't look into
> this in detail, and I'm not entirely sure what the correct fix here
> should be.
> 
> Brian
> 


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ