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] [day] [month] [year] [list]
Message-ID: <a7034e0c-a2ab-425a-8472-ef0a87a17681@suse.cz>
Date: Sun, 9 Nov 2025 20:11:09 +0100
From: Vlastimil Babka <vbabka@...e.cz>
To: Mike Rapoport <rppt@...nel.org>, Andrew Morton
 <akpm@...ux-foundation.org>, Nathan Chancellor <nathan@...nel.org>
Cc: "David Hildenbrand (Red Hat)" <david@...nel.org>,
 Ankit Khushwaha <ankitkhushwaha.linux@...il.com>,
 Lorenzo Stoakes <lorenzo.stoakes@...cle.com>,
 "Liam R. Howlett" <Liam.Howlett@...cle.com>,
 Suren Baghdasaryan <surenb@...gle.com>, Michal Hocko <mhocko@...e.com>,
 Shuah Khan <shuah@...nel.org>, linux-mm@...ck.org,
 linux-kselftest@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] selftest/mm: fix pointer comparison in mremap_test

On 11/9/25 07:54, Mike Rapoport wrote:
> (added Nathan for clang advice)
> 
> On Fri, Nov 07, 2025 at 04:08:55PM -0800, Andrew Morton wrote:
>> On Fri, 7 Nov 2025 10:27:27 +0100 "David Hildenbrand (Red Hat)" <david@...nel.org> wrote:
>> 
>> > On 06.11.25 13:02, Ankit Khushwaha wrote:
>> > > On Thu, Nov 06, 2025 at 12:18:57PM +0100, David Hildenbrand (Red Hat) wrote:
>> > >> On 06.11.25 11:49, Ankit Khushwaha wrote:
>> > >>> Pointer arthemitic with 'void * addr' and 'unsigned long long dest_alignment'
>> > >>> triggers following warning:
>> > >>>
>> > >>> mremap_test.c:1035:31: warning: pointer comparison always evaluates to
>> > >>> false [-Wtautological-compare]
>> > >>>    1035 |                 if (addr + c.dest_alignment < addr) {
>> > >>>         |                                             ^
>> > >>>
>> > >>> typecasting 'addr' to 'unsigned long long' to fix pointer comparison.
>> > >>
>> > >> With which compiler are you seeing this?
>> > > 
>> > > Hi David,
>> > > 
>> > > clang version 20.1.8 (Fedora 20.1.8-4.fc42) raised this warning.
>> > > 
>> > > To reproduce:
>> > > 	make -C tools/testing/selftests/mm CC=clang
>> > 
>> > Thanks, and thanks to Lorenzo for the details.
>> > 
>> > Acked-by: David Hildenbrand (Red Hat) <david@...nel.org>
>> 
>> I must say, applying this would be an unhappy life event.
>> 
>> 	if (void* + ulong < void*)
>> 
>> makes perfect sense in a world which permits void* arithmetic (ie,
>> ours).  So what the heck is clang doing??

My (not very informed) guess would be something about undefined behavior
because pointer arithmetic is strictly speaking only valid within an array,
so void* + ulong is also still in the same array, and thus can't become
smaller by an overflow, because overflow can't happen if we're still within
the same valid array...

But I don't know if this strictness is only applied to the warning itself or
to the actual compilation too (does it eliminate everything as dead code then?)

>> If we do
>> 
>> 	void *addr2 = addr + c.dest_alignment;
>> 	if (addr2 < addr)
>> 		...
>> 
>> then which statement warns, and why?

As the answer was that nothing warns, I'd think it just isn't able to warn
if it's no longer part of the same statement. Whether it also means it's not
eliminated as dead code anymore, dunno.


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ