From c4ebb84eede7a03f1934e6343de1127ff5538ca3 Mon Sep 17 00:00:00 2001 From: Markus Mayer Date: Wed, 27 May 2026 17:44:37 -0700 Subject: [PATCH 1/2] build: auto-detect the presence of the openat2() syscall Let configure detect if the openat2() syscall is supported by the kernel headers we are building against. Do not attempt to use openat2() if support is not present. Users can still disable using the openat2() syscall manually if so desired. Signed-off-by: Markus Mayer --- configure.ac | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 4faab5fcb..2016b3a6b 100644 --- a/configure.ac +++ b/configure.ac @@ -103,10 +103,6 @@ dnl (and coverage-counted) without needing a pre-5.6 kernel. Behaviour-neutral dnl by default (the knob only REMOVES a tier when explicitly disabled). AC_ARG_ENABLE(openat2, AS_HELP_STRING([--disable-openat2],[do not use Linux openat2(RESOLVE_BENEATH); force the portable resolver (for exercising the fallback tier)])) -if test x"$enable_openat2" != x"no"; then - AC_DEFINE([HAVE_OPENAT2], 1, - [Define to use Linux openat2(RESOLVE_BENEATH) in secure_relative_open where available.]) -fi AC_MSG_CHECKING([if md2man can create manpages]) if test x"$ac_cv_path_PYTHON3" = x; then @@ -357,6 +353,19 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[return 0;]])], CFLAGS="$OLD_CFLAGS" AC_SUBST(NOEXECSTACK) +AC_CACHE_CHECK([for openat2],rsync_cv_HAVE_OPENAT2,[ + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[#include ]], [[int i = SYS_openat2]]) + ], + [rsync_cv_HAVE_OPENAT2=yes], [rsync_cv_HAVE_OPENAT2=no]) +]) +if test x"$enable_openat2" != x"no"; then + if test x"$rsync_cv_HAVE_OPENAT2" = x"yes"; then + AC_DEFINE([HAVE_OPENAT2], 1, + [Define to use Linux openat2(RESOLVE_BENEATH) in secure_relative_open where available.]) + fi +fi + # arrgh. libc in some old debian version screwed up the largefile # stuff, getting byte range locking wrong AC_CACHE_CHECK([for broken largefile support],rsync_cv_HAVE_BROKEN_LARGEFILE,[ From fcd22c48dbb0cf99617386d9c133642ad5d945f3 Mon Sep 17 00:00:00 2001 From: Markus Mayer Date: Fri, 29 May 2026 10:15:13 -0700 Subject: [PATCH 2/2] t_chmod_secure: use HAVE_OPENAT2 to check for openat2() support To prevent using openat2() in situations where it is not supported, use #if defined(__linux__) && defined(HAVE_OPENAT2) in t_chmod_secure.c, just like it was already being done in syscall.c. Signed-off-by: Markus Mayer --- t_chmod_secure.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t_chmod_secure.c b/t_chmod_secure.c index 7c57dbbca..130c74195 100644 --- a/t_chmod_secure.c +++ b/t_chmod_secure.c @@ -17,7 +17,7 @@ #include -#ifdef __linux__ +#if defined(__linux__) && defined(HAVE_OPENAT2) #include #include #endif @@ -45,7 +45,7 @@ static int errs = 0; static int kernel_resolve_beneath_supported(void) { int fd; -#ifdef __linux__ +#if defined(__linux__) && defined(HAVE_OPENAT2) { struct open_how how; memset(&how, 0, sizeof how);