Bug 397605 - ioctl FICLONE mishandled
Summary: ioctl FICLONE mishandled
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: 3.13.0
Platform: Debian unstable Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-19 07:02 UTC by Kenton Varda
Modified: 2020-12-20 19:36 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Patch to handle FICLONE ioctl on Linux (2.18 KB, text/plain)
2018-11-16 14:43 UTC, Laurent Bonnans
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kenton Varda 2018-08-19 07:02:56 UTC
The parameter to ioctl FICLONE is a file descriptor, as documented here:

http://man7.org/linux/man-pages/man2/ioctl_ficlonerange.2.html

However, valgrind seems to believe that it should be a pointer, and complains that the pointer is not valid, saying: "Syscall param ioctl(generic) points to unaddressable byte(s)"
Comment 1 Laurent Bonnans 2018-11-16 14:43:08 UTC
Created attachment 116351 [details]
Patch to handle FICLONE ioctl on Linux
Comment 2 Laurent Bonnans 2018-11-16 14:47:23 UTC
I've sent a patch to handle FICLONE correctly. It seems to me that the ioctl definition in Linux's uapi is misleading because it is set with a write direction but do not use the argument as a pointer (it is a file descriptor). Hence the error in the generic ioctl handler.

It can be tested by running this command on a btrfs filesystem (might do it with another fs, haven't tested):

    valgrind cp --reflink=always example.txt example_copy.txt
Comment 3 Balint Reczey 2020-02-18 08:46:46 UTC
I can confirm that the patch works and in would be nice to have in in the next Valgrind release.
I've set up a PPA with the patch applied:
https://launchpad.net/~rbalint/+archive/ubuntu/valgrind
Comment 4 Mark Wielaard 2020-12-20 19:36:25 UTC
Apologies this patch lingered so long. It does look correct, I replicated the issue and your analysis of how the _IOW uapi definition is misleading also seems correct. Pushed as:

commit 1c49351424f04ee29a5efc054cb08ab3ad22b978
Author: Laurent Bonnans <laurent.bonnans@here.com>
Date:   Fri Nov 16 15:22:18 2018 +0100

    Fix 397605 - Add support for Linux FICLONE ioctl