1
0
mirror of https://github.com/Zygo/bees.git synced 2025-05-17 13:25:45 +02:00

openat2: create a weak syscall wrapper for it

openat2 allows closing more TOCTOU holes, but we can only use it when
the kernel supports it.

This should disappear seamlessly when libc implements the function.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
Zygo Blaxell 2025-01-09 01:16:02 -05:00
parent 613ddc3c71
commit a9b07d7684
3 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,17 @@
#ifndef CRUCIBLE_OPENAT2_H
#define CRUCIBLE_OPENAT2_H
#include <linux/openat2.h>
#include <fcntl.h>
#include <sys/syscall.h>
#include <unistd.h>
extern "C" {
/// Weak symbol to support libc with no syscall wrapper
int openat2(int dirfd, const char *pathname, struct open_how *how, size_t size) throw();
};
#endif // CRUCIBLE_OPENAT2_H

View File

@ -14,6 +14,7 @@ CRUCIBLE_OBJS = \
fs.o \
multilock.o \
ntoa.o \
openat2.o \
path.o \
process.o \
string.o \

13
lib/openat2.cc Normal file
View File

@ -0,0 +1,13 @@
#include "crucible/openat2.h"
extern "C" {
int
__attribute__((weak))
openat2(int const dirfd, const char *const pathname, struct open_how *const how, size_t const size)
throw()
{
return syscall(SYS_openat2, dirfd, pathname, how, size);
}
};