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: <98ae03ab-ec73-4649-8a7a-71839d6e6eb0@lucifer.local>
Date: Thu, 6 Nov 2025 14:40:56 +0000
From: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
To: Ankit Khushwaha <ankitkhushwaha.linux@...il.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
        David Hildenbrand <david@...nel.org>,
        "Liam R. Howlett" <Liam.Howlett@...cle.com>,
        Vlastimil Babka <vbabka@...e.cz>, Mike Rapoport <rppt@...nel.org>,
        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 Thu, Nov 06, 2025 at 04:19:17PM +0530, 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.

Thanks for raising!

>
> Signed-off-by: Ankit Khushwaha <ankitkhushwaha.linux@...il.com>

See below, but the fix seems ok despite the existing code being really horrible
+ in need of rework:

Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>

> ---
>  tools/testing/selftests/mm/mremap_test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selftests/mm/mremap_test.c
> index a95c0663a011..5ae0400176af 100644
> --- a/tools/testing/selftests/mm/mremap_test.c
> +++ b/tools/testing/selftests/mm/mremap_test.c
> @@ -1032,7 +1032,7 @@ static long long remap_region(struct config c, unsigned int threshold_mb,
>  	/* Don't destroy existing mappings unless expected to overlap */
>  	while (!is_remap_region_valid(addr, c.region_size) && !c.overlapping) {
>  		/* Check for unsigned overflow */
> -		if (addr + c.dest_alignment < addr) {
> +		if ((unsigned long long) addr + c.dest_alignment < (unsigned long long) addr) {

Hmm this is odd though. gcc (and presumably for compatibility clang) treat void
* arithmetic as if void * was of size 1, so on 64-bit systems this should be:

64-bit value + 64-bit value < 64-bit value

Which is a valid check for overflow right?

On 32-bit it seems even more so:

32-bit value + 64-bit value < 64-bit value

So I'm not sure why this warning is happening.

Maybe clang is doing some very clever checks to determine this is false.

In practice I don't see how this could happen given userland pointers are
already restricted on upper bits.

BUT at the same time this is something that the rest of the test code does so it
seems fine to take this.

Also, (to be clear - it's not your fault Ankit):

This (existing code) is horrible, I don't know why we're using unsigned long
long _anyway_ here, the whole function is appalling.

Your fix is in line with the existing code but is still quite horrible (again
_not your fault_ :). So on the basis that it shuts this error up

I guess we can take this patch as the fix is equally as gross as the existing
code, but can we please:

a. do away with the unsigned long long nonsense if possible (presumably to try
   to detect overflow on 32-bit systems, but I do not understand why we are
   bothering it seems totally overengineered and pointless for arbitrary mremap
   tests)

b. For the love of all spiders, cats and other beautiful things on planet earth,
   let's please store a local unsigned long variable for the address and convert
   from void * _once_ :)

>  			ksft_print_msg("Couldn't find a valid region to remap to\n");
>  			ret = -1;
>  			goto clean_up_src;
> --
> 2.51.0
>

Thanks, Lorenzo

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ