Bug 498143

Summary: False positive on EVIOCGRAB ioctl.
Product: [Developer tools] valgrind Reporter: Tali Auster <me>
Component: generalAssignee: Julian Seward <jseward>
Status: RESOLVED FIXED    
Severity: minor CC: mark
Priority: NOR    
Version First Reported In: 3.23.0   
Target Milestone: ---   
Platform: Debian unstable   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Tali Auster 2025-01-02 07:05:13 UTC
The EVIOCGRAB ioctl takes as argument just one parameter and tests whether it's truthy: It does *not* dereference the argument. Valgrind, however, doesn't agree, and logs a warning like the following when one calls ioctl(fd, EVIOCGRAB, 1):

```
==6155== Thread 3:
==6155== Syscall param ioctl(generic) points to unaddressable byte(s)
==6155== at 0x4A9723B: ioctl (ioctl.c:36)
...
==6155== Address 0x1 is not stack'd, malloc'd or (recently) free'd
```

STEPS TO REPRODUCE
1.  Run valgrind on a program that calls ioctl(some_fd, EVIOCGRAB, 1); (or any other truthy value)

OBSERVED RESULT

False positive warning.


EXPECTED RESULT

No warning; this is safe code.

SOFTWARE/OS VERSIONS

This is on Debian Sid, but I've reproduced it on Fedora as well. This affects (at least) Linuxes 6.12.4 and 6.12.6. Valgrind v3.2.0 and 3.24.0.

ADDITIONAL INFORMATION

Let me know if there's any other info I can provide. Thanks :)
Comment 1 Mark Wielaard 2025-01-08 15:55:28 UTC
This was an easy fix:

commit 59eb5a4af60d4beb2c6910a1fa6cdf8d1f3a56f2 (HEAD -> master)
Author: Mark Wielaard <mark@klomp.org>
Date:   Wed Jan 8 16:52:03 2025 +0100

    linux: support EVIOCGRAB ioctl
    
    EVIOCGRAB just takes an int argument.
    
    https://bugs.kde.org/show_bug.cgi?id=498143

We do support some, but not all, input device ioctls.
Please file another report if others are missing.
Comment 2 Mark Wielaard 2025-01-12 23:23:01 UTC
Also pushed to  VALGRIND_3_24_BRANCH

commit b732f86998e39ca8714330f487804428b54c481c
Author: Mark Wielaard <mark@klomp.org>
Date:   Wed Jan 8 16:52:03 2025 +0100

    linux: support EVIOCGRAB ioctl
    
    EVIOCGRAB just takes an int argument.
    
    https://bugs.kde.org/show_bug.cgi?id=498143
    
    (cherry picked from commit 59eb5a4af60d4beb2c6910a1fa6cdf8d1f3a56f2)
Comment 3 Tali Auster 2025-01-13 02:29:46 UTC
Thanks! Glad the fix was simple :)