Bug 503641

Summary: close_range syscalls started failing with 3.25.0
Product: [Developer tools] valgrind Reporter: correctmost <cmbugz>
Component: generalAssignee: Paul Floyd <pjfloyd>
Status: RESOLVED FIXED    
Severity: normal CC: pjfloyd
Priority: NOR    
Version First Reported In: 3.25.0   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description correctmost 2025-05-02 04:22:52 UTC
SUMMARY

I run xfce4-session in Valgrind.  After upgrading to 3.25.0, I see errors like this:

xfce4-session-WARNING **: 22:03:59.181: Unable to launch "xfwm4": Failed to close file descriptor for child process (Invalid argument)

xfce4-session-WARNING **: 22:03:59.328: Unable to launch "xfsettingsd": Failed to close file descriptor for child process (Invalid argument)

I ran a bisection and found that the errors started with commit d984d9aabe5b89d6787c2604b72c09360e7b6fc0:
https://sourceware.org/git/?p=valgrind.git;a=commitdiff;h=d984d9aabe5b89d6787c2604b72c09360e7b6fc0

Here's an example syscall trace before that commit:

SYSCALL[15385,1](436) sys_close_range ( 4, 4294967295, 0 ) --> [pre-success] Success(0x0)

And a trace after that commit:

SYSCALL[29937,1](436) sys_close_range ( 4, 4294967295, 0 ) --> [pre-fail] Failure(0x16)

It seems like changing the first and last parameters to signed ints is causing the failures.

SOFTWARE/OS VERSIONS

Valgrind 3.25.0 on Arch Linux
Comment 1 Paul Floyd 2025-05-02 11:35:14 UTC
A small reproducer:

#include <unistd.h>
#include <cstdio>
#include <cerrno>
#include <linux/close_range.h>

int main(void)
{
    if (close_range(2, ~0U, 0) == -1)
    {
        perror("close_range failed:");
    }
}
Comment 2 Paul Floyd 2025-05-02 17:24:49 UTC
commit 933e542b431f17681cc915de656e853dc16d4fe7 (HEAD -> master, origin/master, origin/HEAD)
Author: Paul Floyd <pjfloyd@wanadoo.fr>
Date:   Fri May 2 18:53:09 2025 +0200

    Bug 503641 - close_range syscalls started failing with 3.25.0