Bug 433873

Summary: openat2 syscall unimplemented on Linux
Product: [Developer tools] valgrind Reporter: Drew DeVault <sir>
Component: generalAssignee: Julian Seward <jseward>
Status: RESOLVED FIXED    
Severity: normal CC: pjfloyd, sam
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Program which demonstrates the use of the openat2 syscall
diff for opnenat2
patch for openat2
patch for openat2

Description Drew DeVault 2021-03-02 20:03:21 UTC
syscall 437 (on amd64), openat2, is not implemented by Valgrind.
Comment 1 Paul Floyd 2021-03-03 07:25:01 UTC
Do you have a small testcase to reproduce this?
Comment 2 Drew DeVault 2021-03-03 13:53:37 UTC
Created attachment 136343 [details]
Program which demonstrates the use of the openat2 syscall

Sure thing. Here's a test program.
Comment 3 Paul Floyd 2021-11-03 21:46:22 UTC
Created attachment 143181 [details]
diff for opnenat2

Here is the start of an implementation. Mostly it's just a copy/paste of sys_openat, with the args changed to use struct open_how*, and also to do more thorouhg checking of the args.

I'm not sure if the values of VKI_O_DIRECTORY / VKI___O_TMPFILE / VKI_O_TMPFILE are generic across Linux hardware platforms. If they are then they need to be moved to include/vki/vki-linux.h. If not they need to be moved to the platform versions of vki-linux.h
Comment 4 Paul Floyd 2021-11-03 22:18:33 UTC
Created attachment 143183 [details]
patch  for openat2

This time
- make sure masks are extended to unsigned long long
- use resolved field rather than mistakenly mode
Comment 5 Paul Floyd 2021-11-03 22:31:16 UTC
I had a little difficulty compiling the example code, ended up copying/pasting a few ofd the octal flags from /usr/include/asm-generic/fcntl.h directly into the file.

I based the mode/flags and resolve checks on this comment in openat.h

 * Arguments for how openat2(2) should open the target path. If only @flags and
 * @mode are non-zero, then openat2(2) operates very similarly to openat(2).
 *
 * However, unlike openat(2), unknown or invalid bits in @flags result in
 * -EINVAL rather than being silently ignored. @mode must be zero unless one of
 * {O_CREAT, O_TMPFILE} are set.
Comment 6 Paul Floyd 2021-11-03 22:32:21 UTC
Created attachment 143184 [details]
patch  for openat2

Third time lucky with the flag checks.
Comment 7 Paul Floyd 2023-01-06 11:44:51 UTC
Hmm. I should perhaps land this. Need some tests (scalar at least).
Comment 8 Paul Floyd 2023-01-06 20:28:33 UTC
Should be fixed with this commit

commit 2c93baf53a652fd503c0c21bccb7e85363f43e58 (HEAD -> master, origin/master, origin/HEAD)
Author: Paul Floyd <pjfloyd@wanadoo.fr>
Date:   Fri Jan 6 21:27:01 2023 +0100

    BugĀ 433873 - openat2 syscall unimplemented on Linux
    
    This syscall is not exposed via glibc, so there is only an
    addition to the scalar test.