From 6ca5be8d3f3d0ff69f04b2d76a0efa7ad7dfd694 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 28 Feb 2025 21:49:03 +0900 Subject: [PATCH 01/36] missing_syscall: memfd_create() is supported by glibc since 2.27 Now, our baseline of glibc is 2.31, hence it is OK to drop it. --- meson.build | 1 - src/basic/missing_mman.h | 14 +------ src/basic/missing_syscall.h | 10 ----- src/basic/missing_syscall_def.h | 68 --------------------------------- src/basic/missing_syscalls.py | 1 - 5 files changed, 2 insertions(+), 92 deletions(-) diff --git a/meson.build b/meson.build index f4fd28410f..a92d9f2cb0 100644 --- a/meson.build +++ b/meson.build @@ -603,7 +603,6 @@ foreach ident : ['secure_getenv', '__secure_getenv'] endforeach foreach ident : [ - ['memfd_create', '''#include '''], ['gettid', '''#include #include '''], ['fchmodat2', '''#include diff --git a/src/basic/missing_mman.h b/src/basic/missing_mman.h index d6a8b4bb9e..29196b1c71 100644 --- a/src/basic/missing_mman.h +++ b/src/basic/missing_mman.h @@ -5,24 +5,14 @@ #include "macro.h" -#ifndef MFD_ALLOW_SEALING -# define MFD_ALLOW_SEALING 0x0002U -#else -assert_cc(MFD_ALLOW_SEALING == 0x0002U); -#endif - -#ifndef MFD_CLOEXEC -# define MFD_CLOEXEC 0x0001U -#else -assert_cc(MFD_CLOEXEC == 0x0001U); -#endif - +/* since glibc-2.38 */ #ifndef MFD_NOEXEC_SEAL # define MFD_NOEXEC_SEAL 0x0008U #else assert_cc(MFD_NOEXEC_SEAL == 0x0008U); #endif +/* since glibc-2.38 */ #ifndef MFD_EXEC # define MFD_EXEC 0x0010U #else diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index 3eab1a27ef..531e2fafb4 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -68,16 +68,6 @@ static inline int missing_ioprio_set(int which, int who, int ioprio) { /* ======================================================================= */ -#if !HAVE_MEMFD_CREATE -static inline int missing_memfd_create(const char *name, unsigned int flags) { - return syscall(__NR_memfd_create, name, flags); -} - -# define memfd_create missing_memfd_create -#endif - -/* ======================================================================= */ - #if !HAVE_GETRANDOM /* glibc says getrandom() returns ssize_t */ static inline ssize_t missing_getrandom(void *buffer, size_t count, unsigned flags) { diff --git a/src/basic/missing_syscall_def.h b/src/basic/missing_syscall_def.h index e042b6be88..0b4a6190e1 100644 --- a/src/basic/missing_syscall_def.h +++ b/src/basic/missing_syscall_def.h @@ -382,74 +382,6 @@ assert_cc(__NR_getrandom == systemd_NR_getrandom); # endif #endif -#ifndef __IGNORE_memfd_create -# if defined(__aarch64__) -# define systemd_NR_memfd_create 279 -# elif defined(__alpha__) -# define systemd_NR_memfd_create 512 -# elif defined(__arc__) || defined(__tilegx__) -# define systemd_NR_memfd_create 279 -# elif defined(__arm__) -# define systemd_NR_memfd_create 385 -# elif defined(__i386__) -# define systemd_NR_memfd_create 356 -# elif defined(__ia64__) -# define systemd_NR_memfd_create 1340 -# elif defined(__loongarch_lp64) -# define systemd_NR_memfd_create 279 -# elif defined(__m68k__) -# define systemd_NR_memfd_create 353 -# elif defined(_MIPS_SIM) -# if _MIPS_SIM == _MIPS_SIM_ABI32 -# define systemd_NR_memfd_create 4354 -# elif _MIPS_SIM == _MIPS_SIM_NABI32 -# define systemd_NR_memfd_create 6318 -# elif _MIPS_SIM == _MIPS_SIM_ABI64 -# define systemd_NR_memfd_create 5314 -# else -# error "Unknown MIPS ABI" -# endif -# elif defined(__hppa__) -# define systemd_NR_memfd_create 340 -# elif defined(__powerpc__) -# define systemd_NR_memfd_create 360 -# elif defined(__riscv) -# if __riscv_xlen == 32 -# define systemd_NR_memfd_create 279 -# elif __riscv_xlen == 64 -# define systemd_NR_memfd_create 279 -# else -# error "Unknown RISC-V ABI" -# endif -# elif defined(__s390__) -# define systemd_NR_memfd_create 350 -# elif defined(__sparc__) -# define systemd_NR_memfd_create 348 -# elif defined(__x86_64__) -# if defined(__ILP32__) -# define systemd_NR_memfd_create (319 | /* __X32_SYSCALL_BIT */ 0x40000000) -# else -# define systemd_NR_memfd_create 319 -# endif -# elif !defined(missing_arch_template) -# warning "memfd_create() syscall number is unknown for your architecture" -# endif - -/* may be an (invalid) negative number due to libseccomp, see PR 13319 */ -# if defined __NR_memfd_create && __NR_memfd_create >= 0 -# if defined systemd_NR_memfd_create -assert_cc(__NR_memfd_create == systemd_NR_memfd_create); -# endif -# else -# if defined __NR_memfd_create -# undef __NR_memfd_create -# endif -# if defined systemd_NR_memfd_create && systemd_NR_memfd_create >= 0 -# define __NR_memfd_create systemd_NR_memfd_create -# endif -# endif -#endif - #ifndef __IGNORE_mount_setattr # if defined(__aarch64__) # define systemd_NR_mount_setattr 442 diff --git a/src/basic/missing_syscalls.py b/src/basic/missing_syscalls.py index e84e0afc20..e7c16f6406 100644 --- a/src/basic/missing_syscalls.py +++ b/src/basic/missing_syscalls.py @@ -11,7 +11,6 @@ SYSCALLS = [ 'copy_file_range', 'fchmodat2', 'getrandom', - 'memfd_create', 'mount_setattr', 'move_mount', 'name_to_handle_at', From 69a5c4b14c2aea4897029a12a1a0310e59dbe670 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 28 Feb 2025 22:17:01 +0900 Subject: [PATCH 02/36] missing_syscall: getrandom is supported by glibc since 2.25 Now our baseline of glibc is 2.31, hence it is OK to drop our definition. --- meson.build | 1 - src/basic/missing_random.h | 21 ++-------- src/basic/missing_syscall.h | 11 ------ src/basic/missing_syscall_def.h | 68 --------------------------------- src/basic/missing_syscalls.py | 1 - 5 files changed, 3 insertions(+), 99 deletions(-) diff --git a/meson.build b/meson.build index a92d9f2cb0..de89853134 100644 --- a/meson.build +++ b/meson.build @@ -663,7 +663,6 @@ foreach ident : [ ['getdents64', '''#include '''], ['pidfd_spawn', '''#include '''], ['strerrorname_np', '''#include '''], - ['getrandom', '''#include '''], ['quotactl_fd', '''#include '''], ['setxattrat', '''#include '''], # no known header declares setxattrat ['removexattrat', '''#include '''], # no known header declares removexattrat diff --git a/src/basic/missing_random.h b/src/basic/missing_random.h index 5f40c4e58c..690021969e 100644 --- a/src/basic/missing_random.h +++ b/src/basic/missing_random.h @@ -1,26 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include + #include "macro.h" -#if HAVE_GETRANDOM -# include -#else -# include -#endif - -#ifndef GRND_NONBLOCK -# define GRND_NONBLOCK 0x0001 -#else -assert_cc(GRND_NONBLOCK == 0x0001); -#endif - -#ifndef GRND_RANDOM -# define GRND_RANDOM 0x0002 -#else -assert_cc(GRND_RANDOM == 0x0002); -#endif - +/* Defined since glibc-2.32. */ #ifndef GRND_INSECURE # define GRND_INSECURE 0x0004 #else diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index 531e2fafb4..5369cc5358 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -68,17 +68,6 @@ static inline int missing_ioprio_set(int which, int who, int ioprio) { /* ======================================================================= */ -#if !HAVE_GETRANDOM -/* glibc says getrandom() returns ssize_t */ -static inline ssize_t missing_getrandom(void *buffer, size_t count, unsigned flags) { - return syscall(__NR_getrandom, buffer, count, flags); -} - -# define getrandom missing_getrandom -#endif - -/* ======================================================================= */ - /* The syscall has been defined since forever, but the glibc wrapper was missing. */ #if !HAVE_GETTID static inline pid_t missing_gettid(void) { diff --git a/src/basic/missing_syscall_def.h b/src/basic/missing_syscall_def.h index 0b4a6190e1..a98a2a2030 100644 --- a/src/basic/missing_syscall_def.h +++ b/src/basic/missing_syscall_def.h @@ -314,74 +314,6 @@ assert_cc(__NR_fchmodat2 == systemd_NR_fchmodat2); # endif #endif -#ifndef __IGNORE_getrandom -# if defined(__aarch64__) -# define systemd_NR_getrandom 278 -# elif defined(__alpha__) -# define systemd_NR_getrandom 511 -# elif defined(__arc__) || defined(__tilegx__) -# define systemd_NR_getrandom 278 -# elif defined(__arm__) -# define systemd_NR_getrandom 384 -# elif defined(__i386__) -# define systemd_NR_getrandom 355 -# elif defined(__ia64__) -# define systemd_NR_getrandom 1339 -# elif defined(__loongarch_lp64) -# define systemd_NR_getrandom 278 -# elif defined(__m68k__) -# define systemd_NR_getrandom 352 -# elif defined(_MIPS_SIM) -# if _MIPS_SIM == _MIPS_SIM_ABI32 -# define systemd_NR_getrandom 4353 -# elif _MIPS_SIM == _MIPS_SIM_NABI32 -# define systemd_NR_getrandom 6317 -# elif _MIPS_SIM == _MIPS_SIM_ABI64 -# define systemd_NR_getrandom 5313 -# else -# error "Unknown MIPS ABI" -# endif -# elif defined(__hppa__) -# define systemd_NR_getrandom 339 -# elif defined(__powerpc__) -# define systemd_NR_getrandom 359 -# elif defined(__riscv) -# if __riscv_xlen == 32 -# define systemd_NR_getrandom 278 -# elif __riscv_xlen == 64 -# define systemd_NR_getrandom 278 -# else -# error "Unknown RISC-V ABI" -# endif -# elif defined(__s390__) -# define systemd_NR_getrandom 349 -# elif defined(__sparc__) -# define systemd_NR_getrandom 347 -# elif defined(__x86_64__) -# if defined(__ILP32__) -# define systemd_NR_getrandom (318 | /* __X32_SYSCALL_BIT */ 0x40000000) -# else -# define systemd_NR_getrandom 318 -# endif -# elif !defined(missing_arch_template) -# warning "getrandom() syscall number is unknown for your architecture" -# endif - -/* may be an (invalid) negative number due to libseccomp, see PR 13319 */ -# if defined __NR_getrandom && __NR_getrandom >= 0 -# if defined systemd_NR_getrandom -assert_cc(__NR_getrandom == systemd_NR_getrandom); -# endif -# else -# if defined __NR_getrandom -# undef __NR_getrandom -# endif -# if defined systemd_NR_getrandom && systemd_NR_getrandom >= 0 -# define __NR_getrandom systemd_NR_getrandom -# endif -# endif -#endif - #ifndef __IGNORE_mount_setattr # if defined(__aarch64__) # define systemd_NR_mount_setattr 442 diff --git a/src/basic/missing_syscalls.py b/src/basic/missing_syscalls.py index e7c16f6406..81ef4feef6 100644 --- a/src/basic/missing_syscalls.py +++ b/src/basic/missing_syscalls.py @@ -10,7 +10,6 @@ SYSCALLS = [ 'close_range', 'copy_file_range', 'fchmodat2', - 'getrandom', 'mount_setattr', 'move_mount', 'name_to_handle_at', From 65e844bdb884521cbbf8336a027fff57c7f63edb Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 28 Feb 2025 22:27:32 +0900 Subject: [PATCH 03/36] missing_syscall: gettid is supported by glibc since 2.30 Now our baseline of glibc is 2.31, hence it is OK to drop our definition. --- meson.build | 2 -- src/basic/missing_syscall.h | 15 --------------- 2 files changed, 17 deletions(-) diff --git a/meson.build b/meson.build index de89853134..0b4e3bab3e 100644 --- a/meson.build +++ b/meson.build @@ -603,8 +603,6 @@ foreach ident : ['secure_getenv', '__secure_getenv'] endforeach foreach ident : [ - ['gettid', '''#include - #include '''], ['fchmodat2', '''#include #include '''], # no known header declares fchmodat2 ['pivot_root', '''#include diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index 5369cc5358..757cfdea19 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -68,21 +68,6 @@ static inline int missing_ioprio_set(int which, int who, int ioprio) { /* ======================================================================= */ -/* The syscall has been defined since forever, but the glibc wrapper was missing. */ -#if !HAVE_GETTID -static inline pid_t missing_gettid(void) { -# if defined __NR_gettid && __NR_gettid >= 0 - return (pid_t) syscall(__NR_gettid); -# else -# error "__NR_gettid not defined" -# endif -} - -# define gettid missing_gettid -#endif - -/* ======================================================================= */ - #if !HAVE_NAME_TO_HANDLE_AT struct file_handle { unsigned int handle_bytes; From 96ff465861f090a971949bb887852050c2fe4f09 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 28 Feb 2025 22:30:42 +0900 Subject: [PATCH 04/36] missing_syscall: name_to_handle_at is supported by glibc since 2.14 Now our baseline of glibc is 2.31, hence it is OK to drop our definition. --- meson.build | 3 -- src/basic/missing_fcntl.h | 1 + src/basic/missing_syscall.h | 21 ---------- src/basic/missing_syscall_def.h | 68 --------------------------------- src/basic/missing_syscalls.py | 1 - 5 files changed, 1 insertion(+), 93 deletions(-) diff --git a/meson.build b/meson.build index 0b4e3bab3e..fe8188acab 100644 --- a/meson.build +++ b/meson.build @@ -610,9 +610,6 @@ foreach ident : [ ['ioprio_get', '''#include '''], # no known header declares ioprio_get ['ioprio_set', '''#include '''], # no known header declares ioprio_set ['sched_setattr', '''#include '''], - ['name_to_handle_at', '''#include - #include - #include '''], ['setns', '''#include '''], ['renameat2', '''#include #include '''], diff --git a/src/basic/missing_fcntl.h b/src/basic/missing_fcntl.h index a6188879c1..b02c7be7a4 100644 --- a/src/basic/missing_fcntl.h +++ b/src/basic/missing_fcntl.h @@ -97,6 +97,7 @@ #endif #endif +/* This is defined since glibc-2.39. */ #ifndef AT_HANDLE_FID #define AT_HANDLE_FID AT_REMOVEDIR #endif diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index 757cfdea19..fac6f30b2f 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -68,27 +68,6 @@ static inline int missing_ioprio_set(int which, int who, int ioprio) { /* ======================================================================= */ -#if !HAVE_NAME_TO_HANDLE_AT -struct file_handle { - unsigned int handle_bytes; - int handle_type; - unsigned char f_handle[0]; -}; - -static inline int missing_name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) { -# ifdef __NR_name_to_handle_at - return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags); -# else - errno = ENOSYS; - return -1; -# endif -} - -# define name_to_handle_at missing_name_to_handle_at -#endif - -/* ======================================================================= */ - #if !HAVE_SETNS static inline int missing_setns(int fd, int nstype) { return syscall(__NR_setns, fd, nstype); diff --git a/src/basic/missing_syscall_def.h b/src/basic/missing_syscall_def.h index a98a2a2030..f35a6f2348 100644 --- a/src/basic/missing_syscall_def.h +++ b/src/basic/missing_syscall_def.h @@ -450,74 +450,6 @@ assert_cc(__NR_move_mount == systemd_NR_move_mount); # endif #endif -#ifndef __IGNORE_name_to_handle_at -# if defined(__aarch64__) -# define systemd_NR_name_to_handle_at 264 -# elif defined(__alpha__) -# define systemd_NR_name_to_handle_at 497 -# elif defined(__arc__) || defined(__tilegx__) -# define systemd_NR_name_to_handle_at 264 -# elif defined(__arm__) -# define systemd_NR_name_to_handle_at 370 -# elif defined(__i386__) -# define systemd_NR_name_to_handle_at 341 -# elif defined(__ia64__) -# define systemd_NR_name_to_handle_at 1326 -# elif defined(__loongarch_lp64) -# define systemd_NR_name_to_handle_at 264 -# elif defined(__m68k__) -# define systemd_NR_name_to_handle_at 340 -# elif defined(_MIPS_SIM) -# if _MIPS_SIM == _MIPS_SIM_ABI32 -# define systemd_NR_name_to_handle_at 4339 -# elif _MIPS_SIM == _MIPS_SIM_NABI32 -# define systemd_NR_name_to_handle_at 6303 -# elif _MIPS_SIM == _MIPS_SIM_ABI64 -# define systemd_NR_name_to_handle_at 5298 -# else -# error "Unknown MIPS ABI" -# endif -# elif defined(__hppa__) -# define systemd_NR_name_to_handle_at 325 -# elif defined(__powerpc__) -# define systemd_NR_name_to_handle_at 345 -# elif defined(__riscv) -# if __riscv_xlen == 32 -# define systemd_NR_name_to_handle_at 264 -# elif __riscv_xlen == 64 -# define systemd_NR_name_to_handle_at 264 -# else -# error "Unknown RISC-V ABI" -# endif -# elif defined(__s390__) -# define systemd_NR_name_to_handle_at 335 -# elif defined(__sparc__) -# define systemd_NR_name_to_handle_at 332 -# elif defined(__x86_64__) -# if defined(__ILP32__) -# define systemd_NR_name_to_handle_at (303 | /* __X32_SYSCALL_BIT */ 0x40000000) -# else -# define systemd_NR_name_to_handle_at 303 -# endif -# elif !defined(missing_arch_template) -# warning "name_to_handle_at() syscall number is unknown for your architecture" -# endif - -/* may be an (invalid) negative number due to libseccomp, see PR 13319 */ -# if defined __NR_name_to_handle_at && __NR_name_to_handle_at >= 0 -# if defined systemd_NR_name_to_handle_at -assert_cc(__NR_name_to_handle_at == systemd_NR_name_to_handle_at); -# endif -# else -# if defined __NR_name_to_handle_at -# undef __NR_name_to_handle_at -# endif -# if defined systemd_NR_name_to_handle_at && systemd_NR_name_to_handle_at >= 0 -# define __NR_name_to_handle_at systemd_NR_name_to_handle_at -# endif -# endif -#endif - #ifndef __IGNORE_open_tree # if defined(__aarch64__) # define systemd_NR_open_tree 428 diff --git a/src/basic/missing_syscalls.py b/src/basic/missing_syscalls.py index 81ef4feef6..59705471df 100644 --- a/src/basic/missing_syscalls.py +++ b/src/basic/missing_syscalls.py @@ -12,7 +12,6 @@ SYSCALLS = [ 'fchmodat2', 'mount_setattr', 'move_mount', - 'name_to_handle_at', 'open_tree', 'openat2', 'pidfd_open', From d322854cacfef1e06ce2f6dac2b4b933361c0842 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 28 Feb 2025 22:45:25 +0900 Subject: [PATCH 05/36] missing_syscall: setns is supported by glibc since 2.14 Also, CLONE_PIDFD is defined in sched.h since 2.31. Now our baseline of glibc is 2.31, hence it is OK to drop our definition. --- meson.build | 1 - src/basic/missing_sched.h | 17 +-------- src/basic/missing_syscall.h | 10 ----- src/basic/missing_syscall_def.h | 68 --------------------------------- src/basic/missing_syscalls.py | 1 - 5 files changed, 2 insertions(+), 95 deletions(-) diff --git a/meson.build b/meson.build index fe8188acab..ea47d1359a 100644 --- a/meson.build +++ b/meson.build @@ -610,7 +610,6 @@ foreach ident : [ ['ioprio_get', '''#include '''], # no known header declares ioprio_get ['ioprio_set', '''#include '''], # no known header declares ioprio_set ['sched_setattr', '''#include '''], - ['setns', '''#include '''], ['renameat2', '''#include #include '''], ['kcmp', '''#include '''], diff --git a/src/basic/missing_sched.h b/src/basic/missing_sched.h index 6e5e2b1e20..d8e2b6d3c7 100644 --- a/src/basic/missing_sched.h +++ b/src/basic/missing_sched.h @@ -6,21 +6,8 @@ #include "macro.h" -/* 5e2bec7c2248ae27c5b16cd97215ae05c1d39179 (4.6) */ -#ifndef CLONE_NEWCGROUP -# define CLONE_NEWCGROUP 0x02000000 -#else -assert_cc(CLONE_NEWCGROUP == 0x02000000); -#endif - -/* b3e5838252665ee4cfa76b82bdf1198dca81e5be (5.2) */ -#ifndef CLONE_PIDFD -# define CLONE_PIDFD 0x00001000 -#else -assert_cc(CLONE_PIDFD == 0x00001000); -#endif - -/* 769071ac9f20b6a447410c7eaa55d1a5233ef40c (5.8) */ +/* 769071ac9f20b6a447410c7eaa55d1a5233ef40c (5.8), + * defined in sched.h since glibc-2.36. */ #ifndef CLONE_NEWTIME # define CLONE_NEWTIME 0x00000080 #else diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index fac6f30b2f..e9b6548ccd 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -68,16 +68,6 @@ static inline int missing_ioprio_set(int which, int who, int ioprio) { /* ======================================================================= */ -#if !HAVE_SETNS -static inline int missing_setns(int fd, int nstype) { - return syscall(__NR_setns, fd, nstype); -} - -# define setns missing_setns -#endif - -/* ======================================================================= */ - static inline pid_t raw_getpid(void) { #if defined(__alpha__) return (pid_t) syscall(__NR_getxpid); diff --git a/src/basic/missing_syscall_def.h b/src/basic/missing_syscall_def.h index f35a6f2348..1bd4889dac 100644 --- a/src/basic/missing_syscall_def.h +++ b/src/basic/missing_syscall_def.h @@ -994,74 +994,6 @@ assert_cc(__NR_renameat2 == systemd_NR_renameat2); # endif #endif -#ifndef __IGNORE_setns -# if defined(__aarch64__) -# define systemd_NR_setns 268 -# elif defined(__alpha__) -# define systemd_NR_setns 501 -# elif defined(__arc__) || defined(__tilegx__) -# define systemd_NR_setns 268 -# elif defined(__arm__) -# define systemd_NR_setns 375 -# elif defined(__i386__) -# define systemd_NR_setns 346 -# elif defined(__ia64__) -# define systemd_NR_setns 1330 -# elif defined(__loongarch_lp64) -# define systemd_NR_setns 268 -# elif defined(__m68k__) -# define systemd_NR_setns 344 -# elif defined(_MIPS_SIM) -# if _MIPS_SIM == _MIPS_SIM_ABI32 -# define systemd_NR_setns 4344 -# elif _MIPS_SIM == _MIPS_SIM_NABI32 -# define systemd_NR_setns 6308 -# elif _MIPS_SIM == _MIPS_SIM_ABI64 -# define systemd_NR_setns 5303 -# else -# error "Unknown MIPS ABI" -# endif -# elif defined(__hppa__) -# define systemd_NR_setns 328 -# elif defined(__powerpc__) -# define systemd_NR_setns 350 -# elif defined(__riscv) -# if __riscv_xlen == 32 -# define systemd_NR_setns 268 -# elif __riscv_xlen == 64 -# define systemd_NR_setns 268 -# else -# error "Unknown RISC-V ABI" -# endif -# elif defined(__s390__) -# define systemd_NR_setns 339 -# elif defined(__sparc__) -# define systemd_NR_setns 337 -# elif defined(__x86_64__) -# if defined(__ILP32__) -# define systemd_NR_setns (308 | /* __X32_SYSCALL_BIT */ 0x40000000) -# else -# define systemd_NR_setns 308 -# endif -# elif !defined(missing_arch_template) -# warning "setns() syscall number is unknown for your architecture" -# endif - -/* may be an (invalid) negative number due to libseccomp, see PR 13319 */ -# if defined __NR_setns && __NR_setns >= 0 -# if defined systemd_NR_setns -assert_cc(__NR_setns == systemd_NR_setns); -# endif -# else -# if defined __NR_setns -# undef __NR_setns -# endif -# if defined systemd_NR_setns && systemd_NR_setns >= 0 -# define __NR_setns systemd_NR_setns -# endif -# endif -#endif - #ifndef __IGNORE_setxattrat # if defined(__aarch64__) # define systemd_NR_setxattrat 463 diff --git a/src/basic/missing_syscalls.py b/src/basic/missing_syscalls.py index 59705471df..0302fa424a 100644 --- a/src/basic/missing_syscalls.py +++ b/src/basic/missing_syscalls.py @@ -20,7 +20,6 @@ SYSCALLS = [ 'quotactl_fd', 'removexattrat', 'renameat2', - 'setns', 'setxattrat', ] From f2786bd3e7f1f2c813aa2ddf242c3a8593449b1e Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 28 Feb 2025 22:50:32 +0900 Subject: [PATCH 06/36] missing_syscall: renameat2 is supported by glibc since 2.28 Now our baseline of glibc is 2.31, hence it is OK to drop our definition. --- meson.build | 2 - src/basic/missing_fs.h | 4 -- src/basic/missing_syscall.h | 10 ----- src/basic/missing_syscall_def.h | 68 --------------------------------- src/basic/missing_syscalls.py | 1 - 5 files changed, 85 deletions(-) diff --git a/meson.build b/meson.build index ea47d1359a..ca7af554ac 100644 --- a/meson.build +++ b/meson.build @@ -610,8 +610,6 @@ foreach ident : [ ['ioprio_get', '''#include '''], # no known header declares ioprio_get ['ioprio_set', '''#include '''], # no known header declares ioprio_set ['sched_setattr', '''#include '''], - ['renameat2', '''#include - #include '''], ['kcmp', '''#include '''], ['keyctl', '''#include #include '''], diff --git a/src/basic/missing_fs.h b/src/basic/missing_fs.h index 60b0a3a2a7..5c64cb6e0c 100644 --- a/src/basic/missing_fs.h +++ b/src/basic/missing_fs.h @@ -6,10 +6,6 @@ #include "macro.h" /* linux/fs.h */ -#ifndef RENAME_NOREPLACE /* 0a7c3937a1f23f8cb5fc77ae01661e9968a51d0c (3.15) */ -#define RENAME_NOREPLACE (1 << 0) -#endif - #ifndef BLKGETDISKSEQ /* 7957d93bf32bc211415827e44fdd9cdf1388df59 (5.15) */ #define BLKGETDISKSEQ _IOR(0x12,128,__u64) #endif diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index e9b6548ccd..2eff224a47 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -78,16 +78,6 @@ static inline pid_t raw_getpid(void) { /* ======================================================================= */ -#if !HAVE_RENAMEAT2 -static inline int missing_renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) { - return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags); -} - -# define renameat2 missing_renameat2 -#endif - -/* ======================================================================= */ - #if !HAVE_KCMP static inline int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) { return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2); diff --git a/src/basic/missing_syscall_def.h b/src/basic/missing_syscall_def.h index 1bd4889dac..7e1c6a3c99 100644 --- a/src/basic/missing_syscall_def.h +++ b/src/basic/missing_syscall_def.h @@ -926,74 +926,6 @@ assert_cc(__NR_removexattrat == systemd_NR_removexattrat); # endif #endif -#ifndef __IGNORE_renameat2 -# if defined(__aarch64__) -# define systemd_NR_renameat2 276 -# elif defined(__alpha__) -# define systemd_NR_renameat2 510 -# elif defined(__arc__) || defined(__tilegx__) -# define systemd_NR_renameat2 276 -# elif defined(__arm__) -# define systemd_NR_renameat2 382 -# elif defined(__i386__) -# define systemd_NR_renameat2 353 -# elif defined(__ia64__) -# define systemd_NR_renameat2 1338 -# elif defined(__loongarch_lp64) -# define systemd_NR_renameat2 276 -# elif defined(__m68k__) -# define systemd_NR_renameat2 351 -# elif defined(_MIPS_SIM) -# if _MIPS_SIM == _MIPS_SIM_ABI32 -# define systemd_NR_renameat2 4351 -# elif _MIPS_SIM == _MIPS_SIM_NABI32 -# define systemd_NR_renameat2 6315 -# elif _MIPS_SIM == _MIPS_SIM_ABI64 -# define systemd_NR_renameat2 5311 -# else -# error "Unknown MIPS ABI" -# endif -# elif defined(__hppa__) -# define systemd_NR_renameat2 337 -# elif defined(__powerpc__) -# define systemd_NR_renameat2 357 -# elif defined(__riscv) -# if __riscv_xlen == 32 -# define systemd_NR_renameat2 276 -# elif __riscv_xlen == 64 -# define systemd_NR_renameat2 276 -# else -# error "Unknown RISC-V ABI" -# endif -# elif defined(__s390__) -# define systemd_NR_renameat2 347 -# elif defined(__sparc__) -# define systemd_NR_renameat2 345 -# elif defined(__x86_64__) -# if defined(__ILP32__) -# define systemd_NR_renameat2 (316 | /* __X32_SYSCALL_BIT */ 0x40000000) -# else -# define systemd_NR_renameat2 316 -# endif -# elif !defined(missing_arch_template) -# warning "renameat2() syscall number is unknown for your architecture" -# endif - -/* may be an (invalid) negative number due to libseccomp, see PR 13319 */ -# if defined __NR_renameat2 && __NR_renameat2 >= 0 -# if defined systemd_NR_renameat2 -assert_cc(__NR_renameat2 == systemd_NR_renameat2); -# endif -# else -# if defined __NR_renameat2 -# undef __NR_renameat2 -# endif -# if defined systemd_NR_renameat2 && systemd_NR_renameat2 >= 0 -# define __NR_renameat2 systemd_NR_renameat2 -# endif -# endif -#endif - #ifndef __IGNORE_setxattrat # if defined(__aarch64__) # define systemd_NR_setxattrat 463 diff --git a/src/basic/missing_syscalls.py b/src/basic/missing_syscalls.py index 0302fa424a..3c5bcd15da 100644 --- a/src/basic/missing_syscalls.py +++ b/src/basic/missing_syscalls.py @@ -19,7 +19,6 @@ SYSCALLS = [ 'pkey_mprotect', 'quotactl_fd', 'removexattrat', - 'renameat2', 'setxattrat', ] From 177f168f432ad53710c06786cba7eef8d173343e Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 28 Feb 2025 22:57:42 +0900 Subject: [PATCH 07/36] missing_syscall: copy_file_range is supported by glibc since 2.27 Now our baseline of glibc is 2.31, hence it is OK to drop our definition. --- meson.build | 2 - src/basic/missing_syscall.h | 18 --------- src/basic/missing_syscall_def.h | 68 --------------------------------- src/basic/missing_syscalls.py | 1 - 4 files changed, 89 deletions(-) diff --git a/meson.build b/meson.build index ca7af554ac..6332dbb899 100644 --- a/meson.build +++ b/meson.build @@ -613,8 +613,6 @@ foreach ident : [ ['kcmp', '''#include '''], ['keyctl', '''#include #include '''], - ['copy_file_range', '''#include - #include '''], ['bpf', '''#include #include '''], ['explicit_bzero' , '''#include '''], diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index 2eff224a47..be1edd6c94 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -110,24 +110,6 @@ static inline key_serial_t missing_request_key(const char *type, const char *des /* ======================================================================= */ -#if !HAVE_COPY_FILE_RANGE -static inline ssize_t missing_copy_file_range(int fd_in, loff_t *off_in, - int fd_out, loff_t *off_out, - size_t len, - unsigned int flags) { -# ifdef __NR_copy_file_range - return syscall(__NR_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags); -# else - errno = ENOSYS; - return -1; -# endif -} - -# define copy_file_range missing_copy_file_range -#endif - -/* ======================================================================= */ - #if !HAVE_BPF union bpf_attr; diff --git a/src/basic/missing_syscall_def.h b/src/basic/missing_syscall_def.h index 7e1c6a3c99..264fe606fc 100644 --- a/src/basic/missing_syscall_def.h +++ b/src/basic/missing_syscall_def.h @@ -178,74 +178,6 @@ assert_cc(__NR_close_range == systemd_NR_close_range); # endif #endif -#ifndef __IGNORE_copy_file_range -# if defined(__aarch64__) -# define systemd_NR_copy_file_range 285 -# elif defined(__alpha__) -# define systemd_NR_copy_file_range 519 -# elif defined(__arc__) || defined(__tilegx__) -# define systemd_NR_copy_file_range 285 -# elif defined(__arm__) -# define systemd_NR_copy_file_range 391 -# elif defined(__i386__) -# define systemd_NR_copy_file_range 377 -# elif defined(__ia64__) -# define systemd_NR_copy_file_range 1347 -# elif defined(__loongarch_lp64) -# define systemd_NR_copy_file_range 285 -# elif defined(__m68k__) -# define systemd_NR_copy_file_range 376 -# elif defined(_MIPS_SIM) -# if _MIPS_SIM == _MIPS_SIM_ABI32 -# define systemd_NR_copy_file_range 4360 -# elif _MIPS_SIM == _MIPS_SIM_NABI32 -# define systemd_NR_copy_file_range 6324 -# elif _MIPS_SIM == _MIPS_SIM_ABI64 -# define systemd_NR_copy_file_range 5320 -# else -# error "Unknown MIPS ABI" -# endif -# elif defined(__hppa__) -# define systemd_NR_copy_file_range 346 -# elif defined(__powerpc__) -# define systemd_NR_copy_file_range 379 -# elif defined(__riscv) -# if __riscv_xlen == 32 -# define systemd_NR_copy_file_range 285 -# elif __riscv_xlen == 64 -# define systemd_NR_copy_file_range 285 -# else -# error "Unknown RISC-V ABI" -# endif -# elif defined(__s390__) -# define systemd_NR_copy_file_range 375 -# elif defined(__sparc__) -# define systemd_NR_copy_file_range 357 -# elif defined(__x86_64__) -# if defined(__ILP32__) -# define systemd_NR_copy_file_range (326 | /* __X32_SYSCALL_BIT */ 0x40000000) -# else -# define systemd_NR_copy_file_range 326 -# endif -# elif !defined(missing_arch_template) -# warning "copy_file_range() syscall number is unknown for your architecture" -# endif - -/* may be an (invalid) negative number due to libseccomp, see PR 13319 */ -# if defined __NR_copy_file_range && __NR_copy_file_range >= 0 -# if defined systemd_NR_copy_file_range -assert_cc(__NR_copy_file_range == systemd_NR_copy_file_range); -# endif -# else -# if defined __NR_copy_file_range -# undef __NR_copy_file_range -# endif -# if defined systemd_NR_copy_file_range && systemd_NR_copy_file_range >= 0 -# define __NR_copy_file_range systemd_NR_copy_file_range -# endif -# endif -#endif - #ifndef __IGNORE_fchmodat2 # if defined(__aarch64__) # define systemd_NR_fchmodat2 452 diff --git a/src/basic/missing_syscalls.py b/src/basic/missing_syscalls.py index 3c5bcd15da..01b20b1ca8 100644 --- a/src/basic/missing_syscalls.py +++ b/src/basic/missing_syscalls.py @@ -8,7 +8,6 @@ import functools SYSCALLS = [ 'bpf', 'close_range', - 'copy_file_range', 'fchmodat2', 'mount_setattr', 'move_mount', From fbfe09ccd0643d33c862e81104c666f31a884338 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 3 Mar 2025 11:42:10 +0900 Subject: [PATCH 08/36] missing_syscall: drop unused rt_sigqueueinfo wrapper The syscall is unused since 19e1a908b512410e0968fec9259a8fc221001f12. --- meson.build | 4 ---- src/basic/missing_syscall.h | 14 -------------- 2 files changed, 18 deletions(-) diff --git a/meson.build b/meson.build index 6332dbb899..05c13e947f 100644 --- a/meson.build +++ b/meson.build @@ -631,10 +631,6 @@ foreach ident : [ #include #include #include '''], - ['rt_sigqueueinfo', '''#include - #include - #include - #include '''], ['rt_tgsigqueueinfo', '''#include #include #include diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index be1edd6c94..af7aa528c6 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -188,20 +188,6 @@ static inline int missing_pidfd_open(pid_t pid, unsigned flags) { /* ======================================================================= */ -#if !HAVE_RT_SIGQUEUEINFO -static inline int missing_rt_sigqueueinfo(pid_t tgid, int sig, siginfo_t *info) { -# if defined __NR_rt_sigqueueinfo && __NR_rt_sigqueueinfo >= 0 - return syscall(__NR_rt_sigqueueinfo, tgid, sig, info); -# else -# error "__NR_rt_sigqueueinfo not defined" -# endif -} - -# define rt_sigqueueinfo missing_rt_sigqueueinfo -#endif - -/* ======================================================================= */ - #if !HAVE_RT_TGSIGQUEUEINFO static inline int missing_rt_tgsigqueueinfo(pid_t tgid, pid_t tid, int sig, siginfo_t *info) { # if defined __NR_rt_tgsigqueueinfo && __NR_rt_tgsigqueueinfo >= 0 From 2a6e117ddbea0cc1371d765376bad4fd2acf558b Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 3 Mar 2025 13:07:21 +0900 Subject: [PATCH 09/36] missing_syscall: drop unnecessary syscall number definitions --- src/basic/missing_syscall_def.h | 408 -------------------------------- src/basic/missing_syscalls.py | 16 +- 2 files changed, 5 insertions(+), 419 deletions(-) diff --git a/src/basic/missing_syscall_def.h b/src/basic/missing_syscall_def.h index 264fe606fc..8d4edaac16 100644 --- a/src/basic/missing_syscall_def.h +++ b/src/basic/missing_syscall_def.h @@ -42,74 +42,6 @@ # define missing_arch_template 1 # endif -#ifndef __IGNORE_bpf -# if defined(__aarch64__) -# define systemd_NR_bpf 280 -# elif defined(__alpha__) -# define systemd_NR_bpf 515 -# elif defined(__arc__) || defined(__tilegx__) -# define systemd_NR_bpf 280 -# elif defined(__arm__) -# define systemd_NR_bpf 386 -# elif defined(__i386__) -# define systemd_NR_bpf 357 -# elif defined(__ia64__) -# define systemd_NR_bpf 1341 -# elif defined(__loongarch_lp64) -# define systemd_NR_bpf 280 -# elif defined(__m68k__) -# define systemd_NR_bpf 354 -# elif defined(_MIPS_SIM) -# if _MIPS_SIM == _MIPS_SIM_ABI32 -# define systemd_NR_bpf 4355 -# elif _MIPS_SIM == _MIPS_SIM_NABI32 -# define systemd_NR_bpf 6319 -# elif _MIPS_SIM == _MIPS_SIM_ABI64 -# define systemd_NR_bpf 5315 -# else -# error "Unknown MIPS ABI" -# endif -# elif defined(__hppa__) -# define systemd_NR_bpf 341 -# elif defined(__powerpc__) -# define systemd_NR_bpf 361 -# elif defined(__riscv) -# if __riscv_xlen == 32 -# define systemd_NR_bpf 280 -# elif __riscv_xlen == 64 -# define systemd_NR_bpf 280 -# else -# error "Unknown RISC-V ABI" -# endif -# elif defined(__s390__) -# define systemd_NR_bpf 351 -# elif defined(__sparc__) -# define systemd_NR_bpf 349 -# elif defined(__x86_64__) -# if defined(__ILP32__) -# define systemd_NR_bpf (321 | /* __X32_SYSCALL_BIT */ 0x40000000) -# else -# define systemd_NR_bpf 321 -# endif -# elif !defined(missing_arch_template) -# warning "bpf() syscall number is unknown for your architecture" -# endif - -/* may be an (invalid) negative number due to libseccomp, see PR 13319 */ -# if defined __NR_bpf && __NR_bpf >= 0 -# if defined systemd_NR_bpf -assert_cc(__NR_bpf == systemd_NR_bpf); -# endif -# else -# if defined __NR_bpf -# undef __NR_bpf -# endif -# if defined systemd_NR_bpf && systemd_NR_bpf >= 0 -# define __NR_bpf systemd_NR_bpf -# endif -# endif -#endif - #ifndef __IGNORE_close_range # if defined(__aarch64__) # define systemd_NR_close_range 436 @@ -314,142 +246,6 @@ assert_cc(__NR_mount_setattr == systemd_NR_mount_setattr); # endif #endif -#ifndef __IGNORE_move_mount -# if defined(__aarch64__) -# define systemd_NR_move_mount 429 -# elif defined(__alpha__) -# define systemd_NR_move_mount 539 -# elif defined(__arc__) || defined(__tilegx__) -# define systemd_NR_move_mount 429 -# elif defined(__arm__) -# define systemd_NR_move_mount 429 -# elif defined(__i386__) -# define systemd_NR_move_mount 429 -# elif defined(__ia64__) -# define systemd_NR_move_mount 1453 -# elif defined(__loongarch_lp64) -# define systemd_NR_move_mount 429 -# elif defined(__m68k__) -# define systemd_NR_move_mount 429 -# elif defined(_MIPS_SIM) -# if _MIPS_SIM == _MIPS_SIM_ABI32 -# define systemd_NR_move_mount 4429 -# elif _MIPS_SIM == _MIPS_SIM_NABI32 -# define systemd_NR_move_mount 6429 -# elif _MIPS_SIM == _MIPS_SIM_ABI64 -# define systemd_NR_move_mount 5429 -# else -# error "Unknown MIPS ABI" -# endif -# elif defined(__hppa__) -# define systemd_NR_move_mount 429 -# elif defined(__powerpc__) -# define systemd_NR_move_mount 429 -# elif defined(__riscv) -# if __riscv_xlen == 32 -# define systemd_NR_move_mount 429 -# elif __riscv_xlen == 64 -# define systemd_NR_move_mount 429 -# else -# error "Unknown RISC-V ABI" -# endif -# elif defined(__s390__) -# define systemd_NR_move_mount 429 -# elif defined(__sparc__) -# define systemd_NR_move_mount 429 -# elif defined(__x86_64__) -# if defined(__ILP32__) -# define systemd_NR_move_mount (429 | /* __X32_SYSCALL_BIT */ 0x40000000) -# else -# define systemd_NR_move_mount 429 -# endif -# elif !defined(missing_arch_template) -# warning "move_mount() syscall number is unknown for your architecture" -# endif - -/* may be an (invalid) negative number due to libseccomp, see PR 13319 */ -# if defined __NR_move_mount && __NR_move_mount >= 0 -# if defined systemd_NR_move_mount -assert_cc(__NR_move_mount == systemd_NR_move_mount); -# endif -# else -# if defined __NR_move_mount -# undef __NR_move_mount -# endif -# if defined systemd_NR_move_mount && systemd_NR_move_mount >= 0 -# define __NR_move_mount systemd_NR_move_mount -# endif -# endif -#endif - -#ifndef __IGNORE_open_tree -# if defined(__aarch64__) -# define systemd_NR_open_tree 428 -# elif defined(__alpha__) -# define systemd_NR_open_tree 538 -# elif defined(__arc__) || defined(__tilegx__) -# define systemd_NR_open_tree 428 -# elif defined(__arm__) -# define systemd_NR_open_tree 428 -# elif defined(__i386__) -# define systemd_NR_open_tree 428 -# elif defined(__ia64__) -# define systemd_NR_open_tree 1452 -# elif defined(__loongarch_lp64) -# define systemd_NR_open_tree 428 -# elif defined(__m68k__) -# define systemd_NR_open_tree 428 -# elif defined(_MIPS_SIM) -# if _MIPS_SIM == _MIPS_SIM_ABI32 -# define systemd_NR_open_tree 4428 -# elif _MIPS_SIM == _MIPS_SIM_NABI32 -# define systemd_NR_open_tree 6428 -# elif _MIPS_SIM == _MIPS_SIM_ABI64 -# define systemd_NR_open_tree 5428 -# else -# error "Unknown MIPS ABI" -# endif -# elif defined(__hppa__) -# define systemd_NR_open_tree 428 -# elif defined(__powerpc__) -# define systemd_NR_open_tree 428 -# elif defined(__riscv) -# if __riscv_xlen == 32 -# define systemd_NR_open_tree 428 -# elif __riscv_xlen == 64 -# define systemd_NR_open_tree 428 -# else -# error "Unknown RISC-V ABI" -# endif -# elif defined(__s390__) -# define systemd_NR_open_tree 428 -# elif defined(__sparc__) -# define systemd_NR_open_tree 428 -# elif defined(__x86_64__) -# if defined(__ILP32__) -# define systemd_NR_open_tree (428 | /* __X32_SYSCALL_BIT */ 0x40000000) -# else -# define systemd_NR_open_tree 428 -# endif -# elif !defined(missing_arch_template) -# warning "open_tree() syscall number is unknown for your architecture" -# endif - -/* may be an (invalid) negative number due to libseccomp, see PR 13319 */ -# if defined __NR_open_tree && __NR_open_tree >= 0 -# if defined systemd_NR_open_tree -assert_cc(__NR_open_tree == systemd_NR_open_tree); -# endif -# else -# if defined __NR_open_tree -# undef __NR_open_tree -# endif -# if defined systemd_NR_open_tree && systemd_NR_open_tree >= 0 -# define __NR_open_tree systemd_NR_open_tree -# endif -# endif -#endif - #ifndef __IGNORE_openat2 # if defined(__aarch64__) # define systemd_NR_openat2 437 @@ -518,210 +314,6 @@ assert_cc(__NR_openat2 == systemd_NR_openat2); # endif #endif -#ifndef __IGNORE_pidfd_open -# if defined(__aarch64__) -# define systemd_NR_pidfd_open 434 -# elif defined(__alpha__) -# define systemd_NR_pidfd_open 544 -# elif defined(__arc__) || defined(__tilegx__) -# define systemd_NR_pidfd_open 434 -# elif defined(__arm__) -# define systemd_NR_pidfd_open 434 -# elif defined(__i386__) -# define systemd_NR_pidfd_open 434 -# elif defined(__ia64__) -# define systemd_NR_pidfd_open 1458 -# elif defined(__loongarch_lp64) -# define systemd_NR_pidfd_open 434 -# elif defined(__m68k__) -# define systemd_NR_pidfd_open 434 -# elif defined(_MIPS_SIM) -# if _MIPS_SIM == _MIPS_SIM_ABI32 -# define systemd_NR_pidfd_open 4434 -# elif _MIPS_SIM == _MIPS_SIM_NABI32 -# define systemd_NR_pidfd_open 6434 -# elif _MIPS_SIM == _MIPS_SIM_ABI64 -# define systemd_NR_pidfd_open 5434 -# else -# error "Unknown MIPS ABI" -# endif -# elif defined(__hppa__) -# define systemd_NR_pidfd_open 434 -# elif defined(__powerpc__) -# define systemd_NR_pidfd_open 434 -# elif defined(__riscv) -# if __riscv_xlen == 32 -# define systemd_NR_pidfd_open 434 -# elif __riscv_xlen == 64 -# define systemd_NR_pidfd_open 434 -# else -# error "Unknown RISC-V ABI" -# endif -# elif defined(__s390__) -# define systemd_NR_pidfd_open 434 -# elif defined(__sparc__) -# define systemd_NR_pidfd_open 434 -# elif defined(__x86_64__) -# if defined(__ILP32__) -# define systemd_NR_pidfd_open (434 | /* __X32_SYSCALL_BIT */ 0x40000000) -# else -# define systemd_NR_pidfd_open 434 -# endif -# elif !defined(missing_arch_template) -# warning "pidfd_open() syscall number is unknown for your architecture" -# endif - -/* may be an (invalid) negative number due to libseccomp, see PR 13319 */ -# if defined __NR_pidfd_open && __NR_pidfd_open >= 0 -# if defined systemd_NR_pidfd_open -assert_cc(__NR_pidfd_open == systemd_NR_pidfd_open); -# endif -# else -# if defined __NR_pidfd_open -# undef __NR_pidfd_open -# endif -# if defined systemd_NR_pidfd_open && systemd_NR_pidfd_open >= 0 -# define __NR_pidfd_open systemd_NR_pidfd_open -# endif -# endif -#endif - -#ifndef __IGNORE_pidfd_send_signal -# if defined(__aarch64__) -# define systemd_NR_pidfd_send_signal 424 -# elif defined(__alpha__) -# define systemd_NR_pidfd_send_signal 534 -# elif defined(__arc__) || defined(__tilegx__) -# define systemd_NR_pidfd_send_signal 424 -# elif defined(__arm__) -# define systemd_NR_pidfd_send_signal 424 -# elif defined(__i386__) -# define systemd_NR_pidfd_send_signal 424 -# elif defined(__ia64__) -# define systemd_NR_pidfd_send_signal 1448 -# elif defined(__loongarch_lp64) -# define systemd_NR_pidfd_send_signal 424 -# elif defined(__m68k__) -# define systemd_NR_pidfd_send_signal 424 -# elif defined(_MIPS_SIM) -# if _MIPS_SIM == _MIPS_SIM_ABI32 -# define systemd_NR_pidfd_send_signal 4424 -# elif _MIPS_SIM == _MIPS_SIM_NABI32 -# define systemd_NR_pidfd_send_signal 6424 -# elif _MIPS_SIM == _MIPS_SIM_ABI64 -# define systemd_NR_pidfd_send_signal 5424 -# else -# error "Unknown MIPS ABI" -# endif -# elif defined(__hppa__) -# define systemd_NR_pidfd_send_signal 424 -# elif defined(__powerpc__) -# define systemd_NR_pidfd_send_signal 424 -# elif defined(__riscv) -# if __riscv_xlen == 32 -# define systemd_NR_pidfd_send_signal 424 -# elif __riscv_xlen == 64 -# define systemd_NR_pidfd_send_signal 424 -# else -# error "Unknown RISC-V ABI" -# endif -# elif defined(__s390__) -# define systemd_NR_pidfd_send_signal 424 -# elif defined(__sparc__) -# define systemd_NR_pidfd_send_signal 424 -# elif defined(__x86_64__) -# if defined(__ILP32__) -# define systemd_NR_pidfd_send_signal (424 | /* __X32_SYSCALL_BIT */ 0x40000000) -# else -# define systemd_NR_pidfd_send_signal 424 -# endif -# elif !defined(missing_arch_template) -# warning "pidfd_send_signal() syscall number is unknown for your architecture" -# endif - -/* may be an (invalid) negative number due to libseccomp, see PR 13319 */ -# if defined __NR_pidfd_send_signal && __NR_pidfd_send_signal >= 0 -# if defined systemd_NR_pidfd_send_signal -assert_cc(__NR_pidfd_send_signal == systemd_NR_pidfd_send_signal); -# endif -# else -# if defined __NR_pidfd_send_signal -# undef __NR_pidfd_send_signal -# endif -# if defined systemd_NR_pidfd_send_signal && systemd_NR_pidfd_send_signal >= 0 -# define __NR_pidfd_send_signal systemd_NR_pidfd_send_signal -# endif -# endif -#endif - -#ifndef __IGNORE_pkey_mprotect -# if defined(__aarch64__) -# define systemd_NR_pkey_mprotect 288 -# elif defined(__alpha__) -# define systemd_NR_pkey_mprotect 524 -# elif defined(__arc__) || defined(__tilegx__) -# define systemd_NR_pkey_mprotect 288 -# elif defined(__arm__) -# define systemd_NR_pkey_mprotect 394 -# elif defined(__i386__) -# define systemd_NR_pkey_mprotect 380 -# elif defined(__ia64__) -# define systemd_NR_pkey_mprotect 1354 -# elif defined(__loongarch_lp64) -# define systemd_NR_pkey_mprotect 288 -# elif defined(__m68k__) -# define systemd_NR_pkey_mprotect 381 -# elif defined(_MIPS_SIM) -# if _MIPS_SIM == _MIPS_SIM_ABI32 -# define systemd_NR_pkey_mprotect 4363 -# elif _MIPS_SIM == _MIPS_SIM_NABI32 -# define systemd_NR_pkey_mprotect 6327 -# elif _MIPS_SIM == _MIPS_SIM_ABI64 -# define systemd_NR_pkey_mprotect 5323 -# else -# error "Unknown MIPS ABI" -# endif -# elif defined(__hppa__) -# define systemd_NR_pkey_mprotect 351 -# elif defined(__powerpc__) -# define systemd_NR_pkey_mprotect 386 -# elif defined(__riscv) -# if __riscv_xlen == 32 -# define systemd_NR_pkey_mprotect 288 -# elif __riscv_xlen == 64 -# define systemd_NR_pkey_mprotect 288 -# else -# error "Unknown RISC-V ABI" -# endif -# elif defined(__s390__) -# define systemd_NR_pkey_mprotect 384 -# elif defined(__sparc__) -# define systemd_NR_pkey_mprotect 362 -# elif defined(__x86_64__) -# if defined(__ILP32__) -# define systemd_NR_pkey_mprotect (329 | /* __X32_SYSCALL_BIT */ 0x40000000) -# else -# define systemd_NR_pkey_mprotect 329 -# endif -# elif !defined(missing_arch_template) -# warning "pkey_mprotect() syscall number is unknown for your architecture" -# endif - -/* may be an (invalid) negative number due to libseccomp, see PR 13319 */ -# if defined __NR_pkey_mprotect && __NR_pkey_mprotect >= 0 -# if defined systemd_NR_pkey_mprotect -assert_cc(__NR_pkey_mprotect == systemd_NR_pkey_mprotect); -# endif -# else -# if defined __NR_pkey_mprotect -# undef __NR_pkey_mprotect -# endif -# if defined systemd_NR_pkey_mprotect && systemd_NR_pkey_mprotect >= 0 -# define __NR_pkey_mprotect systemd_NR_pkey_mprotect -# endif -# endif -#endif - #ifndef __IGNORE_quotactl_fd # if defined(__aarch64__) # define systemd_NR_quotactl_fd 443 diff --git a/src/basic/missing_syscalls.py b/src/basic/missing_syscalls.py index 01b20b1ca8..0d351e322d 100644 --- a/src/basic/missing_syscalls.py +++ b/src/basic/missing_syscalls.py @@ -6,17 +6,11 @@ import functools # We only generate numbers for a dozen or so syscalls SYSCALLS = [ - 'bpf', - 'close_range', - 'fchmodat2', - 'mount_setattr', - 'move_mount', - 'open_tree', - 'openat2', - 'pidfd_open', - 'pidfd_send_signal', - 'pkey_mprotect', - 'quotactl_fd', + 'close_range', # defined in glibc header since glibc-2.33 + 'fchmodat2', # defined in glibc header since glibc-2.39 + 'mount_setattr', # defined in glibc header since glibc-2.34 + 'openat2', # defined in glibc header since glibc-2.32 + 'quotactl_fd', # defined in glibc header since glibc-2.35 'removexattrat', 'setxattrat', ] From 1d917ba4211805b9ccf3d70e45b460c34f1e8e14 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 3 Mar 2025 13:15:34 +0900 Subject: [PATCH 10/36] missing_syscall: drop unnecessary ifdefs for syscall number Nowadays, we define syscall numbers for newer syscalls. Hence the conditions are not necessary. This also adds several comments about when syscalls are introduced. --- src/basic/missing_syscall.h | 118 ++++++++---------------------------- 1 file changed, 25 insertions(+), 93 deletions(-) diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index af7aa528c6..6bf9c0d5ae 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -24,13 +24,9 @@ /* ======================================================================= */ #if !HAVE_FCHMODAT2 +/* since kernel v6.6 (78252deb023cf0879256fcfbafe37022c390762b) */ static inline int missing_fchmodat2(int dirfd, const char *path, mode_t mode, int flags) { -# ifdef __NR_fchmodat2 return syscall(__NR_fchmodat2, dirfd, path, mode, flags); -# else - errno = ENOSYS; - return -1; -# endif } # define fchmodat2 missing_fchmodat2 @@ -95,12 +91,16 @@ static inline long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg # define keyctl missing_keyctl } +/* ======================================================================= */ + static inline key_serial_t missing_add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) { return syscall(__NR_add_key, type, description, payload, plen, ringid); # define add_key missing_add_key } +/* ======================================================================= */ + static inline key_serial_t missing_request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) { return syscall(__NR_request_key, type, description, callout_info, destringid); @@ -114,12 +114,7 @@ static inline key_serial_t missing_request_key(const char *type, const char *des union bpf_attr; static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size) { -#ifdef __NR_bpf return (int) syscall(__NR_bpf, cmd, attr, size); -#else - errno = ENOSYS; - return -1; -#endif } # define bpf missing_bpf @@ -138,14 +133,7 @@ enum { static inline long missing_set_mempolicy(int mode, const unsigned long *nodemask, unsigned long maxnode) { - long i; -# if defined __NR_set_mempolicy && __NR_set_mempolicy >= 0 - i = syscall(__NR_set_mempolicy, mode, nodemask, maxnode); -# else - errno = ENOSYS; - i = -1; -# endif - return i; + return syscall(__NR_set_mempolicy, mode, nodemask, maxnode); } # define set_mempolicy missing_set_mempolicy @@ -155,14 +143,7 @@ static inline long missing_set_mempolicy(int mode, const unsigned long *nodemask static inline long missing_get_mempolicy(int *mode, unsigned long *nodemask, unsigned long maxnode, void *addr, unsigned long flags) { - long i; -# if defined __NR_get_mempolicy && __NR_get_mempolicy >= 0 - i = syscall(__NR_get_mempolicy, mode, nodemask, maxnode, addr, flags); -# else - errno = ENOSYS; - i = -1; -# endif - return i; + return syscall(__NR_get_mempolicy, mode, nodemask, maxnode, addr, flags); } # define get_mempolicy missing_get_mempolicy @@ -171,6 +152,7 @@ static inline long missing_get_mempolicy(int *mode, unsigned long *nodemask, /* ======================================================================= */ #if !HAVE_PIDFD_SEND_SIGNAL +/* since kernel v5.1 (3eb39f47934f9d5a3027fe00d906a45fe3a15fad) */ static inline int missing_pidfd_send_signal(int fd, int sig, siginfo_t *info, unsigned flags) { return syscall(__NR_pidfd_send_signal, fd, sig, info, flags); } @@ -178,7 +160,10 @@ static inline int missing_pidfd_send_signal(int fd, int sig, siginfo_t *info, un # define pidfd_send_signal missing_pidfd_send_signal #endif +/* ======================================================================= */ + #if !HAVE_PIDFD_OPEN +/* since kernel v5.3 (7615d9e1780e26e0178c93c55b73309a5dc093d7) */ static inline int missing_pidfd_open(pid_t pid, unsigned flags) { return syscall(__NR_pidfd_open, pid, flags); } @@ -190,11 +175,7 @@ static inline int missing_pidfd_open(pid_t pid, unsigned flags) { #if !HAVE_RT_TGSIGQUEUEINFO static inline int missing_rt_tgsigqueueinfo(pid_t tgid, pid_t tid, int sig, siginfo_t *info) { -# if defined __NR_rt_tgsigqueueinfo && __NR_rt_tgsigqueueinfo >= 0 return syscall(__NR_rt_tgsigqueueinfo, tgid, tid, sig, info); -# else -# error "__NR_rt_tgsigqueueinfo not defined" -# endif } # define rt_tgsigqueueinfo missing_rt_tgsigqueueinfo @@ -203,15 +184,11 @@ static inline int missing_rt_tgsigqueueinfo(pid_t tgid, pid_t tid, int sig, sigi /* ======================================================================= */ #if !HAVE_EXECVEAT +/* since kernel v3.19 (51f39a1f0cea1cacf8c787f652f26dfee9611874) */ static inline int missing_execveat(int dirfd, const char *pathname, char *const argv[], char *const envp[], int flags) { -# if defined __NR_execveat && __NR_execveat >= 0 return syscall(__NR_execveat, dirfd, pathname, argv, envp, flags); -# else - errno = ENOSYS; - return -1; -# endif } # undef AT_EMPTY_PATH @@ -222,8 +199,8 @@ static inline int missing_execveat(int dirfd, const char *pathname, /* ======================================================================= */ #if !HAVE_CLOSE_RANGE +/* since kernel v5.9 (9b4feb630e8e9801603f3cab3a36369e3c1cf88d) */ static inline int missing_close_range(unsigned first_fd, unsigned end_fd, unsigned flags) { -# ifdef __NR_close_range /* Kernel-side the syscall expects fds as unsigned integers (just like close() actually), while * userspace exclusively uses signed integers for fds. glibc chose to expose it 1:1 however, hence we * do so here too, even if we end up passing signed fds to it most of the time. */ @@ -231,10 +208,6 @@ static inline int missing_close_range(unsigned first_fd, unsigned end_fd, unsign first_fd, end_fd, flags); -# else - errno = ENOSYS; - return -1; -# endif } # define close_range missing_close_range @@ -243,6 +216,7 @@ static inline int missing_close_range(unsigned first_fd, unsigned end_fd, unsign /* ======================================================================= */ #if !HAVE_MOUNT_SETATTR +/* since kernel v5.12 (2a1867219c7b27f928e2545782b86daaf9ad50bd) */ #if !HAVE_STRUCT_MOUNT_ATTR struct mount_attr { @@ -314,12 +288,7 @@ static inline int missing_mount_setattr( struct mount_attr *attr, size_t size) { -# if defined __NR_mount_setattr && __NR_mount_setattr >= 0 return syscall(__NR_mount_setattr, dfd, path, flags, attr, size); -# else - errno = ENOSYS; - return -1; -# endif } # define mount_setattr missing_mount_setattr @@ -328,6 +297,7 @@ static inline int missing_mount_setattr( /* ======================================================================= */ #if !HAVE_OPEN_TREE +/* since kernel v5.2 (a07b20004793d8926f78d63eb5980559f7813404, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */ #ifndef OPEN_TREE_CLONE #define OPEN_TREE_CLONE 1 @@ -342,12 +312,7 @@ static inline int missing_open_tree( const char *filename, unsigned flags) { -# if defined __NR_open_tree && __NR_open_tree >= 0 return syscall(__NR_open_tree, dfd, filename, flags); -# else - errno = ENOSYS; - return -1; -# endif } # define open_tree missing_open_tree @@ -360,6 +325,7 @@ static inline int missing_open_tree( #endif #if !HAVE_MOVE_MOUNT +/* since kernel v5.2 (2db154b3ea8e14b04fee23e3fdfd5e9d17fbc6ae, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */ #ifndef MOVE_MOUNT_F_EMPTY_PATH #define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */ @@ -376,12 +342,7 @@ static inline int missing_move_mount( const char *to_pathname, unsigned flags) { -# if defined __NR_move_mount && __NR_move_mount >= 0 return syscall(__NR_move_mount, from_dfd, from_pathname, to_dfd, to_pathname, flags); -# else - errno = ENOSYS; - return -1; -# endif } # define move_mount missing_move_mount @@ -390,18 +351,14 @@ static inline int missing_move_mount( /* ======================================================================= */ #if !HAVE_FSOPEN +/* since kernel v5.2 (24dcb3d90a1f67fe08c68a004af37df059d74005, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */ #ifndef FSOPEN_CLOEXEC #define FSOPEN_CLOEXEC 0x00000001 #endif static inline int missing_fsopen(const char *fsname, unsigned flags) { -# if defined __NR_fsopen && __NR_fsopen >= 0 return syscall(__NR_fsopen, fsname, flags); -# else - errno = ENOSYS; - return -1; -# endif } # define fsopen missing_fsopen @@ -410,6 +367,7 @@ static inline int missing_fsopen(const char *fsname, unsigned flags) { /* ======================================================================= */ #if !HAVE_FSCONFIG +/* since kernel v5.2 (ecdab150fddb42fe6a739335257949220033b782, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */ #ifndef FSCONFIG_SET_FLAG #define FSCONFIG_SET_FLAG 0 /* Set parameter, supplying no value */ @@ -428,12 +386,7 @@ static inline int missing_fsopen(const char *fsname, unsigned flags) { #endif static inline int missing_fsconfig(int fd, unsigned cmd, const char *key, const void *value, int aux) { -# if defined __NR_fsconfig && __NR_fsconfig >= 0 return syscall(__NR_fsconfig, fd, cmd, key, value, aux); -# else - errno = ENOSYS; - return -1; -# endif } # define fsconfig missing_fsconfig @@ -442,18 +395,14 @@ static inline int missing_fsconfig(int fd, unsigned cmd, const char *key, const /* ======================================================================= */ #if !HAVE_FSMOUNT +/* since kernel v5.2 for (93766fbd2696c2c4453dd8e1070977e9cd4e6b6d, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */ #ifndef FSMOUNT_CLOEXEC #define FSMOUNT_CLOEXEC 0x00000001 #endif static inline int missing_fsmount(int fd, unsigned flags, unsigned ms_flags) { -# if defined __NR_fsmount && __NR_fsmount >= 0 return syscall(__NR_fsmount, fd, flags, ms_flags); -# else - errno = ENOSYS; - return -1; -# endif } # define fsmount missing_fsmount @@ -462,14 +411,8 @@ static inline int missing_fsmount(int fd, unsigned flags, unsigned ms_flags) { /* ======================================================================= */ #if !HAVE_GETDENTS64 - static inline ssize_t missing_getdents64(int fd, void *buffer, size_t length) { -# if defined __NR_getdents64 && __NR_getdents64 >= 0 return syscall(__NR_getdents64, fd, buffer, length); -# else - errno = ENOSYS; - return -1; -# endif } # define getdents64 missing_getdents64 @@ -478,7 +421,7 @@ static inline ssize_t missing_getdents64(int fd, void *buffer, size_t length) { /* ======================================================================= */ #if !HAVE_SCHED_SETATTR - +/* since kernel 3.14 (e6cfc0295c7d51b008999a8b13a44fb43f8685ea) */ static inline ssize_t missing_sched_setattr(pid_t pid, struct sched_attr *attr, unsigned int flags) { return syscall(__NR_sched_setattr, pid, attr, flags); } @@ -503,14 +446,9 @@ int __clone2(int (*fn)(void *), void *stack_base, size_t stack_size, int flags, /* ======================================================================= */ #if !HAVE_QUOTACTL_FD - +/* since kernel v5.14 (64c2c2c62f92339b176ea24403d8db16db36f9e6) */ static inline int missing_quotactl_fd(int fd, int cmd, int id, void *addr) { -# ifdef __NR_quotactl_fd return syscall(__NR_quotactl_fd, fd, cmd, id, addr); -# else - errno = ENOSYS; - return -1; -# endif } # define quotactl_fd missing_quotactl_fd @@ -519,6 +457,7 @@ static inline int missing_quotactl_fd(int fd, int cmd, int id, void *addr) { /* ======================================================================= */ #if !HAVE_SETXATTRAT +/* since kernel v6.13 (6140be90ec70c39fa844741ca3cc807dd0866394) */ struct xattr_args { _align_(8) uint64_t value; uint32_t size; @@ -526,25 +465,18 @@ struct xattr_args { }; static inline int missing_setxattrat(int fd, const char *path, int at_flags, const char *name, const struct xattr_args *args, size_t size) { -# ifdef __NR_setxattrat return syscall(__NR_setxattrat, fd, path, at_flags, name, args, size); -# else - errno = ENOSYS; - return -1; -# endif } # define setxattrat missing_setxattrat #endif +/* ======================================================================= */ + #if !HAVE_REMOVEXATTRAT +/* since kernel v6.13 (6140be90ec70c39fa844741ca3cc807dd0866394) */ static inline int missing_removexattrat(int fd, const char *path, int at_flags, const char *name) { -# ifdef __NR_removexattrat return syscall(__NR_removexattrat, fd, path, at_flags, name); -# else - errno = ENOSYS; - return -1; -# endif } # define removexattrat missing_removexattrat From 6b557580fe111ad20a962c84a5887d90045a3237 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 3 Mar 2025 13:25:52 +0900 Subject: [PATCH 11/36] missing_syscall: drop unnecessary definition of AT_EMPTY_PATH It is defined since glibc-2.14 (46998f745736b3c8df5901a27b6c2a19f5cc5e98), and the value was never changed. --- src/basic/missing_syscall.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index 6bf9c0d5ae..ebdb1c30b9 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -191,8 +191,6 @@ static inline int missing_execveat(int dirfd, const char *pathname, return syscall(__NR_execveat, dirfd, pathname, argv, envp, flags); } -# undef AT_EMPTY_PATH -# define AT_EMPTY_PATH 0x1000 # define execveat missing_execveat #endif From 2e22dd218af5c81a30945742b323777cdc5511b4 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 00:14:24 +0900 Subject: [PATCH 12/36] memory-util: explicit_bzero() exists since glibc-2.25 --- meson.build | 1 - src/fundamental/memory-util-fundamental.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 05c13e947f..108e3d46b0 100644 --- a/meson.build +++ b/meson.build @@ -615,7 +615,6 @@ foreach ident : [ #include '''], ['bpf', '''#include #include '''], - ['explicit_bzero' , '''#include '''], ['reallocarray', '''#include '''], ['set_mempolicy', '''#include #include '''], diff --git a/src/fundamental/memory-util-fundamental.h b/src/fundamental/memory-util-fundamental.h index 6870f54f58..6c3aac34a2 100644 --- a/src/fundamental/memory-util-fundamental.h +++ b/src/fundamental/memory-util-fundamental.h @@ -17,7 +17,7 @@ _l_ > 0 ? memset((x), 0, _l_) : (x); \ }) -#if !SD_BOOT && HAVE_EXPLICIT_BZERO +#if !SD_BOOT static inline void *explicit_bzero_safe(void *p, size_t l) { if (p && l > 0) explicit_bzero(p, l); From e79d88320a60def6607296a558b3fa2fbf5ed84d Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 00:15:56 +0900 Subject: [PATCH 13/36] alloc-util: reallocarray() exists since glibc-2.26 --- meson.build | 1 - src/basic/alloc-util.h | 9 --------- 2 files changed, 10 deletions(-) diff --git a/meson.build b/meson.build index 108e3d46b0..7cf12bc452 100644 --- a/meson.build +++ b/meson.build @@ -615,7 +615,6 @@ foreach ident : [ #include '''], ['bpf', '''#include #include '''], - ['reallocarray', '''#include '''], ['set_mempolicy', '''#include #include '''], ['get_mempolicy', '''#include diff --git a/src/basic/alloc-util.h b/src/basic/alloc-util.h index ba71298287..e589a94fd0 100644 --- a/src/basic/alloc-util.h +++ b/src/basic/alloc-util.h @@ -119,15 +119,6 @@ _malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t need, size_t s return malloc(size * need ?: 1); } -#if !HAVE_REALLOCARRAY -_alloc_(2, 3) static inline void *reallocarray(void *p, size_t need, size_t size) { - if (size_multiply_overflow(size, need)) - return NULL; - - return realloc(p, size * need ?: 1); -} -#endif - _alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t need, size_t size) { if (size_multiply_overflow(size, need)) return NULL; From 905497c86d95eaa24fa178c992d9c9bf4187a6b4 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 01:07:35 +0900 Subject: [PATCH 14/36] missing_stdlib: secure_getenv() exists since glibc-2.17 --- meson.build | 4 ---- src/basic/missing_stdlib.h | 13 ------------- src/shared/libcrypt-util.c | 1 - 3 files changed, 18 deletions(-) delete mode 100644 src/basic/missing_stdlib.h diff --git a/meson.build b/meson.build index 7cf12bc452..a8876cfe01 100644 --- a/meson.build +++ b/meson.build @@ -598,10 +598,6 @@ endforeach conf.set10('WANT_LINUX_FS_H', want_linux_fs_h) -foreach ident : ['secure_getenv', '__secure_getenv'] - conf.set10('HAVE_' + ident.to_upper(), cc.has_function(ident)) -endforeach - foreach ident : [ ['fchmodat2', '''#include #include '''], # no known header declares fchmodat2 diff --git a/src/basic/missing_stdlib.h b/src/basic/missing_stdlib.h deleted file mode 100644 index 8c76f93eb2..0000000000 --- a/src/basic/missing_stdlib.h +++ /dev/null @@ -1,13 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#include - -/* stdlib.h */ -#if !HAVE_SECURE_GETENV -# if HAVE___SECURE_GETENV -# define secure_getenv __secure_getenv -# else -# error "neither secure_getenv nor __secure_getenv are available" -# endif -#endif diff --git a/src/shared/libcrypt-util.c b/src/shared/libcrypt-util.c index 50b2502166..c04c0eeea8 100644 --- a/src/shared/libcrypt-util.c +++ b/src/shared/libcrypt-util.c @@ -24,7 +24,6 @@ #include "log.h" #include "macro.h" #include "memory-util.h" -#include "missing_stdlib.h" #include "random-util.h" #include "string-util.h" #include "strv.h" From 883360f63aebde44a995b87a1939847b069269e8 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 00:08:35 +0900 Subject: [PATCH 15/36] missing_type: char16_t and char32_t are always defined in uchar.h since C11 Now, we use C17, hence the fallback definitions can be dropped. --- meson.build | 4 +--- src/basic/escape.h | 1 - src/basic/missing_type.h | 12 ------------ src/basic/utf8.h | 1 - 4 files changed, 1 insertion(+), 17 deletions(-) delete mode 100644 src/basic/missing_type.h diff --git a/meson.build b/meson.build index a8876cfe01..9402103401 100644 --- a/meson.build +++ b/meson.build @@ -569,11 +569,9 @@ decl_headers = ''' #include #include #include -#include ''' -foreach decl : ['char16_t', - 'char32_t', +foreach decl : [ 'struct mount_attr', 'struct dirent64', 'struct sched_attr', diff --git a/src/basic/escape.h b/src/basic/escape.h index 224a795aa4..05c27f688e 100644 --- a/src/basic/escape.h +++ b/src/basic/escape.h @@ -8,7 +8,6 @@ #include #include "string-util.h" -#include "missing_type.h" /* What characters are special in the shell? */ /* must be escaped outside and inside double-quotes */ diff --git a/src/basic/missing_type.h b/src/basic/missing_type.h deleted file mode 100644 index 1d17705c35..0000000000 --- a/src/basic/missing_type.h +++ /dev/null @@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#include - -#if !HAVE_CHAR32_T -# define char32_t uint32_t -#endif - -#if !HAVE_CHAR16_T -# define char16_t uint16_t -#endif diff --git a/src/basic/utf8.h b/src/basic/utf8.h index f6158b2ef1..3b1a468c4f 100644 --- a/src/basic/utf8.h +++ b/src/basic/utf8.h @@ -7,7 +7,6 @@ #include #include "macro.h" -#include "missing_type.h" #define UTF8_REPLACEMENT_CHARACTER "\xef\xbf\xbd" #define UTF8_BYTE_ORDER_MARK "\xef\xbb\xbf" From b5337d1d524545e9938391e871f39cccc1d1fc14 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 01:05:05 +0900 Subject: [PATCH 16/36] meson: cleanup glibc header checkers --- meson.build | 104 ++++++++++++++++++++-------------------------------- 1 file changed, 40 insertions(+), 64 deletions(-) diff --git a/meson.build b/meson.build index 9402103401..f31f637247 100644 --- a/meson.build +++ b/meson.build @@ -565,85 +565,61 @@ long_max = cc.compute_int( assert(long_max > 100000) conf.set_quoted('LONG_MAX_STR', '@0@'.format(long_max)) -decl_headers = ''' -#include -#include -#include -''' - -foreach decl : [ - 'struct mount_attr', - 'struct dirent64', - 'struct sched_attr', - ] - +foreach ident : [ + ['struct dirent64', '''##include '''], # for musl, but only for compile time check, see dirent-util.h + ['struct mount_attr', '''#include '''], # since glibc-2.36 + ['struct sched_attr', '''#include '''], # since glibc-2.41 +] # We get -1 if the size cannot be determined - have = cc.sizeof(decl, prefix : decl_headers, args : '-D_GNU_SOURCE') > 0 + have = cc.sizeof(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE') > 0 - if decl == 'struct mount_attr' + if ident[0] == 'struct mount_attr' if have want_linux_fs_h = false else - have = cc.sizeof(decl, - prefix : decl_headers + '#include ', + have = cc.sizeof(ident[0], + prefix : ident[1] + '\n#include ', args : '-D_GNU_SOURCE') > 0 want_linux_fs_h = have endif endif - conf.set10('HAVE_' + decl.underscorify().to_upper(), have) + conf.set10('HAVE_' + ident[0].underscorify().to_upper(), have) endforeach conf.set10('WANT_LINUX_FS_H', want_linux_fs_h) foreach ident : [ - ['fchmodat2', '''#include - #include '''], # no known header declares fchmodat2 - ['pivot_root', '''#include - #include '''], # no known header declares pivot_root - ['ioprio_get', '''#include '''], # no known header declares ioprio_get - ['ioprio_set', '''#include '''], # no known header declares ioprio_set - ['sched_setattr', '''#include '''], - ['kcmp', '''#include '''], - ['keyctl', '''#include - #include '''], - ['bpf', '''#include - #include '''], - ['set_mempolicy', '''#include - #include '''], - ['get_mempolicy', '''#include - #include '''], - ['pidfd_send_signal', '''#include - #include - #include - #include - #include '''], - ['pidfd_open', '''#include - #include - #include - #include - #include '''], - ['rt_tgsigqueueinfo', '''#include - #include - #include - #include '''], - ['mallinfo', '''#include '''], - ['mallinfo2', '''#include '''], - ['execveat', '''#include '''], - ['close_range', '''#include '''], - ['epoll_pwait2', '''#include '''], - ['mount_setattr', '''#include '''], - ['move_mount', '''#include '''], - ['open_tree', '''#include '''], - ['fsopen', '''#include '''], - ['fsconfig', '''#include '''], - ['fsmount', '''#include '''], - ['getdents64', '''#include '''], - ['pidfd_spawn', '''#include '''], - ['strerrorname_np', '''#include '''], - ['quotactl_fd', '''#include '''], - ['setxattrat', '''#include '''], # no known header declares setxattrat - ['removexattrat', '''#include '''], # no known header declares removexattrat + ['set_mempolicy', '''#include '''], # declared at numaif.h provided by libnuma, which we do not use + ['get_mempolicy', '''#include '''], # declared at numaif.h provided by libnuma, which we do not use + ['getdents64', '''#include '''], # since glibc-2.30, but check it for musl + ['strerrorname_np', '''#include '''], # since glibc-2.32 + ['mallinfo', '''#include '''], # deprecated since glibc-2.33, but check it for musl + ['mallinfo2', '''#include '''], # since glibc-2.33 + ['execveat', '''#include '''], # since glibc-2.34 + ['close_range', '''#include '''], # since glibc-2.34 + ['epoll_pwait2', '''#include '''], # since glibc-2.35 + ['fsconfig', '''#include '''], # since glibc-2.36 + ['fsmount', '''#include '''], # since glibc-2.36 + ['fsopen', '''#include '''], # since glibc-2.36 + ['mount_setattr', '''#include '''], # since glibc-2.36 + ['move_mount', '''#include '''], # since glibc-2.36 + ['open_tree', '''#include '''], # since glibc-2.36 + ['pidfd_open', '''#include '''], # since glibc-2.36 + ['pidfd_send_signal', '''#include '''], # since glibc-2.36 + ['pidfd_spawn', '''#include '''], # since glibc-2.39 + ['sched_setattr', '''#include '''], # since glibc-2.41 + ['ioprio_get', '''#include '''], # no known header declares ioprio_get + ['ioprio_set', '''#include '''], # no known header declares ioprio_set + ['rt_tgsigqueueinfo', '''#include '''], # no known header declares rt_tgsigqueueinfo + ['quotactl_fd', '''#include '''], # no known header declares quotactl_fd + ['fchmodat2', '''#include '''], # no known header declares fchmodat2 + ['bpf', '''#include '''], # no known header declares bpf + ['kcmp', '''#include '''], # no known header declares kcmp + ['keyctl', '''#include '''], # no known header declares keyctl + ['pivot_root', '''#include '''], # no known header declares pivot_root + ['setxattrat', '''#include '''], # no known header declares setxattrat + ['removexattrat', '''#include '''], # no known header declares removexattrat ] have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE') From c5cba760cfd11c1d65e24714b586253be354b1da Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 02:40:45 +0900 Subject: [PATCH 17/36] missing_fcntl: drop definitions covered by glibc-2.31 Note, this also fixes the definition for O_TMPFILE for parisc and hppa, it should be 040000000 (seven zeros) rather than 0400000000 (eight zeros). --- src/basic/missing_fcntl.h | 64 ++------------------------------------- 1 file changed, 3 insertions(+), 61 deletions(-) diff --git a/src/basic/missing_fcntl.h b/src/basic/missing_fcntl.h index b02c7be7a4..3c3f3a445f 100644 --- a/src/basic/missing_fcntl.h +++ b/src/basic/missing_fcntl.h @@ -3,74 +3,16 @@ #include -#ifndef F_LINUX_SPECIFIC_BASE -#define F_LINUX_SPECIFIC_BASE 1024 -#endif - +/* This is defined since glibc-2.41. */ #ifndef F_DUPFD_QUERY -#define F_DUPFD_QUERY (F_LINUX_SPECIFIC_BASE + 3) -#endif - -#ifndef F_SETPIPE_SZ -#define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7) -#endif - -#ifndef F_GETPIPE_SZ -#define F_GETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 8) -#endif - -#ifndef F_ADD_SEALS -#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9) -#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10) - -#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */ -#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */ -#define F_SEAL_GROW 0x0004 /* prevent file from growing */ -#define F_SEAL_WRITE 0x0008 /* prevent writes */ -#endif - -#ifndef F_SEAL_FUTURE_WRITE -#define F_SEAL_FUTURE_WRITE 0x0010 /* prevent future writes while mapped */ +#define F_DUPFD_QUERY 1027 #endif +/* This is defined since glibc-2.39. */ #ifndef F_SEAL_EXEC #define F_SEAL_EXEC 0x0020 /* prevent chmod modifying exec bits */ #endif -#ifndef F_OFD_GETLK -#define F_OFD_GETLK 36 -#define F_OFD_SETLK 37 -#define F_OFD_SETLKW 38 -#endif - -#ifndef MAX_HANDLE_SZ -#define MAX_HANDLE_SZ 128 -#endif - -/* The precise definition of __O_TMPFILE is arch specific; use the - * values defined by the kernel (note: some are hexa, some are octal, - * duplicated as-is from the kernel definitions): - * - alpha, parisc, sparc: each has a specific value; - * - others: they use the "generic" value. - */ - -#ifndef __O_TMPFILE -#if defined(__alpha__) -#define __O_TMPFILE 0100000000 -#elif defined(__parisc__) || defined(__hppa__) -#define __O_TMPFILE 0400000000 -#elif defined(__sparc__) || defined(__sparc64__) -#define __O_TMPFILE 0x2000000 -#else -#define __O_TMPFILE 020000000 -#endif -#endif - -/* a horrid kludge trying to make sure that this will fail on old kernels */ -#ifndef O_TMPFILE -#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY) -#endif - /* So O_LARGEFILE is generally implied by glibc, and defined to zero hence, because we only build in LFS * mode. However, when invoking fcntl(F_GETFL) the flag is ORed into the result anyway — glibc does not mask * it away. Which sucks. Let's define the actual value here, so that we can mask it ourselves. From 1b8f8a2d302d9f77ac5f91b3891bbe7d8486c7a0 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 02:50:07 +0900 Subject: [PATCH 18/36] missing_fs: drop unnecessary entries Now our kernel baseline is 5.4. --- src/basic/missing_fs.h | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/basic/missing_fs.h b/src/basic/missing_fs.h index 5c64cb6e0c..79c43c72f7 100644 --- a/src/basic/missing_fs.h +++ b/src/basic/missing_fs.h @@ -10,20 +10,6 @@ #define BLKGETDISKSEQ _IOR(0x12,128,__u64) #endif -#ifndef FICLONE /* 04b38d601239b4d9be641b412cf4b7456a041c67 (4.5) */ -#define FICLONE _IOW(0x94, 9, int) -#endif - -#ifndef FICLONERANGE /* 04b38d601239b4d9be641b412cf4b7456a041c67 (4.5) */ -#define FICLONERANGE _IOW(0x94, 13, struct file_clone_range) -struct file_clone_range { - __s64 src_fd; - __u64 src_offset; - __u64 src_length; - __u64 dest_offset; -}; -#endif - /* linux/fs.h or sys/mount.h */ #ifndef MS_MOVE # define MS_MOVE 8192 From 4dbaa211b5a9b515afaa3a4ec36b8a5a09833ff6 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 02:54:35 +0900 Subject: [PATCH 19/36] basic/linux: import hidraw.h and hid.h from linux-6.14-rc4 --- src/basic/linux/hid.h | 81 +++++++++++++++++++++++++++++++ src/basic/linux/hidraw.h | 59 ++++++++++++++++++++++ src/basic/missing_hidraw.h | 9 ---- src/login/logind-session-device.c | 2 +- 4 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 src/basic/linux/hid.h create mode 100644 src/basic/linux/hidraw.h delete mode 100644 src/basic/missing_hidraw.h diff --git a/src/basic/linux/hid.h b/src/basic/linux/hid.h new file mode 100644 index 0000000000..ad13cf85a0 --- /dev/null +++ b/src/basic/linux/hid.h @@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +/* + * Copyright (c) 1999 Andreas Gal + * Copyright (c) 2000-2001 Vojtech Pavlik + * Copyright (c) 2006-2007 Jiri Kosina + */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Should you need to contact me, the author, you can do so either by + * e-mail - mail your message to , or by paper mail: + * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic + */ +#ifndef __HID_H +#define __HID_H + + + +/* + * USB HID (Human Interface Device) interface class code + */ + +#define USB_INTERFACE_CLASS_HID 3 + +/* + * USB HID interface subclass and protocol codes + */ + +#define USB_INTERFACE_SUBCLASS_BOOT 1 +#define USB_INTERFACE_PROTOCOL_KEYBOARD 1 +#define USB_INTERFACE_PROTOCOL_MOUSE 2 + +/* + * HID report types --- Ouch! HID spec says 1 2 3! + */ + +enum hid_report_type { + HID_INPUT_REPORT = 0, + HID_OUTPUT_REPORT = 1, + HID_FEATURE_REPORT = 2, + + HID_REPORT_TYPES, +}; + +/* + * HID class requests + */ + +enum hid_class_request { + HID_REQ_GET_REPORT = 0x01, + HID_REQ_GET_IDLE = 0x02, + HID_REQ_GET_PROTOCOL = 0x03, + HID_REQ_SET_REPORT = 0x09, + HID_REQ_SET_IDLE = 0x0A, + HID_REQ_SET_PROTOCOL = 0x0B, +}; + +/* + * HID class descriptor types + */ + +#define HID_DT_HID (USB_TYPE_CLASS | 0x01) +#define HID_DT_REPORT (USB_TYPE_CLASS | 0x02) +#define HID_DT_PHYSICAL (USB_TYPE_CLASS | 0x03) + +#define HID_MAX_DESCRIPTOR_SIZE 4096 + + +#endif /* __HID_H */ diff --git a/src/basic/linux/hidraw.h b/src/basic/linux/hidraw.h new file mode 100644 index 0000000000..cdbafc2831 --- /dev/null +++ b/src/basic/linux/hidraw.h @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Copyright (c) 2007 Jiri Kosina + */ +/* + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + */ +#ifndef _HIDRAW_H +#define _HIDRAW_H + + + +#include +#include + +struct hidraw_report_descriptor { + __u32 size; + __u8 value[HID_MAX_DESCRIPTOR_SIZE]; +}; + +struct hidraw_devinfo { + __u32 bustype; + __s16 vendor; + __s16 product; +}; + +/* ioctl interface */ +#define HIDIOCGRDESCSIZE _IOR('H', 0x01, int) +#define HIDIOCGRDESC _IOR('H', 0x02, struct hidraw_report_descriptor) +#define HIDIOCGRAWINFO _IOR('H', 0x03, struct hidraw_devinfo) +#define HIDIOCGRAWNAME(len) _IOC(_IOC_READ, 'H', 0x04, len) +#define HIDIOCGRAWPHYS(len) _IOC(_IOC_READ, 'H', 0x05, len) +/* The first byte of SFEATURE and GFEATURE is the report number */ +#define HIDIOCSFEATURE(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x06, len) +#define HIDIOCGFEATURE(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x07, len) +#define HIDIOCGRAWUNIQ(len) _IOC(_IOC_READ, 'H', 0x08, len) +/* The first byte of SINPUT and GINPUT is the report number */ +#define HIDIOCSINPUT(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x09, len) +#define HIDIOCGINPUT(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x0A, len) +/* The first byte of SOUTPUT and GOUTPUT is the report number */ +#define HIDIOCSOUTPUT(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x0B, len) +#define HIDIOCGOUTPUT(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x0C, len) +#define HIDIOCREVOKE _IOW('H', 0x0D, int) /* Revoke device access */ + +#define HIDRAW_FIRST_MINOR 0 +#define HIDRAW_MAX_DEVICES 64 +/* number of reports to buffer */ +#define HIDRAW_BUFFER_SIZE 64 + + +/* kernel-only API declarations */ + +#endif /* _HIDRAW_H */ diff --git a/src/basic/missing_hidraw.h b/src/basic/missing_hidraw.h deleted file mode 100644 index 98ba5c019a..0000000000 --- a/src/basic/missing_hidraw.h +++ /dev/null @@ -1,9 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#include - -/* b31c9d9dc343146b9f4ce67b4eee748c49296e99 (6.12) */ -#ifndef HIDIOCREVOKE -#define HIDIOCREVOKE _IOW('H', 0x0D, int) -#endif diff --git a/src/login/logind-session-device.c b/src/login/logind-session-device.c index adea60aef6..035a367954 100644 --- a/src/login/logind-session-device.c +++ b/src/login/logind-session-device.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include #include #include #include @@ -16,7 +17,6 @@ #include "logind-session-dbus.h" #include "logind-session-device.h" #include "missing_drm.h" -#include "missing_hidraw.h" #include "missing_input.h" #include "parse-util.h" From 87fb62f598cc50070229334d81f40d4add0be47d Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 03:02:00 +0900 Subject: [PATCH 20/36] missing_input: replace the header with genuine linux header --- src/basic/missing_input.h | 58 ------------------------------- src/login/logind-button.c | 2 +- src/login/logind-session-device.c | 2 +- src/udev/udev-builtin-input_id.c | 4 +-- 4 files changed, 4 insertions(+), 62 deletions(-) delete mode 100644 src/basic/missing_input.h diff --git a/src/basic/missing_input.h b/src/basic/missing_input.h deleted file mode 100644 index ee61bf99d6..0000000000 --- a/src/basic/missing_input.h +++ /dev/null @@ -1,58 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#include -#include - -#include "macro.h" - -/* linux@c7dc65737c9a607d3e6f8478659876074ad129b8 (3.12) */ -#ifndef EVIOCREVOKE -# define EVIOCREVOKE _IOW('E', 0x91, int) -#endif - -/* linux@06a16293f71927f756dcf37558a79c0b05a91641 (4.4) */ -#ifndef EVIOCSMASK -struct input_mask { - __u32 type; - __u32 codes_size; - __u64 codes_ptr; -}; - -# define EVIOCGMASK _IOR('E', 0x92, struct input_mask) -# define EVIOCSMASK _IOW('E', 0x93, struct input_mask) -#endif - -/* linux@7611392fe8ff95ecae528b01a815ae3d72ca6b95 (3.17) */ -#ifndef INPUT_PROP_POINTING_STICK -# define INPUT_PROP_POINTING_STICK 0x05 -#else -assert_cc(INPUT_PROP_POINTING_STICK == 0x05); -#endif - -/* linux@500d4160abe9a2e88b12e319c13ae3ebd1e18108 (4.0) */ -#ifndef INPUT_PROP_ACCELEROMETER -# define INPUT_PROP_ACCELEROMETER 0x06 -#else -assert_cc(INPUT_PROP_ACCELEROMETER == 0x06); -#endif - -/* linux@d09bbfd2a8408a995419dff0d2ba906013cf4cc9 (3.11) */ -#ifndef BTN_DPAD_UP -# define BTN_DPAD_UP 0x220 -# define BTN_DPAD_DOWN 0x221 -# define BTN_DPAD_LEFT 0x222 -# define BTN_DPAD_RIGHT 0x223 -#else -assert_cc(BTN_DPAD_UP == 0x220); -assert_cc(BTN_DPAD_DOWN == 0x221); -assert_cc(BTN_DPAD_LEFT == 0x222); -assert_cc(BTN_DPAD_RIGHT == 0x223); -#endif - -/* linux@358f24704f2f016af7d504b357cdf32606091d07 (3.13) */ -#ifndef KEY_ALS_TOGGLE -# fine KEY_ALS_TOGGLE 0x230 -#else -assert_cc(KEY_ALS_TOGGLE == 0x230); -#endif diff --git a/src/login/logind-button.c b/src/login/logind-button.c index f980ea5ece..bc49305fcd 100644 --- a/src/login/logind-button.c +++ b/src/login/logind-button.c @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -12,7 +13,6 @@ #include "fd-util.h" #include "logind-button.h" #include "logind-dbus.h" -#include "missing_input.h" #include "string-util.h" /* KEY_RESTART is the highest value key in keys_interested. */ diff --git a/src/login/logind-session-device.c b/src/login/logind-session-device.c index 035a367954..f0730f751c 100644 --- a/src/login/logind-session-device.c +++ b/src/login/logind-session-device.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -17,7 +18,6 @@ #include "logind-session-dbus.h" #include "logind-session-device.h" #include "missing_drm.h" -#include "missing_input.h" #include "parse-util.h" enum SessionDeviceNotifications { diff --git a/src/udev/udev-builtin-input_id.c b/src/udev/udev-builtin-input_id.c index 509edee8aa..f16ca00e13 100644 --- a/src/udev/udev-builtin-input_id.c +++ b/src/udev/udev-builtin-input_id.c @@ -8,13 +8,13 @@ #include #include +#include +#include #include #include -#include #include "device-util.h" #include "fd-util.h" -#include "missing_input.h" #include "parse-util.h" #include "stdio-util.h" #include "string-util.h" From e7e91769e86f27b8243ff4f8d3dea3336ea17298 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 03:09:43 +0900 Subject: [PATCH 21/36] basic/linux: import ioprio.h from kernel 6.14-rc4 This also fixes the maximum allowed ioprio class: 8 -> 7 --- meson.build | 1 - src/basic/ioprio-util.c | 6 +- src/basic/ioprio-util.h | 17 ++++- src/basic/linux/ioprio.h | 127 +++++++++++++++++++++++++++++++++++ src/basic/missing_ioprio.h | 89 ------------------------ src/core/dbus-execute.c | 3 +- src/core/exec-invoke.c | 2 +- src/core/load-fragment.c | 3 +- src/test/test-process-util.c | 2 +- 9 files changed, 149 insertions(+), 101 deletions(-) create mode 100644 src/basic/linux/ioprio.h delete mode 100644 src/basic/missing_ioprio.h diff --git a/meson.build b/meson.build index f31f637247..f69ead2ddc 100644 --- a/meson.build +++ b/meson.build @@ -707,7 +707,6 @@ if not cc.has_header('sys/capability.h') error('POSIX caps headers not found') endif foreach header : ['crypt.h', - 'linux/ioprio.h', 'sys/sdt.h', 'threads.h', 'valgrind/memcheck.h', diff --git a/src/basic/ioprio-util.c b/src/basic/ioprio-util.c index b63650b80b..3add1bddd0 100644 --- a/src/basic/ioprio-util.c +++ b/src/basic/ioprio-util.c @@ -23,9 +23,9 @@ int ioprio_parse_priority(const char *s, int *ret) { static const char *const ioprio_class_table[] = { [IOPRIO_CLASS_NONE] = "none", - [IOPRIO_CLASS_RT] = "realtime", - [IOPRIO_CLASS_BE] = "best-effort", + [IOPRIO_CLASS_RT] = "realtime", + [IOPRIO_CLASS_BE] = "best-effort", [IOPRIO_CLASS_IDLE] = "idle", }; -DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ioprio_class, int, IOPRIO_N_CLASSES); +DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ioprio_class, int, IOPRIO_NR_CLASSES-1); diff --git a/src/basic/ioprio-util.h b/src/basic/ioprio-util.h index b8c9b7dd59..376eb85dad 100644 --- a/src/basic/ioprio-util.h +++ b/src/basic/ioprio-util.h @@ -1,8 +1,21 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include + #include "macro.h" -#include "missing_ioprio.h" + +static inline int ioprio_prio_class(int value) { + return IOPRIO_PRIO_CLASS(value); +} + +static inline int ioprio_prio_data(int value) { + return IOPRIO_PRIO_DATA(value); +} + +static inline int ioprio_prio_value(int class, int data) { + return IOPRIO_PRIO_VALUE_HINT(class, IOPRIO_PRIO_LEVEL(data), IOPRIO_PRIO_HINT(data)); +} int ioprio_class_to_string_alloc(int i, char **s); int ioprio_class_from_string(const char *s); @@ -12,7 +25,7 @@ static inline bool ioprio_class_is_valid(int i) { } static inline bool ioprio_priority_is_valid(int i) { - return i >= 0 && i < IOPRIO_BE_NR; + return i >= 0 && i < IOPRIO_NR_LEVELS; } int ioprio_parse_priority(const char *s, int *ret); diff --git a/src/basic/linux/ioprio.h b/src/basic/linux/ioprio.h new file mode 100644 index 0000000000..9a51dd0c9b --- /dev/null +++ b/src/basic/linux/ioprio.h @@ -0,0 +1,127 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _LINUX_IOPRIO_H +#define _LINUX_IOPRIO_H + +#include +#include + +/* + * Gives us 8 prio classes with 13-bits of data for each class + */ +#define IOPRIO_CLASS_SHIFT 13 +#define IOPRIO_NR_CLASSES 8 +#define IOPRIO_CLASS_MASK (IOPRIO_NR_CLASSES - 1) +#define IOPRIO_PRIO_MASK ((1UL << IOPRIO_CLASS_SHIFT) - 1) + +#define IOPRIO_PRIO_CLASS(ioprio) \ + (((ioprio) >> IOPRIO_CLASS_SHIFT) & IOPRIO_CLASS_MASK) +#define IOPRIO_PRIO_DATA(ioprio) ((ioprio) & IOPRIO_PRIO_MASK) + +/* + * These are the io priority classes as implemented by the BFQ and mq-deadline + * schedulers. RT is the realtime class, it always gets premium service. For + * ATA disks supporting NCQ IO priority, RT class IOs will be processed using + * high priority NCQ commands. BE is the best-effort scheduling class, the + * default for any process. IDLE is the idle scheduling class, it is only + * served when no one else is using the disk. + */ +enum { + IOPRIO_CLASS_NONE = 0, + IOPRIO_CLASS_RT = 1, + IOPRIO_CLASS_BE = 2, + IOPRIO_CLASS_IDLE = 3, + + /* Special class to indicate an invalid ioprio value */ + IOPRIO_CLASS_INVALID = 7, +}; + +/* + * The RT and BE priority classes both support up to 8 priority levels that + * can be specified using the lower 3-bits of the priority data. + */ +#define IOPRIO_LEVEL_NR_BITS 3 +#define IOPRIO_NR_LEVELS (1 << IOPRIO_LEVEL_NR_BITS) +#define IOPRIO_LEVEL_MASK (IOPRIO_NR_LEVELS - 1) +#define IOPRIO_PRIO_LEVEL(ioprio) ((ioprio) & IOPRIO_LEVEL_MASK) + +#define IOPRIO_BE_NR IOPRIO_NR_LEVELS + +/* + * Possible values for the "which" argument of the ioprio_get() and + * ioprio_set() system calls (see "man ioprio_set"). + */ +enum { + IOPRIO_WHO_PROCESS = 1, + IOPRIO_WHO_PGRP, + IOPRIO_WHO_USER, +}; + +/* + * Fallback BE class priority level. + */ +#define IOPRIO_NORM 4 +#define IOPRIO_BE_NORM IOPRIO_NORM + +/* + * The 10 bits between the priority class and the priority level are used to + * optionally define I/O hints for any combination of I/O priority class and + * level. Depending on the kernel configuration, I/O scheduler being used and + * the target I/O device being used, hints can influence how I/Os are processed + * without affecting the I/O scheduling ordering defined by the I/O priority + * class and level. + */ +#define IOPRIO_HINT_SHIFT IOPRIO_LEVEL_NR_BITS +#define IOPRIO_HINT_NR_BITS 10 +#define IOPRIO_NR_HINTS (1 << IOPRIO_HINT_NR_BITS) +#define IOPRIO_HINT_MASK (IOPRIO_NR_HINTS - 1) +#define IOPRIO_PRIO_HINT(ioprio) \ + (((ioprio) >> IOPRIO_HINT_SHIFT) & IOPRIO_HINT_MASK) + +/* + * I/O hints. + */ +enum { + /* No hint */ + IOPRIO_HINT_NONE = 0, + + /* + * Device command duration limits: indicate to the device a desired + * duration limit for the commands that will be used to process an I/O. + * These will currently only be effective for SCSI and ATA devices that + * support the command duration limits feature. If this feature is + * enabled, then the commands issued to the device to process an I/O with + * one of these hints set will have the duration limit index (dld field) + * set to the value of the hint. + */ + IOPRIO_HINT_DEV_DURATION_LIMIT_1 = 1, + IOPRIO_HINT_DEV_DURATION_LIMIT_2 = 2, + IOPRIO_HINT_DEV_DURATION_LIMIT_3 = 3, + IOPRIO_HINT_DEV_DURATION_LIMIT_4 = 4, + IOPRIO_HINT_DEV_DURATION_LIMIT_5 = 5, + IOPRIO_HINT_DEV_DURATION_LIMIT_6 = 6, + IOPRIO_HINT_DEV_DURATION_LIMIT_7 = 7, +}; + +#define IOPRIO_BAD_VALUE(val, max) ((val) < 0 || (val) >= (max)) + +/* + * Return an I/O priority value based on a class, a level and a hint. + */ +static __always_inline __u16 ioprio_value(int prioclass, int priolevel, + int priohint) +{ + if (IOPRIO_BAD_VALUE(prioclass, IOPRIO_NR_CLASSES) || + IOPRIO_BAD_VALUE(priolevel, IOPRIO_NR_LEVELS) || + IOPRIO_BAD_VALUE(priohint, IOPRIO_NR_HINTS)) + return IOPRIO_CLASS_INVALID << IOPRIO_CLASS_SHIFT; + + return (prioclass << IOPRIO_CLASS_SHIFT) | + (priohint << IOPRIO_HINT_SHIFT) | priolevel; +} + +#define IOPRIO_PRIO_VALUE(prioclass, priolevel) \ + ioprio_value(prioclass, priolevel, IOPRIO_HINT_NONE) +#define IOPRIO_PRIO_VALUE_HINT(prioclass, priolevel, priohint) \ + ioprio_value(prioclass, priolevel, priohint) + +#endif /* _LINUX_IOPRIO_H */ diff --git a/src/basic/missing_ioprio.h b/src/basic/missing_ioprio.h deleted file mode 100644 index 1f7323d813..0000000000 --- a/src/basic/missing_ioprio.h +++ /dev/null @@ -1,89 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#if HAVE_LINUX_IOPRIO_H -# include -#endif - -#include "macro.h" - -#ifndef IOPRIO_N_CLASSES -# define IOPRIO_N_CLASSES 8 -#else -assert_cc(IOPRIO_N_CLASSES == 8); -#endif - -#ifndef IOPRIO_BE_NR -# define IOPRIO_BE_NR 8 -#else -assert_cc(IOPRIO_BE_NR == 8); -#endif - -#ifndef IOPRIO_CLASS_NONE -# define IOPRIO_CLASS_NONE 0 -#else -assert_cc(IOPRIO_CLASS_NONE == 0); -#endif -#ifndef IOPRIO_CLASS_RT -# define IOPRIO_CLASS_RT 1 -#else -assert_cc(IOPRIO_CLASS_RT == 1); -#endif -#ifndef IOPRIO_CLASS_BE -# define IOPRIO_CLASS_BE 2 -#else -assert_cc(IOPRIO_CLASS_BE == 2); -#endif -#ifndef IOPRIO_CLASS_IDLE -# define IOPRIO_CLASS_IDLE 3 -#else -assert_cc(IOPRIO_CLASS_IDLE == 3); -#endif - -#ifndef IOPRIO_WHO_PROCESS -# define IOPRIO_WHO_PROCESS 1 -#else -assert_cc(IOPRIO_WHO_PROCESS == 1); -#endif - -#ifndef IOPRIO_WHO_PGRP -# define IOPRIO_WHO_PGRP 2 -#else -assert_cc(IOPRIO_WHO_PGRP == 2); -#endif - -#ifndef IOPRIO_WHO_USER -# define IOPRIO_WHO_USER 3 -#else -assert_cc(IOPRIO_WHO_USER == 3); -#endif - -#ifndef IOPRIO_BITS -# define IOPRIO_BITS 16 -#else -assert_cc(IOPRIO_BITS == 16); -#endif - -#ifndef IOPRIO_N_CLASSES -# define IOPRIO_N_CLASSES 8 -#else -assert_cc(IOPRIO_N_CLASSES == 8); -#endif - -#ifndef IOPRIO_CLASS_SHIFT -# define IOPRIO_CLASS_SHIFT 13 -#else -assert_cc(IOPRIO_CLASS_SHIFT == 13); -#endif - -static inline int ioprio_prio_class(int value) { - return value >> IOPRIO_CLASS_SHIFT; -} - -static inline int ioprio_prio_data(int value) { - return value & ((1 << IOPRIO_CLASS_SHIFT) - 1); -} - -static inline int ioprio_prio_value(int class, int data) { - return (class << IOPRIO_CLASS_SHIFT) | data; -} diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index 8039565f26..2e2e142a19 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -22,12 +22,11 @@ #include "fileio.h" #include "hexdecoct.h" #include "hostname-util.h" -#include "iovec-util.h" #include "ioprio-util.h" +#include "iovec-util.h" #include "journal-file.h" #include "load-fragment.h" #include "memstream-util.h" -#include "missing_ioprio.h" #include "mountpoint-util.h" #include "namespace.h" #include "parse-util.h" diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index 37df73adb7..8d1e072d3f 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -37,10 +37,10 @@ #include "hexdecoct.h" #include "hostname-setup.h" #include "io-util.h" +#include "ioprio-util.h" #include "iovec-util.h" #include "journal-send.h" #include "memfd-util.h" -#include "missing_ioprio.h" #include "missing_prctl.h" #include "missing_sched.h" #include "missing_securebits.h" diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 5cb5494b0b..dde7a55f4f 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -41,14 +41,13 @@ #include "fstab-util.h" #include "hexdecoct.h" #include "hostname-util.h" -#include "iovec-util.h" #include "ioprio-util.h" +#include "iovec-util.h" #include "ip-protocol-list.h" #include "journal-file.h" #include "limits-util.h" #include "load-fragment.h" #include "log.h" -#include "missing_ioprio.h" #include "mountpoint-util.h" #include "nulstr-util.h" #include "open-file.h" diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index 7bd416f8d0..0f00089eec 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -721,7 +721,7 @@ TEST(ioprio_class_from_to_string) { test_ioprio_class_from_to_string_one("0", IOPRIO_CLASS_NONE, IOPRIO_CLASS_BE); test_ioprio_class_from_to_string_one("1", 1, 1); test_ioprio_class_from_to_string_one("7", 7, 7); - test_ioprio_class_from_to_string_one("8", 8, 8); + test_ioprio_class_from_to_string_one("8", -EINVAL, -EINVAL); test_ioprio_class_from_to_string_one("9", -EINVAL, -EINVAL); test_ioprio_class_from_to_string_one("-1", -EINVAL, -EINVAL); } From fa716b6fc7b53fbb2d0d28868705140d85ded983 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 03:38:23 +0900 Subject: [PATCH 22/36] missing_keyctl: import keyctl.h from kernel 6.14-rc4 --- src/basic/linux/keyctl.h | 136 +++++++++++++++++++++++++++++++++++++ src/basic/missing_keyctl.h | 54 --------------- 2 files changed, 136 insertions(+), 54 deletions(-) create mode 100644 src/basic/linux/keyctl.h diff --git a/src/basic/linux/keyctl.h b/src/basic/linux/keyctl.h new file mode 100644 index 0000000000..222c6c688a --- /dev/null +++ b/src/basic/linux/keyctl.h @@ -0,0 +1,136 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +/* keyctl.h: keyctl command IDs + * + * Copyright (C) 2004, 2008 Red Hat, Inc. All Rights Reserved. + * Written by David Howells (dhowells@redhat.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ + +#ifndef _LINUX_KEYCTL_H +#define _LINUX_KEYCTL_H + +#include + +/* special process keyring shortcut IDs */ +#define KEY_SPEC_THREAD_KEYRING -1 /* - key ID for thread-specific keyring */ +#define KEY_SPEC_PROCESS_KEYRING -2 /* - key ID for process-specific keyring */ +#define KEY_SPEC_SESSION_KEYRING -3 /* - key ID for session-specific keyring */ +#define KEY_SPEC_USER_KEYRING -4 /* - key ID for UID-specific keyring */ +#define KEY_SPEC_USER_SESSION_KEYRING -5 /* - key ID for UID-session keyring */ +#define KEY_SPEC_GROUP_KEYRING -6 /* - key ID for GID-specific keyring */ +#define KEY_SPEC_REQKEY_AUTH_KEY -7 /* - key ID for assumed request_key auth key */ +#define KEY_SPEC_REQUESTOR_KEYRING -8 /* - key ID for request_key() dest keyring */ + +/* request-key default keyrings */ +#define KEY_REQKEY_DEFL_NO_CHANGE -1 +#define KEY_REQKEY_DEFL_DEFAULT 0 +#define KEY_REQKEY_DEFL_THREAD_KEYRING 1 +#define KEY_REQKEY_DEFL_PROCESS_KEYRING 2 +#define KEY_REQKEY_DEFL_SESSION_KEYRING 3 +#define KEY_REQKEY_DEFL_USER_KEYRING 4 +#define KEY_REQKEY_DEFL_USER_SESSION_KEYRING 5 +#define KEY_REQKEY_DEFL_GROUP_KEYRING 6 +#define KEY_REQKEY_DEFL_REQUESTOR_KEYRING 7 + +/* keyctl commands */ +#define KEYCTL_GET_KEYRING_ID 0 /* ask for a keyring's ID */ +#define KEYCTL_JOIN_SESSION_KEYRING 1 /* join or start named session keyring */ +#define KEYCTL_UPDATE 2 /* update a key */ +#define KEYCTL_REVOKE 3 /* revoke a key */ +#define KEYCTL_CHOWN 4 /* set ownership of a key */ +#define KEYCTL_SETPERM 5 /* set perms on a key */ +#define KEYCTL_DESCRIBE 6 /* describe a key */ +#define KEYCTL_CLEAR 7 /* clear contents of a keyring */ +#define KEYCTL_LINK 8 /* link a key into a keyring */ +#define KEYCTL_UNLINK 9 /* unlink a key from a keyring */ +#define KEYCTL_SEARCH 10 /* search for a key in a keyring */ +#define KEYCTL_READ 11 /* read a key or keyring's contents */ +#define KEYCTL_INSTANTIATE 12 /* instantiate a partially constructed key */ +#define KEYCTL_NEGATE 13 /* negate a partially constructed key */ +#define KEYCTL_SET_REQKEY_KEYRING 14 /* set default request-key keyring */ +#define KEYCTL_SET_TIMEOUT 15 /* set key timeout */ +#define KEYCTL_ASSUME_AUTHORITY 16 /* assume request_key() authorisation */ +#define KEYCTL_GET_SECURITY 17 /* get key security label */ +#define KEYCTL_SESSION_TO_PARENT 18 /* apply session keyring to parent process */ +#define KEYCTL_REJECT 19 /* reject a partially constructed key */ +#define KEYCTL_INSTANTIATE_IOV 20 /* instantiate a partially constructed key */ +#define KEYCTL_INVALIDATE 21 /* invalidate a key */ +#define KEYCTL_GET_PERSISTENT 22 /* get a user's persistent keyring */ +#define KEYCTL_DH_COMPUTE 23 /* Compute Diffie-Hellman values */ +#define KEYCTL_PKEY_QUERY 24 /* Query public key parameters */ +#define KEYCTL_PKEY_ENCRYPT 25 /* Encrypt a blob using a public key */ +#define KEYCTL_PKEY_DECRYPT 26 /* Decrypt a blob using a public key */ +#define KEYCTL_PKEY_SIGN 27 /* Create a public key signature */ +#define KEYCTL_PKEY_VERIFY 28 /* Verify a public key signature */ +#define KEYCTL_RESTRICT_KEYRING 29 /* Restrict keys allowed to link to a keyring */ +#define KEYCTL_MOVE 30 /* Move keys between keyrings */ +#define KEYCTL_CAPABILITIES 31 /* Find capabilities of keyrings subsystem */ +#define KEYCTL_WATCH_KEY 32 /* Watch a key or ring of keys for changes */ + +/* keyctl structures */ +struct keyctl_dh_params { + union { +#ifndef __cplusplus + __s32 private; +#endif + __s32 priv; + }; + __s32 prime; + __s32 base; +}; + +struct keyctl_kdf_params { + char *hashname; + char *otherinfo; + __u32 otherinfolen; + __u32 __spare[8]; +}; + +#define KEYCTL_SUPPORTS_ENCRYPT 0x01 +#define KEYCTL_SUPPORTS_DECRYPT 0x02 +#define KEYCTL_SUPPORTS_SIGN 0x04 +#define KEYCTL_SUPPORTS_VERIFY 0x08 + +struct keyctl_pkey_query { + __u32 supported_ops; /* Which ops are supported */ + __u32 key_size; /* Size of the key in bits */ + __u16 max_data_size; /* Maximum size of raw data to sign in bytes */ + __u16 max_sig_size; /* Maximum size of signature in bytes */ + __u16 max_enc_size; /* Maximum size of encrypted blob in bytes */ + __u16 max_dec_size; /* Maximum size of decrypted blob in bytes */ + __u32 __spare[10]; +}; + +struct keyctl_pkey_params { + __s32 key_id; /* Serial no. of public key to use */ + __u32 in_len; /* Input data size */ + union { + __u32 out_len; /* Output buffer size (encrypt/decrypt/sign) */ + __u32 in2_len; /* 2nd input data size (verify) */ + }; + __u32 __spare[7]; +}; + +#define KEYCTL_MOVE_EXCL 0x00000001 /* Do not displace from the to-keyring */ + +/* + * Capabilities flags. The capabilities list is an array of 8-bit integers; + * each integer can carry up to 8 flags. + */ +#define KEYCTL_CAPS0_CAPABILITIES 0x01 /* KEYCTL_CAPABILITIES supported */ +#define KEYCTL_CAPS0_PERSISTENT_KEYRINGS 0x02 /* Persistent keyrings enabled */ +#define KEYCTL_CAPS0_DIFFIE_HELLMAN 0x04 /* Diffie-Hellman computation enabled */ +#define KEYCTL_CAPS0_PUBLIC_KEY 0x08 /* Public key ops enabled */ +#define KEYCTL_CAPS0_BIG_KEY 0x10 /* big_key-type enabled */ +#define KEYCTL_CAPS0_INVALIDATE 0x20 /* KEYCTL_INVALIDATE supported */ +#define KEYCTL_CAPS0_RESTRICT_KEYRING 0x40 /* KEYCTL_RESTRICT_KEYRING supported */ +#define KEYCTL_CAPS0_MOVE 0x80 /* KEYCTL_MOVE supported */ +#define KEYCTL_CAPS1_NS_KEYRING_NAME 0x01 /* Keyring names are per-user_namespace */ +#define KEYCTL_CAPS1_NS_KEY_TAG 0x02 /* Key indexing can include a namespace tag */ +#define KEYCTL_CAPS1_NOTIFICATIONS 0x04 /* Keys generate watchable notifications */ + +#endif /* _LINUX_KEYCTL_H */ diff --git a/src/basic/missing_keyctl.h b/src/basic/missing_keyctl.h index 78795fa352..01063fd193 100644 --- a/src/basic/missing_keyctl.h +++ b/src/basic/missing_keyctl.h @@ -6,60 +6,6 @@ #include "macro.h" -#ifndef KEYCTL_JOIN_SESSION_KEYRING -# define KEYCTL_JOIN_SESSION_KEYRING 1 -#else -assert_cc(KEYCTL_JOIN_SESSION_KEYRING == 1); -#endif - -#ifndef KEYCTL_CHOWN -# define KEYCTL_CHOWN 4 -#else -assert_cc(KEYCTL_CHOWN == 4); -#endif - -#ifndef KEYCTL_SETPERM -# define KEYCTL_SETPERM 5 -#else -assert_cc(KEYCTL_SETPERM == 5); -#endif - -#ifndef KEYCTL_DESCRIBE -# define KEYCTL_DESCRIBE 6 -#else -assert_cc(KEYCTL_DESCRIBE == 6); -#endif - -#ifndef KEYCTL_LINK -# define KEYCTL_LINK 8 -#else -assert_cc(KEYCTL_LINK == 8); -#endif - -#ifndef KEYCTL_READ -# define KEYCTL_READ 11 -#else -assert_cc(KEYCTL_READ == 11); -#endif - -#ifndef KEYCTL_SET_TIMEOUT -# define KEYCTL_SET_TIMEOUT 15 -#else -assert_cc(KEYCTL_SET_TIMEOUT == 15); -#endif - -#ifndef KEY_SPEC_USER_KEYRING -# define KEY_SPEC_USER_KEYRING -4 -#else -assert_cc(KEY_SPEC_USER_KEYRING == -4); -#endif - -#ifndef KEY_SPEC_SESSION_KEYRING -# define KEY_SPEC_SESSION_KEYRING -3 -#else -assert_cc(KEY_SPEC_SESSION_KEYRING == -3); -#endif - /* From linux/key.h */ #ifndef KEY_POS_VIEW From dc1a78a462c22f1cd5c72bf84cdf13447de5987a Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 03:43:33 +0900 Subject: [PATCH 23/36] basic/linux: import loop.h from kernel 6.14-rc4, and drop missing_loop.h --- src/basic/linux/loop.h | 120 +++++++++++++++++++++++++++++++++++++ src/basic/missing_loop.h | 39 ------------ src/mountfsd/mountwork.c | 2 +- src/shared/loop-util.c | 1 - src/test/test-loop-block.c | 1 - 5 files changed, 121 insertions(+), 42 deletions(-) create mode 100644 src/basic/linux/loop.h delete mode 100644 src/basic/missing_loop.h diff --git a/src/basic/linux/loop.h b/src/basic/linux/loop.h new file mode 100644 index 0000000000..3d128de4e9 --- /dev/null +++ b/src/basic/linux/loop.h @@ -0,0 +1,120 @@ +/* SPDX-License-Identifier: GPL-1.0+ WITH Linux-syscall-note */ +/* + * Copyright 1993 by Theodore Ts'o. + */ +#ifndef _LINUX_LOOP_H +#define _LINUX_LOOP_H + + +#define LO_NAME_SIZE 64 +#define LO_KEY_SIZE 32 + + +/* + * Loop flags + */ +enum { + LO_FLAGS_READ_ONLY = 1, + LO_FLAGS_AUTOCLEAR = 4, + LO_FLAGS_PARTSCAN = 8, + LO_FLAGS_DIRECT_IO = 16, +}; + +/* LO_FLAGS that can be set using LOOP_SET_STATUS(64) */ +#define LOOP_SET_STATUS_SETTABLE_FLAGS (LO_FLAGS_AUTOCLEAR | LO_FLAGS_PARTSCAN) + +/* LO_FLAGS that can be cleared using LOOP_SET_STATUS(64) */ +#define LOOP_SET_STATUS_CLEARABLE_FLAGS (LO_FLAGS_AUTOCLEAR) + +/* LO_FLAGS that can be set using LOOP_CONFIGURE */ +#define LOOP_CONFIGURE_SETTABLE_FLAGS (LO_FLAGS_READ_ONLY | LO_FLAGS_AUTOCLEAR \ + | LO_FLAGS_PARTSCAN | LO_FLAGS_DIRECT_IO) + +#include /* for __kernel_old_dev_t */ +#include /* for __u64 */ + +/* Backwards compatibility version */ +struct loop_info { + int lo_number; /* ioctl r/o */ + __kernel_old_dev_t lo_device; /* ioctl r/o */ + unsigned long lo_inode; /* ioctl r/o */ + __kernel_old_dev_t lo_rdevice; /* ioctl r/o */ + int lo_offset; + int lo_encrypt_type; /* obsolete, ignored */ + int lo_encrypt_key_size; /* ioctl w/o */ + int lo_flags; + char lo_name[LO_NAME_SIZE]; + unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */ + unsigned long lo_init[2]; + char reserved[4]; +}; + +struct loop_info64 { + __u64 lo_device; /* ioctl r/o */ + __u64 lo_inode; /* ioctl r/o */ + __u64 lo_rdevice; /* ioctl r/o */ + __u64 lo_offset; + __u64 lo_sizelimit;/* bytes, 0 == max available */ + __u32 lo_number; /* ioctl r/o */ + __u32 lo_encrypt_type; /* obsolete, ignored */ + __u32 lo_encrypt_key_size; /* ioctl w/o */ + __u32 lo_flags; + __u8 lo_file_name[LO_NAME_SIZE]; + __u8 lo_crypt_name[LO_NAME_SIZE]; + __u8 lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */ + __u64 lo_init[2]; +}; + +/** + * struct loop_config - Complete configuration for a loop device. + * @fd: fd of the file to be used as a backing file for the loop device. + * @block_size: block size to use; ignored if 0. + * @info: struct loop_info64 to configure the loop device with. + * + * This structure is used with the LOOP_CONFIGURE ioctl, and can be used to + * atomically setup and configure all loop device parameters at once. + */ +struct loop_config { + __u32 fd; + __u32 block_size; + struct loop_info64 info; + __u64 __reserved[8]; +}; + +/* + * Loop filter types + */ + +#define LO_CRYPT_NONE 0 +#define LO_CRYPT_XOR 1 +#define LO_CRYPT_DES 2 +#define LO_CRYPT_FISH2 3 /* Twofish encryption */ +#define LO_CRYPT_BLOW 4 +#define LO_CRYPT_CAST128 5 +#define LO_CRYPT_IDEA 6 +#define LO_CRYPT_DUMMY 9 +#define LO_CRYPT_SKIPJACK 10 +#define LO_CRYPT_CRYPTOAPI 18 +#define MAX_LO_CRYPT 20 + +/* + * IOCTL commands --- we will commandeer 0x4C ('L') + */ + +#define LOOP_SET_FD 0x4C00 +#define LOOP_CLR_FD 0x4C01 +#define LOOP_SET_STATUS 0x4C02 +#define LOOP_GET_STATUS 0x4C03 +#define LOOP_SET_STATUS64 0x4C04 +#define LOOP_GET_STATUS64 0x4C05 +#define LOOP_CHANGE_FD 0x4C06 +#define LOOP_SET_CAPACITY 0x4C07 +#define LOOP_SET_DIRECT_IO 0x4C08 +#define LOOP_SET_BLOCK_SIZE 0x4C09 +#define LOOP_CONFIGURE 0x4C0A + +/* /dev/loop-control interface */ +#define LOOP_CTL_ADD 0x4C80 +#define LOOP_CTL_REMOVE 0x4C81 +#define LOOP_CTL_GET_FREE 0x4C82 +#endif /* _LINUX_LOOP_H */ diff --git a/src/basic/missing_loop.h b/src/basic/missing_loop.h deleted file mode 100644 index 56e46f0b8a..0000000000 --- a/src/basic/missing_loop.h +++ /dev/null @@ -1,39 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#include - -#include "macro.h" - -#ifndef LOOP_CONFIGURE -struct loop_config { - __u32 fd; - __u32 block_size; - struct loop_info64 info; - __u64 __reserved[8]; -}; - -# define LOOP_CONFIGURE 0x4C0A -#else -assert_cc(LOOP_CONFIGURE == 0x4C0A); -#endif - -#ifndef LO_FLAGS_DIRECT_IO -# define LO_FLAGS_DIRECT_IO 16 -# define LOOP_SET_DIRECT_IO 0x4C08 -#else -assert_cc(LO_FLAGS_DIRECT_IO == 16); -assert_cc(LOOP_SET_DIRECT_IO == 0x4C08); -#endif - -#ifndef LOOP_SET_BLOCK_SIZE -# define LOOP_SET_BLOCK_SIZE 0x4C09 -#else -assert_cc(LOOP_SET_BLOCK_SIZE == 0x4C09); -#endif - -#ifndef LOOP_SET_STATUS_SETTABLE_FLAGS -# define LOOP_SET_STATUS_SETTABLE_FLAGS (LO_FLAGS_AUTOCLEAR | LO_FLAGS_PARTSCAN) -#else -assert_cc(LOOP_SET_STATUS_SETTABLE_FLAGS == (LO_FLAGS_AUTOCLEAR | LO_FLAGS_PARTSCAN)); -#endif diff --git a/src/mountfsd/mountwork.c b/src/mountfsd/mountwork.c index 2fd610f5d6..96cea432ad 100644 --- a/src/mountfsd/mountwork.c +++ b/src/mountfsd/mountwork.c @@ -4,6 +4,7 @@ #if WANT_LINUX_FS_H #include #endif +#include #include "sd-daemon.h" #include "sd-varlink.h" @@ -19,7 +20,6 @@ #include "io-util.h" #include "json-util.h" #include "main-func.h" -#include "missing_loop.h" #include "missing_mount.h" #include "missing_syscall.h" #include "namespace-util.h" diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index 9c105a6d13..3eba8dcb07 100644 --- a/src/shared/loop-util.c +++ b/src/shared/loop-util.c @@ -27,7 +27,6 @@ #include "fs-util.h" #include "fileio.h" #include "loop-util.h" -#include "missing_loop.h" #include "parse-util.h" #include "path-util.h" #include "random-util.h" diff --git a/src/test/test-loop-block.c b/src/test/test-loop-block.c index 921049c3fb..c18582795b 100644 --- a/src/test/test-loop-block.c +++ b/src/test/test-loop-block.c @@ -15,7 +15,6 @@ #include "fs-util.h" #include "gpt.h" #include "main-func.h" -#include "missing_loop.h" #include "mkfs-util.h" #include "mount-util.h" #include "namespace-util.h" From b4ea2e7249d1c3d2c54adeec86c86379a3cded6c Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 03:50:46 +0900 Subject: [PATCH 24/36] missing_namespace: drop unnecessary entries Our kernel baseline is 5.4. --- src/basic/missing_namespace.h | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/basic/missing_namespace.h b/src/basic/missing_namespace.h index 1c7285151e..b659a8edc3 100644 --- a/src/basic/missing_namespace.h +++ b/src/basic/missing_namespace.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include #include /* Root namespace inode numbers, as per include/linux/proc_ns.h in the kernel source tree, since v3.8: @@ -12,16 +13,3 @@ #define PROC_PID_INIT_INO ((ino_t) UINT32_C(0xEFFFFFFC)) #define PROC_CGROUP_INIT_INO ((ino_t) UINT32_C(0xEFFFFFFB)) #define PROC_TIME_INIT_INO ((ino_t) UINT32_C(0xEFFFFFFA)) - -/* linux/nsfs.h */ -#ifndef NS_GET_USERNS /* 6786741dbf99e44fb0c0ed85a37582b8a26f1c3b (4.9) */ -#define NS_GET_USERNS _IO(0xb7, 0x1) -#endif - -#ifndef NS_GET_NSTYPE /* e5ff5ce6e20ee22511398bb31fb912466cf82a36 (4.11) */ -#define NS_GET_NSTYPE _IO(0xb7, 0x3) -#endif - -#ifndef NS_GET_OWNER_UID /* d95fa3c76a66b6d76b1e109ea505c55e66360f3c (4.11) */ -#define NS_GET_OWNER_UID _IO(0xb7, 0x4) -#endif From 6e338c25d81b4f85189f1d96950f5eb1c44005e4 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 03:55:14 +0900 Subject: [PATCH 25/36] missing_network: drop unnecessary definitions They are already defined in glibc-2.31. --- src/basic/missing_network.h | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/basic/missing_network.h b/src/basic/missing_network.h index ded1bc2f5e..86ea978d4a 100644 --- a/src/basic/missing_network.h +++ b/src/basic/missing_network.h @@ -3,17 +3,7 @@ #include -/* linux/in6.h or netinet/in.h */ -#ifndef IPV6_UNICAST_IF -#define IPV6_UNICAST_IF 76 -#endif - -/* linux/in6.h or netinet/in.h */ -#ifndef IPV6_TRANSPARENT -#define IPV6_TRANSPARENT 75 -#endif - -/* linux/in.h or netinet/in.h */ +/* linux/in.h or netinet/in.h (since glibc-2.32) */ #ifndef IPPROTO_MPTCP #define IPPROTO_MPTCP 262 #endif From 8e091ec420d5928cc405be9be1b458e2f95bc273 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 04:01:07 +0900 Subject: [PATCH 26/36] basic/linux: import prctl.h from linux 6.14-rc4 --- src/basic/capability-util.c | 2 +- src/basic/linux/prctl.h | 356 ++++++++++++++++++++++++++++++++++++ src/basic/missing_prctl.h | 35 ---- src/core/exec-invoke.c | 2 +- src/core/execute.c | 2 +- src/test/test-capability.c | 2 +- src/test/test-execute.c | 2 +- 7 files changed, 361 insertions(+), 40 deletions(-) create mode 100644 src/basic/linux/prctl.h delete mode 100644 src/basic/missing_prctl.h diff --git a/src/basic/capability-util.c b/src/basic/capability-util.c index ccdb31fe4c..941412d3c5 100644 --- a/src/basic/capability-util.c +++ b/src/basic/capability-util.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include #include #include #include @@ -16,7 +17,6 @@ #include "log.h" #include "logarithm.h" #include "macro.h" -#include "missing_prctl.h" #include "missing_threads.h" #include "parse-util.h" #include "pidref.h" diff --git a/src/basic/linux/prctl.h b/src/basic/linux/prctl.h new file mode 100644 index 0000000000..5c6080680c --- /dev/null +++ b/src/basic/linux/prctl.h @@ -0,0 +1,356 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _LINUX_PRCTL_H +#define _LINUX_PRCTL_H + +#include + +/* Values to pass as first argument to prctl() */ + +#define PR_SET_PDEATHSIG 1 /* Second arg is a signal */ +#define PR_GET_PDEATHSIG 2 /* Second arg is a ptr to return the signal */ + +/* Get/set current->mm->dumpable */ +#define PR_GET_DUMPABLE 3 +#define PR_SET_DUMPABLE 4 + +/* Get/set unaligned access control bits (if meaningful) */ +#define PR_GET_UNALIGN 5 +#define PR_SET_UNALIGN 6 +# define PR_UNALIGN_NOPRINT 1 /* silently fix up unaligned user accesses */ +# define PR_UNALIGN_SIGBUS 2 /* generate SIGBUS on unaligned user access */ + +/* Get/set whether or not to drop capabilities on setuid() away from + * uid 0 (as per security/commoncap.c) */ +#define PR_GET_KEEPCAPS 7 +#define PR_SET_KEEPCAPS 8 + +/* Get/set floating-point emulation control bits (if meaningful) */ +#define PR_GET_FPEMU 9 +#define PR_SET_FPEMU 10 +# define PR_FPEMU_NOPRINT 1 /* silently emulate fp operations accesses */ +# define PR_FPEMU_SIGFPE 2 /* don't emulate fp operations, send SIGFPE instead */ + +/* Get/set floating-point exception mode (if meaningful) */ +#define PR_GET_FPEXC 11 +#define PR_SET_FPEXC 12 +# define PR_FP_EXC_SW_ENABLE 0x80 /* Use FPEXC for FP exception enables */ +# define PR_FP_EXC_DIV 0x010000 /* floating point divide by zero */ +# define PR_FP_EXC_OVF 0x020000 /* floating point overflow */ +# define PR_FP_EXC_UND 0x040000 /* floating point underflow */ +# define PR_FP_EXC_RES 0x080000 /* floating point inexact result */ +# define PR_FP_EXC_INV 0x100000 /* floating point invalid operation */ +# define PR_FP_EXC_DISABLED 0 /* FP exceptions disabled */ +# define PR_FP_EXC_NONRECOV 1 /* async non-recoverable exc. mode */ +# define PR_FP_EXC_ASYNC 2 /* async recoverable exception mode */ +# define PR_FP_EXC_PRECISE 3 /* precise exception mode */ + +/* Get/set whether we use statistical process timing or accurate timestamp + * based process timing */ +#define PR_GET_TIMING 13 +#define PR_SET_TIMING 14 +# define PR_TIMING_STATISTICAL 0 /* Normal, traditional, + statistical process timing */ +# define PR_TIMING_TIMESTAMP 1 /* Accurate timestamp based + process timing */ + +#define PR_SET_NAME 15 /* Set process name */ +#define PR_GET_NAME 16 /* Get process name */ + +/* Get/set process endian */ +#define PR_GET_ENDIAN 19 +#define PR_SET_ENDIAN 20 +# define PR_ENDIAN_BIG 0 +# define PR_ENDIAN_LITTLE 1 /* True little endian mode */ +# define PR_ENDIAN_PPC_LITTLE 2 /* "PowerPC" pseudo little endian */ + +/* Get/set process seccomp mode */ +#define PR_GET_SECCOMP 21 +#define PR_SET_SECCOMP 22 + +/* Get/set the capability bounding set (as per security/commoncap.c) */ +#define PR_CAPBSET_READ 23 +#define PR_CAPBSET_DROP 24 + +/* Get/set the process' ability to use the timestamp counter instruction */ +#define PR_GET_TSC 25 +#define PR_SET_TSC 26 +# define PR_TSC_ENABLE 1 /* allow the use of the timestamp counter */ +# define PR_TSC_SIGSEGV 2 /* throw a SIGSEGV instead of reading the TSC */ + +/* Get/set securebits (as per security/commoncap.c) */ +#define PR_GET_SECUREBITS 27 +#define PR_SET_SECUREBITS 28 + +/* + * Get/set the timerslack as used by poll/select/nanosleep + * A value of 0 means "use default" + */ +#define PR_SET_TIMERSLACK 29 +#define PR_GET_TIMERSLACK 30 + +#define PR_TASK_PERF_EVENTS_DISABLE 31 +#define PR_TASK_PERF_EVENTS_ENABLE 32 + +/* + * Set early/late kill mode for hwpoison memory corruption. + * This influences when the process gets killed on a memory corruption. + */ +#define PR_MCE_KILL 33 +# define PR_MCE_KILL_CLEAR 0 +# define PR_MCE_KILL_SET 1 + +# define PR_MCE_KILL_LATE 0 +# define PR_MCE_KILL_EARLY 1 +# define PR_MCE_KILL_DEFAULT 2 + +#define PR_MCE_KILL_GET 34 + +/* + * Tune up process memory map specifics. + */ +#define PR_SET_MM 35 +# define PR_SET_MM_START_CODE 1 +# define PR_SET_MM_END_CODE 2 +# define PR_SET_MM_START_DATA 3 +# define PR_SET_MM_END_DATA 4 +# define PR_SET_MM_START_STACK 5 +# define PR_SET_MM_START_BRK 6 +# define PR_SET_MM_BRK 7 +# define PR_SET_MM_ARG_START 8 +# define PR_SET_MM_ARG_END 9 +# define PR_SET_MM_ENV_START 10 +# define PR_SET_MM_ENV_END 11 +# define PR_SET_MM_AUXV 12 +# define PR_SET_MM_EXE_FILE 13 +# define PR_SET_MM_MAP 14 +# define PR_SET_MM_MAP_SIZE 15 + +/* + * This structure provides new memory descriptor + * map which mostly modifies /proc/pid/stat[m] + * output for a task. This mostly done in a + * sake of checkpoint/restore functionality. + */ +struct prctl_mm_map { + __u64 start_code; /* code section bounds */ + __u64 end_code; + __u64 start_data; /* data section bounds */ + __u64 end_data; + __u64 start_brk; /* heap for brk() syscall */ + __u64 brk; + __u64 start_stack; /* stack starts at */ + __u64 arg_start; /* command line arguments bounds */ + __u64 arg_end; + __u64 env_start; /* environment variables bounds */ + __u64 env_end; + __u64 *auxv; /* auxiliary vector */ + __u32 auxv_size; /* vector size */ + __u32 exe_fd; /* /proc/$pid/exe link file */ +}; + +/* + * Set specific pid that is allowed to ptrace the current task. + * A value of 0 mean "no process". + */ +#define PR_SET_PTRACER 0x59616d61 +# define PR_SET_PTRACER_ANY ((unsigned long)-1) + +#define PR_SET_CHILD_SUBREAPER 36 +#define PR_GET_CHILD_SUBREAPER 37 + +/* + * If no_new_privs is set, then operations that grant new privileges (i.e. + * execve) will either fail or not grant them. This affects suid/sgid, + * file capabilities, and LSMs. + * + * Operations that merely manipulate or drop existing privileges (setresuid, + * capset, etc.) will still work. Drop those privileges if you want them gone. + * + * Changing LSM security domain is considered a new privilege. So, for example, + * asking selinux for a specific new context (e.g. with runcon) will result + * in execve returning -EPERM. + * + * See Documentation/userspace-api/no_new_privs.rst for more details. + */ +#define PR_SET_NO_NEW_PRIVS 38 +#define PR_GET_NO_NEW_PRIVS 39 + +#define PR_GET_TID_ADDRESS 40 + +#define PR_SET_THP_DISABLE 41 +#define PR_GET_THP_DISABLE 42 + +/* + * No longer implemented, but left here to ensure the numbers stay reserved: + */ +#define PR_MPX_ENABLE_MANAGEMENT 43 +#define PR_MPX_DISABLE_MANAGEMENT 44 + +#define PR_SET_FP_MODE 45 +#define PR_GET_FP_MODE 46 +# define PR_FP_MODE_FR (1 << 0) /* 64b FP registers */ +# define PR_FP_MODE_FRE (1 << 1) /* 32b compatibility */ + +/* Control the ambient capability set */ +#define PR_CAP_AMBIENT 47 +# define PR_CAP_AMBIENT_IS_SET 1 +# define PR_CAP_AMBIENT_RAISE 2 +# define PR_CAP_AMBIENT_LOWER 3 +# define PR_CAP_AMBIENT_CLEAR_ALL 4 + +/* arm64 Scalable Vector Extension controls */ +/* Flag values must be kept in sync with ptrace NT_ARM_SVE interface */ +#define PR_SVE_SET_VL 50 /* set task vector length */ +# define PR_SVE_SET_VL_ONEXEC (1 << 18) /* defer effect until exec */ +#define PR_SVE_GET_VL 51 /* get task vector length */ +/* Bits common to PR_SVE_SET_VL and PR_SVE_GET_VL */ +# define PR_SVE_VL_LEN_MASK 0xffff +# define PR_SVE_VL_INHERIT (1 << 17) /* inherit across exec */ + +/* Per task speculation control */ +#define PR_GET_SPECULATION_CTRL 52 +#define PR_SET_SPECULATION_CTRL 53 +/* Speculation control variants */ +# define PR_SPEC_STORE_BYPASS 0 +# define PR_SPEC_INDIRECT_BRANCH 1 +# define PR_SPEC_L1D_FLUSH 2 +/* Return and control values for PR_SET/GET_SPECULATION_CTRL */ +# define PR_SPEC_NOT_AFFECTED 0 +# define PR_SPEC_PRCTL (1UL << 0) +# define PR_SPEC_ENABLE (1UL << 1) +# define PR_SPEC_DISABLE (1UL << 2) +# define PR_SPEC_FORCE_DISABLE (1UL << 3) +# define PR_SPEC_DISABLE_NOEXEC (1UL << 4) + +/* Reset arm64 pointer authentication keys */ +#define PR_PAC_RESET_KEYS 54 +# define PR_PAC_APIAKEY (1UL << 0) +# define PR_PAC_APIBKEY (1UL << 1) +# define PR_PAC_APDAKEY (1UL << 2) +# define PR_PAC_APDBKEY (1UL << 3) +# define PR_PAC_APGAKEY (1UL << 4) + +/* Tagged user address controls for arm64 and RISC-V */ +#define PR_SET_TAGGED_ADDR_CTRL 55 +#define PR_GET_TAGGED_ADDR_CTRL 56 +# define PR_TAGGED_ADDR_ENABLE (1UL << 0) +/* MTE tag check fault modes */ +# define PR_MTE_TCF_NONE 0UL +# define PR_MTE_TCF_SYNC (1UL << 1) +# define PR_MTE_TCF_ASYNC (1UL << 2) +# define PR_MTE_TCF_MASK (PR_MTE_TCF_SYNC | PR_MTE_TCF_ASYNC) +/* MTE tag inclusion mask */ +# define PR_MTE_TAG_SHIFT 3 +# define PR_MTE_TAG_MASK (0xffffUL << PR_MTE_TAG_SHIFT) +/* Unused; kept only for source compatibility */ +# define PR_MTE_TCF_SHIFT 1 +/* RISC-V pointer masking tag length */ +# define PR_PMLEN_SHIFT 24 +# define PR_PMLEN_MASK (0x7fUL << PR_PMLEN_SHIFT) + +/* Control reclaim behavior when allocating memory */ +#define PR_SET_IO_FLUSHER 57 +#define PR_GET_IO_FLUSHER 58 + +/* Dispatch syscalls to a userspace handler */ +#define PR_SET_SYSCALL_USER_DISPATCH 59 +# define PR_SYS_DISPATCH_OFF 0 +# define PR_SYS_DISPATCH_ON 1 +/* The control values for the user space selector when dispatch is enabled */ +# define SYSCALL_DISPATCH_FILTER_ALLOW 0 +# define SYSCALL_DISPATCH_FILTER_BLOCK 1 + +/* Set/get enabled arm64 pointer authentication keys */ +#define PR_PAC_SET_ENABLED_KEYS 60 +#define PR_PAC_GET_ENABLED_KEYS 61 + +/* Request the scheduler to share a core */ +#define PR_SCHED_CORE 62 +# define PR_SCHED_CORE_GET 0 +# define PR_SCHED_CORE_CREATE 1 /* create unique core_sched cookie */ +# define PR_SCHED_CORE_SHARE_TO 2 /* push core_sched cookie to pid */ +# define PR_SCHED_CORE_SHARE_FROM 3 /* pull core_sched cookie to pid */ +# define PR_SCHED_CORE_MAX 4 +# define PR_SCHED_CORE_SCOPE_THREAD 0 +# define PR_SCHED_CORE_SCOPE_THREAD_GROUP 1 +# define PR_SCHED_CORE_SCOPE_PROCESS_GROUP 2 + +/* arm64 Scalable Matrix Extension controls */ +/* Flag values must be in sync with SVE versions */ +#define PR_SME_SET_VL 63 /* set task vector length */ +# define PR_SME_SET_VL_ONEXEC (1 << 18) /* defer effect until exec */ +#define PR_SME_GET_VL 64 /* get task vector length */ +/* Bits common to PR_SME_SET_VL and PR_SME_GET_VL */ +# define PR_SME_VL_LEN_MASK 0xffff +# define PR_SME_VL_INHERIT (1 << 17) /* inherit across exec */ + +/* Memory deny write / execute */ +#define PR_SET_MDWE 65 +# define PR_MDWE_REFUSE_EXEC_GAIN (1UL << 0) +# define PR_MDWE_NO_INHERIT (1UL << 1) + +#define PR_GET_MDWE 66 + +#define PR_SET_VMA 0x53564d41 +# define PR_SET_VMA_ANON_NAME 0 + +#define PR_GET_AUXV 0x41555856 + +#define PR_SET_MEMORY_MERGE 67 +#define PR_GET_MEMORY_MERGE 68 + +#define PR_RISCV_V_SET_CONTROL 69 +#define PR_RISCV_V_GET_CONTROL 70 +# define PR_RISCV_V_VSTATE_CTRL_DEFAULT 0 +# define PR_RISCV_V_VSTATE_CTRL_OFF 1 +# define PR_RISCV_V_VSTATE_CTRL_ON 2 +# define PR_RISCV_V_VSTATE_CTRL_INHERIT (1 << 4) +# define PR_RISCV_V_VSTATE_CTRL_CUR_MASK 0x3 +# define PR_RISCV_V_VSTATE_CTRL_NEXT_MASK 0xc +# define PR_RISCV_V_VSTATE_CTRL_MASK 0x1f + +#define PR_RISCV_SET_ICACHE_FLUSH_CTX 71 +# define PR_RISCV_CTX_SW_FENCEI_ON 0 +# define PR_RISCV_CTX_SW_FENCEI_OFF 1 +# define PR_RISCV_SCOPE_PER_PROCESS 0 +# define PR_RISCV_SCOPE_PER_THREAD 1 + +/* PowerPC Dynamic Execution Control Register (DEXCR) controls */ +#define PR_PPC_GET_DEXCR 72 +#define PR_PPC_SET_DEXCR 73 +/* DEXCR aspect to act on */ +# define PR_PPC_DEXCR_SBHE 0 /* Speculative branch hint enable */ +# define PR_PPC_DEXCR_IBRTPD 1 /* Indirect branch recurrent target prediction disable */ +# define PR_PPC_DEXCR_SRAPD 2 /* Subroutine return address prediction disable */ +# define PR_PPC_DEXCR_NPHIE 3 /* Non-privileged hash instruction enable */ +/* Action to apply / return */ +# define PR_PPC_DEXCR_CTRL_EDITABLE 0x1 /* Aspect can be modified with PR_PPC_SET_DEXCR */ +# define PR_PPC_DEXCR_CTRL_SET 0x2 /* Set the aspect for this process */ +# define PR_PPC_DEXCR_CTRL_CLEAR 0x4 /* Clear the aspect for this process */ +# define PR_PPC_DEXCR_CTRL_SET_ONEXEC 0x8 /* Set the aspect on exec */ +# define PR_PPC_DEXCR_CTRL_CLEAR_ONEXEC 0x10 /* Clear the aspect on exec */ +# define PR_PPC_DEXCR_CTRL_MASK 0x1f + +/* + * Get the current shadow stack configuration for the current thread, + * this will be the value configured via PR_SET_SHADOW_STACK_STATUS. + */ +#define PR_GET_SHADOW_STACK_STATUS 74 + +/* + * Set the current shadow stack configuration. Enabling the shadow + * stack will cause a shadow stack to be allocated for the thread. + */ +#define PR_SET_SHADOW_STACK_STATUS 75 +# define PR_SHADOW_STACK_ENABLE (1UL << 0) +# define PR_SHADOW_STACK_WRITE (1UL << 1) +# define PR_SHADOW_STACK_PUSH (1UL << 2) + +/* + * Prevent further changes to the specified shadow stack + * configuration. All bits may be locked via this call, including + * undefined bits. + */ +#define PR_LOCK_SHADOW_STACK_STATUS 76 + +#endif /* _LINUX_PRCTL_H */ diff --git a/src/basic/missing_prctl.h b/src/basic/missing_prctl.h deleted file mode 100644 index 2c9f9f6c50..0000000000 --- a/src/basic/missing_prctl.h +++ /dev/null @@ -1,35 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#include - -#include "macro.h" - -/* 58319057b7847667f0c9585b9de0e8932b0fdb08 (4.3) */ -#ifndef PR_CAP_AMBIENT -#define PR_CAP_AMBIENT 47 - -#define PR_CAP_AMBIENT_IS_SET 1 -#define PR_CAP_AMBIENT_RAISE 2 -#define PR_CAP_AMBIENT_LOWER 3 -#define PR_CAP_AMBIENT_CLEAR_ALL 4 -#endif - -/* b507808ebce23561d4ff8c2aa1fb949fe402bc61 (6.3) */ -#ifndef PR_SET_MDWE -# define PR_SET_MDWE 65 -#else -assert_cc(PR_SET_MDWE == 65); -#endif - -#ifndef PR_MDWE_REFUSE_EXEC_GAIN -# define PR_MDWE_REFUSE_EXEC_GAIN 1 -#else -assert_cc(PR_MDWE_REFUSE_EXEC_GAIN == 1); -#endif - -#ifndef PR_SET_MEMORY_MERGE -# define PR_SET_MEMORY_MERGE 67 -#else -assert_cc(PR_SET_MEMORY_MERGE == 67); -#endif diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index 8d1e072d3f..1b93f498b0 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include #include #include #include @@ -41,7 +42,6 @@ #include "iovec-util.h" #include "journal-send.h" #include "memfd-util.h" -#include "missing_prctl.h" #include "missing_sched.h" #include "missing_securebits.h" #include "missing_syscall.h" diff --git a/src/core/execute.c b/src/core/execute.c index 29089e1622..2cc4d7e659 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -48,7 +49,6 @@ #include "manager-dump.h" #include "memory-util.h" #include "missing_fs.h" -#include "missing_prctl.h" #include "mkdir-label.h" #include "namespace.h" #include "osc-context.h" diff --git a/src/test/test-capability.c b/src/test/test-capability.c index 6c23c1bb28..314c92fe3c 100644 --- a/src/test/test-capability.c +++ b/src/test/test-capability.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include #include #include #include @@ -15,7 +16,6 @@ #include "fd-util.h" #include "fileio.h" #include "macro.h" -#include "missing_prctl.h" #include "parse-util.h" #include "process-util.h" #include "string-util.h" diff --git a/src/test/test-execute.c b/src/test/test-execute.c index cd1bca1b31..f2224910b0 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include #include #include #include @@ -18,7 +19,6 @@ #include "fs-util.h" #include "macro.h" #include "manager.h" -#include "missing_prctl.h" #include "mkdir.h" #include "mount-util.h" #include "path-util.h" From a7cb43d8d1b2e4f13e457d357e852dd94a649860 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 04:14:28 +0900 Subject: [PATCH 27/36] missing_resource.h: RLIMIT_RTTIME is defined since glibc-2.14 Now our baseline is glibc-2.31. --- src/basic/missing_resource.h | 15 --------------- src/basic/rlimit-util.c | 1 - src/basic/rlimit-util.h | 3 ++- src/core/execute.h | 2 +- src/libsystemd/sd-bus/test-bus-benchmark.c | 2 +- src/nspawn/nspawn-settings.h | 2 +- src/shared/user-record.h | 2 +- src/test/test-rlimit-util.c | 1 - 8 files changed, 6 insertions(+), 22 deletions(-) delete mode 100644 src/basic/missing_resource.h diff --git a/src/basic/missing_resource.h b/src/basic/missing_resource.h deleted file mode 100644 index 18076736c7..0000000000 --- a/src/basic/missing_resource.h +++ /dev/null @@ -1,15 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#include - -#include "macro.h" - -#ifndef RLIMIT_RTTIME -# define RLIMIT_RTTIME 15 -#else -assert_cc(RLIMIT_RTTIME == 15); -#endif - -/* If RLIMIT_RTTIME is not defined, then we cannot use RLIMIT_NLIMITS as is */ -#define _RLIMIT_MAX (RLIMIT_RTTIME+1 > RLIMIT_NLIMITS ? RLIMIT_RTTIME+1 : RLIMIT_NLIMITS) diff --git a/src/basic/rlimit-util.c b/src/basic/rlimit-util.c index a9f7b87f28..70c25adf46 100644 --- a/src/basic/rlimit-util.c +++ b/src/basic/rlimit-util.c @@ -9,7 +9,6 @@ #include "fileio.h" #include "format-util.h" #include "macro.h" -#include "missing_resource.h" #include "process-util.h" #include "rlimit-util.h" #include "string-table.h" diff --git a/src/basic/rlimit-util.h b/src/basic/rlimit-util.h index b5f9989487..ad48e31550 100644 --- a/src/basic/rlimit-util.h +++ b/src/basic/rlimit-util.h @@ -4,7 +4,8 @@ #include #include "macro.h" -#include "missing_resource.h" + +#define _RLIMIT_MAX RLIMIT_NLIMITS const char* rlimit_to_string(int i) _const_; int rlimit_from_string(const char *s) _pure_; diff --git a/src/core/execute.h b/src/core/execute.h index 17662e5c15..65a9b0dea1 100644 --- a/src/core/execute.h +++ b/src/core/execute.h @@ -22,13 +22,13 @@ typedef struct Manager Manager; #include "exec-util.h" #include "fdset.h" #include "list.h" -#include "missing_resource.h" #include "namespace.h" #include "nsflags.h" #include "numa-util.h" #include "open-file.h" #include "ordered-set.h" #include "path-util.h" +#include "rlimit-util.h" #include "runtime-scope.h" #include "set.h" #include "time-util.h" diff --git a/src/libsystemd/sd-bus/test-bus-benchmark.c b/src/libsystemd/sd-bus/test-bus-benchmark.c index d988588de0..78ae564aeb 100644 --- a/src/libsystemd/sd-bus/test-bus-benchmark.c +++ b/src/libsystemd/sd-bus/test-bus-benchmark.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include #include #include @@ -10,7 +11,6 @@ #include "bus-kernel.h" #include "constants.h" #include "fd-util.h" -#include "missing_resource.h" #include "string-util.h" #include "tests.h" #include "time-util.h" diff --git a/src/nspawn/nspawn-settings.h b/src/nspawn/nspawn-settings.h index 0b30506391..e057fc123d 100644 --- a/src/nspawn/nspawn-settings.h +++ b/src/nspawn/nspawn-settings.h @@ -11,9 +11,9 @@ #include "conf-parser.h" #include "cpu-set-util.h" #include "macro.h" -#include "missing_resource.h" #include "nspawn-expose-ports.h" #include "nspawn-mount.h" +#include "rlimit-util.h" #include "seccomp-util.h" #include "time-util.h" diff --git a/src/shared/user-record.h b/src/shared/user-record.h index 8f58c5ca93..67ae68634a 100644 --- a/src/shared/user-record.h +++ b/src/shared/user-record.h @@ -8,7 +8,7 @@ #include "sd-json.h" #include "hashmap.h" -#include "missing_resource.h" +#include "rlimit-util.h" #include "strv.h" #include "time-util.h" #include "user-util.h" diff --git a/src/test/test-rlimit-util.c b/src/test/test-rlimit-util.c index fc9e89c466..55f512cf00 100644 --- a/src/test/test-rlimit-util.c +++ b/src/test/test-rlimit-util.c @@ -8,7 +8,6 @@ #include "alloc-util.h" #include "capability-util.h" #include "macro.h" -#include "missing_resource.h" #include "process-util.h" #include "rlimit-util.h" #include "string-util.h" From 2c2d832eb0943146c81e5c5b0d399d3c60b9068b Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 04:37:01 +0900 Subject: [PATCH 28/36] missing_securebits: remove unnecessary header Our kernel baseline is 5.4, hence all entries in the headers are defined in linux/securebits.h. --- src/basic/missing_securebits.h | 18 ------------------ src/core/exec-invoke.c | 2 +- src/shared/securebits-util.h | 2 +- 3 files changed, 2 insertions(+), 20 deletions(-) delete mode 100644 src/basic/missing_securebits.h diff --git a/src/basic/missing_securebits.h b/src/basic/missing_securebits.h deleted file mode 100644 index 03fad6f503..0000000000 --- a/src/basic/missing_securebits.h +++ /dev/null @@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#include - -/* 746bf6d64275be0c65b0631d8a72b16f1454cfa1 (4.3) */ -#ifndef SECURE_NO_CAP_AMBIENT_RAISE -#define SECURE_NO_CAP_AMBIENT_RAISE 6 -#define SECURE_NO_CAP_AMBIENT_RAISE_LOCKED 7 /* make bit-6 immutable */ -#define SECBIT_NO_CAP_AMBIENT_RAISE (issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE)) -#define SECBIT_NO_CAP_AMBIENT_RAISE_LOCKED (issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE_LOCKED)) - -#undef SECURE_ALL_BITS -#define SECURE_ALL_BITS (issecure_mask(SECURE_NOROOT) | \ - issecure_mask(SECURE_NO_SETUID_FIXUP) | \ - issecure_mask(SECURE_KEEP_CAPS) | \ - issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE)) -#endif diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index 1b93f498b0..c7d48116b9 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -43,7 +44,6 @@ #include "journal-send.h" #include "memfd-util.h" #include "missing_sched.h" -#include "missing_securebits.h" #include "missing_syscall.h" #include "mkdir-label.h" #include "osc-context.h" diff --git a/src/shared/securebits-util.h b/src/shared/securebits-util.h index caf8e6d593..a8f108e0f9 100644 --- a/src/shared/securebits-util.h +++ b/src/shared/securebits-util.h @@ -3,7 +3,7 @@ #include -#include "missing_securebits.h" +#include int secure_bits_to_string_alloc(int i, char **s); int secure_bits_from_string(const char *s); From 75b101718c5d6ff4127b7ea2a7ebc40e6b10929e Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 04:47:31 +0900 Subject: [PATCH 29/36] missing_socket: drop unnecessary definitions All removed definitions are in glibc-2.31 --- src/basic/missing_socket.h | 45 +++++--------------------------------- 1 file changed, 5 insertions(+), 40 deletions(-) diff --git a/src/basic/missing_socket.h b/src/basic/missing_socket.h index 8460ce13bf..3dbe735f64 100644 --- a/src/basic/missing_socket.h +++ b/src/basic/missing_socket.h @@ -3,14 +3,6 @@ #include -#ifndef AF_VSOCK -#define AF_VSOCK 40 -#endif - -#ifndef SO_REUSEPORT -#define SO_REUSEPORT 15 -#endif - #ifndef SO_PEERGROUPS #define SO_PEERGROUPS 59 #endif @@ -27,51 +19,24 @@ #define SO_BINDTOIFINDEX 62 #endif -#ifndef SOL_NETLINK -#define SOL_NETLINK 270 -#endif - -#ifndef SOL_ALG -#define SOL_ALG 279 -#endif - /* Not exposed yet. Defined in include/linux/socket.h. */ #ifndef SOL_SCTP #define SOL_SCTP 132 #endif +/* since glibc-2.39 */ #ifndef SCM_SECURITY #define SCM_SECURITY 0x03 #endif +/* since glibc-2.39 */ #ifndef SCM_PIDFD #define SCM_PIDFD 0x04 #endif -/* netinet/in.h */ -#ifndef IP_FREEBIND -#define IP_FREEBIND 15 -#endif - -#ifndef IP_TRANSPARENT -#define IP_TRANSPARENT 19 -#endif - -#ifndef IPV6_FREEBIND -#define IPV6_FREEBIND 78 -#endif - -#ifndef IP_RECVFRAGSIZE -#define IP_RECVFRAGSIZE 25 -#endif - -#ifndef IPV6_RECVFRAGSIZE -#define IPV6_RECVFRAGSIZE 77 -#endif - -/* The maximum number of fds that SCM_RIGHTS accepts. This is an internal kernel constant, but very much - * useful for userspace too. It's documented in unix(7) these days, hence should be fairly reliable to define - * here. */ +/* The maximum number of fds that SCM_RIGHTS accepts. This is an internal kernel constant defined in + * include/net/scm.h, but very much useful for userspace too. It's documented in unix(7) these days, hence + * should be fairly reliable to define here. */ #ifndef SCM_MAX_FD #define SCM_MAX_FD 253U #endif From e75372958d0c7139338dafcd72d94a91eb614e9c Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 04:57:49 +0900 Subject: [PATCH 30/36] missing_threads.h: threads.h exists since glibc-2.28 --- src/basic/capability-util.c | 2 +- src/basic/cgroup-util.c | 2 +- src/basic/confidential-virt.c | 2 +- src/basic/log.c | 2 +- src/basic/memory-util.c | 2 +- src/basic/missing_threads.h | 13 ------------- src/basic/pidfd-util.c | 2 +- src/basic/process-util.c | 2 +- src/basic/psi-util.c | 2 +- src/basic/random-util.c | 2 +- src/basic/signal-util.c | 2 +- src/basic/time-util.c | 2 +- src/basic/uid-classification.c | 3 ++- src/basic/virt.c | 2 +- src/basic/xattr-util.c | 2 +- src/libsystemd/sd-bus/sd-bus.c | 2 +- src/libsystemd/sd-event/sd-event.c | 2 +- src/libsystemd/sd-id128/sd-id128.c | 2 +- src/libsystemd/sd-journal/journal-file.c | 2 +- src/libsystemd/sd-resolve/sd-resolve.c | 2 +- src/login/logind-inhibit.c | 2 +- src/network/networkd-route-util.c | 2 +- src/nss-systemd/nss-systemd.c | 2 +- src/shared/cgroup-setup.c | 2 +- 24 files changed, 24 insertions(+), 36 deletions(-) delete mode 100644 src/basic/missing_threads.h diff --git a/src/basic/capability-util.c b/src/basic/capability-util.c index 941412d3c5..11d7e95cb6 100644 --- a/src/basic/capability-util.c +++ b/src/basic/capability-util.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "alloc-util.h" @@ -17,7 +18,6 @@ #include "log.h" #include "logarithm.h" #include "macro.h" -#include "missing_threads.h" #include "parse-util.h" #include "pidref.h" #include "stat-util.h" diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index a5b9829f94..5cedd45f3d 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "alloc-util.h" @@ -24,7 +25,6 @@ #include "macro.h" #include "missing_fs.h" #include "missing_magic.h" -#include "missing_threads.h" #include "mkdir.h" #include "parse-util.h" #include "path-util.h" diff --git a/src/basic/confidential-virt.c b/src/basic/confidential-virt.c index 796ae6143c..ebb50e311d 100644 --- a/src/basic/confidential-virt.c +++ b/src/basic/confidential-virt.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "confidential-virt-fundamental.h" @@ -13,7 +14,6 @@ #include "errno-util.h" #include "fd-util.h" #include "fileio.h" -#include "missing_threads.h" #include "string-table.h" #include "utf8.h" diff --git a/src/basic/log.c b/src/basic/log.c index 2250dfe927..51f3a4eead 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "sd-messages.h" @@ -26,7 +27,6 @@ #include "log.h" #include "macro.h" #include "missing_syscall.h" -#include "missing_threads.h" #include "parse-util.h" #include "proc-cmdline.h" #include "process-util.h" diff --git a/src/basic/memory-util.c b/src/basic/memory-util.c index 46ff4074a4..1596727e58 100644 --- a/src/basic/memory-util.c +++ b/src/basic/memory-util.c @@ -1,9 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include #include #include "memory-util.h" -#include "missing_threads.h" size_t page_size(void) { static thread_local size_t pgsz = 0; diff --git a/src/basic/missing_threads.h b/src/basic/missing_threads.h deleted file mode 100644 index c7da1dbd5e..0000000000 --- a/src/basic/missing_threads.h +++ /dev/null @@ -1,13 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -/* If threads.h doesn't exist, then define our own thread_local to match C11's thread_local. */ -#if HAVE_THREADS_H -# include -#elif !(defined(thread_local)) -# ifndef __STDC_NO_THREADS__ -# define thread_local _Thread_local -# else -# define thread_local __thread -# endif -#endif diff --git a/src/basic/pidfd-util.c b/src/basic/pidfd-util.c index 82064e162a..9eeb379682 100644 --- a/src/basic/pidfd-util.c +++ b/src/basic/pidfd-util.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include #include #include "errno-util.h" @@ -10,7 +11,6 @@ #include "memory-util.h" #include "missing_fs.h" #include "missing_magic.h" -#include "missing_threads.h" #include "mountpoint-util.h" #include "parse-util.h" #include "path-util.h" diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 2779f3a234..80eeca6c0a 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #if HAVE_VALGRIND_VALGRIND_H #include @@ -43,7 +44,6 @@ #include "memory-util.h" #include "missing_sched.h" #include "missing_syscall.h" -#include "missing_threads.h" #include "mountpoint-util.h" #include "namespace-util.h" #include "nulstr-util.h" diff --git a/src/basic/psi-util.c b/src/basic/psi-util.c index 2a43b03d97..9ac25e7bff 100644 --- a/src/basic/psi-util.c +++ b/src/basic/psi-util.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include #include #include "alloc-util.h" @@ -8,7 +9,6 @@ #include "extract-word.h" #include "fd-util.h" #include "fileio.h" -#include "missing_threads.h" #include "parse-util.h" #include "psi-util.h" #include "string-util.h" diff --git a/src/basic/random-util.c b/src/basic/random-util.c index fec4f81035..dbabf80383 100644 --- a/src/basic/random-util.c +++ b/src/basic/random-util.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "alloc-util.h" #include "env-util.h" @@ -21,7 +22,6 @@ #include "iovec-util.h" #include "missing_random.h" #include "missing_syscall.h" -#include "missing_threads.h" #include "parse-util.h" #include "pidfd-util.h" #include "process-util.h" diff --git a/src/basic/signal-util.c b/src/basic/signal-util.c index 32d37e68dd..7abee0d29f 100644 --- a/src/basic/signal-util.c +++ b/src/basic/signal-util.c @@ -2,11 +2,11 @@ #include #include +#include #include "errno-util.h" #include "macro.h" #include "missing_syscall.h" -#include "missing_threads.h" #include "parse-util.h" #include "signal-util.h" #include "stdio-util.h" diff --git a/src/basic/time-util.c b/src/basic/time-util.c index 77f354fd1f..2f5f14a67f 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "alloc-util.h" @@ -17,7 +18,6 @@ #include "io-util.h" #include "log.h" #include "macro.h" -#include "missing_threads.h" #include "missing_timerfd.h" #include "parse-util.h" #include "path-util.h" diff --git a/src/basic/uid-classification.c b/src/basic/uid-classification.c index 88be896ff4..90b51ab02b 100644 --- a/src/basic/uid-classification.c +++ b/src/basic/uid-classification.c @@ -1,9 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include + #include "chase.h" #include "fd-util.h" #include "fileio.h" -#include "missing_threads.h" #include "string-util.h" #include "uid-classification.h" #include "user-util.h" diff --git a/src/basic/virt.c b/src/basic/virt.c index 0d6fcaee56..905a37e4a9 100644 --- a/src/basic/virt.c +++ b/src/basic/virt.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "alloc-util.h" @@ -15,7 +16,6 @@ #include "fd-util.h" #include "fileio.h" #include "macro.h" -#include "missing_threads.h" #include "namespace-util.h" #include "process-util.h" #include "stat-util.h" diff --git a/src/basic/xattr-util.c b/src/basic/xattr-util.c index b2ff1bcb32..7ae94761f8 100644 --- a/src/basic/xattr-util.c +++ b/src/basic/xattr-util.c @@ -6,13 +6,13 @@ #include #include #include +#include #include "alloc-util.h" #include "errno-util.h" #include "fd-util.h" #include "macro.h" #include "missing_syscall.h" -#include "missing_threads.h" #include "parse-util.h" #include "sparse-endian.h" #include "stat-util.h" diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index c14d144753..20e6528481 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "sd-bus.h" @@ -38,7 +39,6 @@ #include "macro.h" #include "memory-util.h" #include "missing_syscall.h" -#include "missing_threads.h" #include "origin-id.h" #include "parse-util.h" #include "path-util.h" diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 73b0ee6ef8..ab977153fd 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "sd-daemon.h" #include "sd-event.h" @@ -24,7 +25,6 @@ #include "memory-util.h" #include "missing_magic.h" #include "missing_syscall.h" -#include "missing_threads.h" #include "missing_wait.h" #include "origin-id.h" #include "path-util.h" diff --git a/src/libsystemd/sd-id128/sd-id128.c b/src/libsystemd/sd-id128/sd-id128.c index 5028e56bbd..c407b1c8c3 100644 --- a/src/libsystemd/sd-id128/sd-id128.c +++ b/src/libsystemd/sd-id128/sd-id128.c @@ -2,6 +2,7 @@ #include #include +#include #include #include "sd-id128.h" @@ -16,7 +17,6 @@ #include "keyring-util.h" #include "macro.h" #include "missing_syscall.h" -#include "missing_threads.h" #include "path-util.h" #include "random-util.h" #include "stat-util.h" diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index 97f65c561c..1a154d9275 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include "sd-event.h" @@ -28,7 +29,6 @@ #include "journal-internal.h" #include "lookup3.h" #include "memory-util.h" -#include "missing_threads.h" #include "path-util.h" #include "prioq.h" #include "random-util.h" diff --git a/src/libsystemd/sd-resolve/sd-resolve.c b/src/libsystemd/sd-resolve/sd-resolve.c index 2000f86e69..b01f600ba6 100644 --- a/src/libsystemd/sd-resolve/sd-resolve.c +++ b/src/libsystemd/sd-resolve/sd-resolve.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "sd-resolve.h" @@ -23,7 +24,6 @@ #include "list.h" #include "memory-util.h" #include "missing_syscall.h" -#include "missing_threads.h" #include "process-util.h" #include "resolve-private.h" #include "socket-util.h" diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index ec870d1001..c0ae173783 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "alloc-util.h" @@ -18,7 +19,6 @@ #include "io-util.h" #include "logind-dbus.h" #include "logind-inhibit.h" -#include "missing_threads.h" #include "mkdir-label.h" #include "parse-util.h" #include "path-util.h" diff --git a/src/network/networkd-route-util.c b/src/network/networkd-route-util.c index 6b9810f934..90fba7a540 100644 --- a/src/network/networkd-route-util.c +++ b/src/network/networkd-route-util.c @@ -1,11 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include #include "alloc-util.h" #include "bitfield.h" #include "logarithm.h" -#include "missing_threads.h" #include "networkd-address.h" #include "networkd-link.h" #include "networkd-manager.h" diff --git a/src/nss-systemd/nss-systemd.c b/src/nss-systemd/nss-systemd.c index 6a13b87b02..0dfafa1563 100644 --- a/src/nss-systemd/nss-systemd.c +++ b/src/nss-systemd/nss-systemd.c @@ -3,13 +3,13 @@ #include #include #include +#include #include "env-util.h" #include "errno-util.h" #include "fd-util.h" #include "log.h" #include "macro.h" -#include "missing_threads.h" #include "nss-systemd.h" #include "nss-util.h" #include "pthread-util.h" diff --git a/src/shared/cgroup-setup.c b/src/shared/cgroup-setup.c index 0153454b98..c1019f571d 100644 --- a/src/shared/cgroup-setup.c +++ b/src/shared/cgroup-setup.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include #include #include "cgroup-setup.h" @@ -8,7 +9,6 @@ #include "fd-util.h" #include "fileio.h" #include "fs-util.h" -#include "missing_threads.h" #include "mkdir.h" #include "parse-util.h" #include "path-util.h" From 003b845cb2322afe179f1886a98e622f075164de Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 05:09:58 +0900 Subject: [PATCH 31/36] missing_timerfd: TFD_TIMER_CANCEL_ON_SET is defined since glibc-2.26 --- src/basic/missing_timerfd.h | 12 ------------ src/basic/time-util.c | 1 - 2 files changed, 13 deletions(-) delete mode 100644 src/basic/missing_timerfd.h diff --git a/src/basic/missing_timerfd.h b/src/basic/missing_timerfd.h deleted file mode 100644 index a01a4eca3a..0000000000 --- a/src/basic/missing_timerfd.h +++ /dev/null @@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#include - -#include "macro.h" - -#ifndef TFD_TIMER_CANCEL_ON_SET -# define TFD_TIMER_CANCEL_ON_SET (1 << 1) -#else -assert_cc(TFD_TIMER_CANCEL_ON_SET == (1 << 1)); -#endif diff --git a/src/basic/time-util.c b/src/basic/time-util.c index 2f5f14a67f..fcbedf9e9d 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -18,7 +18,6 @@ #include "io-util.h" #include "log.h" #include "macro.h" -#include "missing_timerfd.h" #include "parse-util.h" #include "path-util.h" #include "process-util.h" From b9b006c504e3f34ca92580b243bc55bfd60c2430 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 05:13:32 +0900 Subject: [PATCH 32/36] missing_wait: add short comment about P_PIDFD --- src/basic/missing_wait.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/basic/missing_wait.h b/src/basic/missing_wait.h index 3965b5bdbf..05648779e3 100644 --- a/src/basic/missing_wait.h +++ b/src/basic/missing_wait.h @@ -5,6 +5,7 @@ #include "macro.h" +/* since glibc-2.36 */ #ifndef P_PIDFD # define P_PIDFD 3 #else From aa14f193983a7d5e368500b0c408993ded2571c0 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 05:24:48 +0900 Subject: [PATCH 33/36] basic/linux: import capability.h from kernel 6.14-rc4 --- src/analyze/analyze-security.c | 1 - src/basic/capability-util.h | 1 - src/basic/generate-cap-list.sh | 2 +- src/basic/linux/capability.h | 431 ++++++++++++++++++++++++++++ src/basic/meson.build | 3 +- src/basic/missing_capability.h | 48 ---- src/hostname/hostnamed.c | 1 - src/import/importd.c | 1 - src/libsystemd/sd-bus/bus-objects.c | 3 +- src/locale/localed.c | 1 - src/login/logind-dbus.c | 1 - src/login/logind-polkit.c | 1 - src/login/logind-seat-dbus.c | 1 - src/login/logind-session-dbus.c | 1 - src/login/logind-user-dbus.c | 1 - src/machine/image-dbus.c | 1 - src/machine/machine-dbus.c | 1 - src/machine/machined-dbus.c | 1 - src/portable/portabled-bus.c | 1 - src/portable/portabled-image-bus.c | 1 - src/resolve/resolved-bus.c | 1 - src/resolve/resolved-dnssd-bus.c | 1 - src/timedate/timedated.c | 1 - 23 files changed, 435 insertions(+), 70 deletions(-) create mode 100644 src/basic/linux/capability.h delete mode 100644 src/basic/missing_capability.h diff --git a/src/analyze/analyze-security.c b/src/analyze/analyze-security.c index 11825832de..8e18681be7 100644 --- a/src/analyze/analyze-security.c +++ b/src/analyze/analyze-security.c @@ -20,7 +20,6 @@ #include "locale-util.h" #include "macro.h" #include "manager.h" -#include "missing_capability.h" #include "missing_sched.h" #include "mkdir.h" #include "nulstr-util.h" diff --git a/src/basic/capability-util.h b/src/basic/capability-util.h index e4104c5da5..a076becdcd 100644 --- a/src/basic/capability-util.h +++ b/src/basic/capability-util.h @@ -7,7 +7,6 @@ #include #include "macro.h" -#include "missing_capability.h" #include "pidref.h" /* Special marker used when storing a capabilities mask as "unset". This would need to be updated as soon as diff --git a/src/basic/generate-cap-list.sh b/src/basic/generate-cap-list.sh index 53abdd9a72..3205390037 100755 --- a/src/basic/generate-cap-list.sh +++ b/src/basic/generate-cap-list.sh @@ -3,6 +3,6 @@ set -eu set -o pipefail -${1:?} -dM -include linux/capability.h -include "${2:?}" -include "${3:?}" - + * + * Andrew G. Morgan + * Alexander Kjeldaas + * with help from Aleph1, Roland Buresund and Andrew Main. + * + * See here for the libcap library ("POSIX draft" compliance): + * + * ftp://www.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.6/ + */ + +#ifndef _LINUX_CAPABILITY_H +#define _LINUX_CAPABILITY_H + +#include + +/* User-level do most of the mapping between kernel and user + capabilities based on the version tag given by the kernel. The + kernel might be somewhat backwards compatible, but don't bet on + it. */ + +/* Note, cap_t, is defined by POSIX (draft) to be an "opaque" pointer to + a set of three capability sets. The transposition of 3*the + following structure to such a composite is better handled in a user + library since the draft standard requires the use of malloc/free + etc.. */ + +#define _LINUX_CAPABILITY_VERSION_1 0x19980330 +#define _LINUX_CAPABILITY_U32S_1 1 + +#define _LINUX_CAPABILITY_VERSION_2 0x20071026 /* deprecated - use v3 */ +#define _LINUX_CAPABILITY_U32S_2 2 + +#define _LINUX_CAPABILITY_VERSION_3 0x20080522 +#define _LINUX_CAPABILITY_U32S_3 2 + +typedef struct __user_cap_header_struct { + __u32 version; + int pid; +} *cap_user_header_t; + +struct __user_cap_data_struct { + __u32 effective; + __u32 permitted; + __u32 inheritable; +}; +typedef struct __user_cap_data_struct *cap_user_data_t; + + +#define VFS_CAP_REVISION_MASK 0xFF000000 +#define VFS_CAP_REVISION_SHIFT 24 +#define VFS_CAP_FLAGS_MASK ~VFS_CAP_REVISION_MASK +#define VFS_CAP_FLAGS_EFFECTIVE 0x000001 + +#define VFS_CAP_REVISION_1 0x01000000 +#define VFS_CAP_U32_1 1 +#define XATTR_CAPS_SZ_1 (sizeof(__le32)*(1 + 2*VFS_CAP_U32_1)) + +#define VFS_CAP_REVISION_2 0x02000000 +#define VFS_CAP_U32_2 2 +#define XATTR_CAPS_SZ_2 (sizeof(__le32)*(1 + 2*VFS_CAP_U32_2)) + +#define VFS_CAP_REVISION_3 0x03000000 +#define VFS_CAP_U32_3 2 +#define XATTR_CAPS_SZ_3 (sizeof(__le32)*(2 + 2*VFS_CAP_U32_3)) + +#define XATTR_CAPS_SZ XATTR_CAPS_SZ_3 +#define VFS_CAP_U32 VFS_CAP_U32_3 +#define VFS_CAP_REVISION VFS_CAP_REVISION_3 + +struct vfs_cap_data { + __le32 magic_etc; /* Little endian */ + struct { + __le32 permitted; /* Little endian */ + __le32 inheritable; /* Little endian */ + } data[VFS_CAP_U32]; +}; + +/* + * same as vfs_cap_data but with a rootid at the end + */ +struct vfs_ns_cap_data { + __le32 magic_etc; + struct { + __le32 permitted; /* Little endian */ + __le32 inheritable; /* Little endian */ + } data[VFS_CAP_U32]; + __le32 rootid; +}; + + +/* + * Backwardly compatible definition for source code - trapped in a + * 32-bit world. If you find you need this, please consider using + * libcap to untrap yourself... + */ +#define _LINUX_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_1 +#define _LINUX_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_1 + + + +/** + ** POSIX-draft defined capabilities. + **/ + +/* In a system with the [_POSIX_CHOWN_RESTRICTED] option defined, this + overrides the restriction of changing file ownership and group + ownership. */ + +#define CAP_CHOWN 0 + +/* Override all DAC access, including ACL execute access if + [_POSIX_ACL] is defined. Excluding DAC access covered by + CAP_LINUX_IMMUTABLE. */ + +#define CAP_DAC_OVERRIDE 1 + +/* Overrides all DAC restrictions regarding read and search on files + and directories, including ACL restrictions if [_POSIX_ACL] is + defined. Excluding DAC access covered by CAP_LINUX_IMMUTABLE. */ + +#define CAP_DAC_READ_SEARCH 2 + +/* Overrides all restrictions about allowed operations on files, where + file owner ID must be equal to the user ID, except where CAP_FSETID + is applicable. It doesn't override MAC and DAC restrictions. */ + +#define CAP_FOWNER 3 + +/* Overrides the following restrictions that the effective user ID + shall match the file owner ID when setting the S_ISUID and S_ISGID + bits on that file; that the effective group ID (or one of the + supplementary group IDs) shall match the file owner ID when setting + the S_ISGID bit on that file; that the S_ISUID and S_ISGID bits are + cleared on successful return from chown(2) (not implemented). */ + +#define CAP_FSETID 4 + +/* Overrides the restriction that the real or effective user ID of a + process sending a signal must match the real or effective user ID + of the process receiving the signal. */ + +#define CAP_KILL 5 + +/* Allows setgid(2) manipulation */ +/* Allows setgroups(2) */ +/* Allows forged gids on socket credentials passing. */ + +#define CAP_SETGID 6 + +/* Allows set*uid(2) manipulation (including fsuid). */ +/* Allows forged pids on socket credentials passing. */ + +#define CAP_SETUID 7 + + +/** + ** Linux-specific capabilities + **/ + +/* Without VFS support for capabilities: + * Transfer any capability in your permitted set to any pid, + * remove any capability in your permitted set from any pid + * With VFS support for capabilities (neither of above, but) + * Add any capability from current's capability bounding set + * to the current process' inheritable set + * Allow taking bits out of capability bounding set + * Allow modification of the securebits for a process + */ + +#define CAP_SETPCAP 8 + +/* Allow modification of S_IMMUTABLE and S_APPEND file attributes */ + +#define CAP_LINUX_IMMUTABLE 9 + +/* Allows binding to TCP/UDP sockets below 1024 */ +/* Allows binding to ATM VCIs below 32 */ + +#define CAP_NET_BIND_SERVICE 10 + +/* Allow broadcasting, listen to multicast */ + +#define CAP_NET_BROADCAST 11 + +/* Allow interface configuration */ +/* Allow administration of IP firewall, masquerading and accounting */ +/* Allow setting debug option on sockets */ +/* Allow modification of routing tables */ +/* Allow setting arbitrary process / process group ownership on + sockets */ +/* Allow binding to any address for transparent proxying (also via NET_RAW) */ +/* Allow setting TOS (type of service) */ +/* Allow setting promiscuous mode */ +/* Allow clearing driver statistics */ +/* Allow multicasting */ +/* Allow read/write of device-specific registers */ +/* Allow activation of ATM control sockets */ + +#define CAP_NET_ADMIN 12 + +/* Allow use of RAW sockets */ +/* Allow use of PACKET sockets */ +/* Allow binding to any address for transparent proxying (also via NET_ADMIN) */ + +#define CAP_NET_RAW 13 + +/* Allow locking of shared memory segments */ +/* Allow mlock and mlockall (which doesn't really have anything to do + with IPC) */ + +#define CAP_IPC_LOCK 14 + +/* Override IPC ownership checks */ + +#define CAP_IPC_OWNER 15 + +/* Insert and remove kernel modules - modify kernel without limit */ +#define CAP_SYS_MODULE 16 + +/* Allow ioperm/iopl access */ +/* Allow sending USB messages to any device via /dev/bus/usb */ + +#define CAP_SYS_RAWIO 17 + +/* Allow use of chroot() */ + +#define CAP_SYS_CHROOT 18 + +/* Allow ptrace() of any process */ + +#define CAP_SYS_PTRACE 19 + +/* Allow configuration of process accounting */ + +#define CAP_SYS_PACCT 20 + +/* Allow configuration of the secure attention key */ +/* Allow administration of the random device */ +/* Allow examination and configuration of disk quotas */ +/* Allow setting the domainname */ +/* Allow setting the hostname */ +/* Allow mount() and umount(), setting up new smb connection */ +/* Allow some autofs root ioctls */ +/* Allow nfsservctl */ +/* Allow VM86_REQUEST_IRQ */ +/* Allow to read/write pci config on alpha */ +/* Allow irix_prctl on mips (setstacksize) */ +/* Allow flushing all cache on m68k (sys_cacheflush) */ +/* Allow removing semaphores */ +/* Used instead of CAP_CHOWN to "chown" IPC message queues, semaphores + and shared memory */ +/* Allow locking/unlocking of shared memory segment */ +/* Allow turning swap on/off */ +/* Allow forged pids on socket credentials passing */ +/* Allow setting readahead and flushing buffers on block devices */ +/* Allow setting geometry in floppy driver */ +/* Allow turning DMA on/off in xd driver */ +/* Allow administration of md devices (mostly the above, but some + extra ioctls) */ +/* Allow tuning the ide driver */ +/* Allow access to the nvram device */ +/* Allow administration of apm_bios, serial and bttv (TV) device */ +/* Allow manufacturer commands in isdn CAPI support driver */ +/* Allow reading non-standardized portions of pci configuration space */ +/* Allow DDI debug ioctl on sbpcd driver */ +/* Allow setting up serial ports */ +/* Allow sending raw qic-117 commands */ +/* Allow enabling/disabling tagged queuing on SCSI controllers and sending + arbitrary SCSI commands */ +/* Allow setting encryption key on loopback filesystem */ +/* Allow setting zone reclaim policy */ +/* Allow everything under CAP_BPF and CAP_PERFMON for backward compatibility */ + +#define CAP_SYS_ADMIN 21 + +/* Allow use of reboot() */ + +#define CAP_SYS_BOOT 22 + +/* Allow raising priority and setting priority on other (different + UID) processes */ +/* Allow use of FIFO and round-robin (realtime) scheduling on own + processes and setting the scheduling algorithm used by another + process. */ +/* Allow setting cpu affinity on other processes */ +/* Allow setting realtime ioprio class */ +/* Allow setting ioprio class on other processes */ + +#define CAP_SYS_NICE 23 + +/* Override resource limits. Set resource limits. */ +/* Override quota limits. */ +/* Override reserved space on ext2 filesystem */ +/* Modify data journaling mode on ext3 filesystem (uses journaling + resources) */ +/* NOTE: ext2 honors fsuid when checking for resource overrides, so + you can override using fsuid too */ +/* Override size restrictions on IPC message queues */ +/* Allow more than 64hz interrupts from the real-time clock */ +/* Override max number of consoles on console allocation */ +/* Override max number of keymaps */ +/* Control memory reclaim behavior */ + +#define CAP_SYS_RESOURCE 24 + +/* Allow manipulation of system clock */ +/* Allow irix_stime on mips */ +/* Allow setting the real-time clock */ + +#define CAP_SYS_TIME 25 + +/* Allow configuration of tty devices */ +/* Allow vhangup() of tty */ + +#define CAP_SYS_TTY_CONFIG 26 + +/* Allow the privileged aspects of mknod() */ + +#define CAP_MKNOD 27 + +/* Allow taking of leases on files */ + +#define CAP_LEASE 28 + +/* Allow writing the audit log via unicast netlink socket */ + +#define CAP_AUDIT_WRITE 29 + +/* Allow configuration of audit via unicast netlink socket */ + +#define CAP_AUDIT_CONTROL 30 + +/* Set or remove capabilities on files. + Map uid=0 into a child user namespace. */ + +#define CAP_SETFCAP 31 + +/* Override MAC access. + The base kernel enforces no MAC policy. + An LSM may enforce a MAC policy, and if it does and it chooses + to implement capability based overrides of that policy, this is + the capability it should use to do so. */ + +#define CAP_MAC_OVERRIDE 32 + +/* Allow MAC configuration or state changes. + The base kernel requires no MAC configuration. + An LSM may enforce a MAC policy, and if it does and it chooses + to implement capability based checks on modifications to that + policy or the data required to maintain it, this is the + capability it should use to do so. */ + +#define CAP_MAC_ADMIN 33 + +/* Allow configuring the kernel's syslog (printk behaviour) */ + +#define CAP_SYSLOG 34 + +/* Allow triggering something that will wake the system */ + +#define CAP_WAKE_ALARM 35 + +/* Allow preventing system suspends */ + +#define CAP_BLOCK_SUSPEND 36 + +/* Allow reading the audit log via multicast netlink socket */ + +#define CAP_AUDIT_READ 37 + +/* + * Allow system performance and observability privileged operations + * using perf_events, i915_perf and other kernel subsystems + */ + +#define CAP_PERFMON 38 + +/* + * CAP_BPF allows the following BPF operations: + * - Creating all types of BPF maps + * - Advanced verifier features + * - Indirect variable access + * - Bounded loops + * - BPF to BPF function calls + * - Scalar precision tracking + * - Larger complexity limits + * - Dead code elimination + * - And potentially other features + * - Loading BPF Type Format (BTF) data + * - Retrieve xlated and JITed code of BPF programs + * - Use bpf_spin_lock() helper + * + * CAP_PERFMON relaxes the verifier checks further: + * - BPF progs can use of pointer-to-integer conversions + * - speculation attack hardening measures are bypassed + * - bpf_probe_read to read arbitrary kernel memory is allowed + * - bpf_trace_printk to print kernel memory is allowed + * + * CAP_SYS_ADMIN is required to use bpf_probe_write_user. + * + * CAP_SYS_ADMIN is required to iterate system wide loaded + * programs, maps, links, BTFs and convert their IDs to file descriptors. + * + * CAP_PERFMON and CAP_BPF are required to load tracing programs. + * CAP_NET_ADMIN and CAP_BPF are required to load networking programs. + */ +#define CAP_BPF 39 + + +/* Allow checkpoint/restore related operations */ +/* Allow PID selection during clone3() */ +/* Allow writing to ns_last_pid */ + +#define CAP_CHECKPOINT_RESTORE 40 + +#define CAP_LAST_CAP CAP_CHECKPOINT_RESTORE + +#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP) + +/* + * Bit location of each capability (used by user-space library and kernel) + */ + +#define CAP_TO_INDEX(x) ((x) >> 5) /* 1 << 5 == bits in __u32 */ +#define CAP_TO_MASK(x) (1U << ((x) & 31)) /* mask for indexed __u32 */ + + +#endif /* _LINUX_CAPABILITY_H */ diff --git a/src/basic/meson.build b/src/basic/meson.build index 147040a193..2372cf4d8d 100644 --- a/src/basic/meson.build +++ b/src/basic/meson.build @@ -114,7 +114,6 @@ basic_sources = files( ) missing_audit_h = files('missing_audit.h') -missing_capability_h = files('missing_capability.h') missing_socket_h = files('missing_socket.h') missing_syscall_def_h = files('missing_syscall_def.h') @@ -138,7 +137,7 @@ generate_cap_list = find_program('generate-cap-list.sh') cap_list_txt = custom_target( 'cap-list.txt', output : 'cap-list.txt', - command : [generate_cap_list, cpp, config_h, missing_capability_h], + command : [generate_cap_list, cpp, files('linux/capability.h')], capture : true) generate_errno_list = find_program('generate-errno-list.sh') diff --git a/src/basic/missing_capability.h b/src/basic/missing_capability.h deleted file mode 100644 index c1c63a6829..0000000000 --- a/src/basic/missing_capability.h +++ /dev/null @@ -1,48 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#include - -/* 3a101b8de0d39403b2c7e5c23fd0b005668acf48 (3.16) */ -#ifndef CAP_AUDIT_READ -# define CAP_AUDIT_READ 37 -#else -assert_cc(CAP_AUDIT_READ == 37); -#endif - -/* 980737282232b752bb14dab96d77665c15889c36 (5.8) */ -#ifndef CAP_PERFMON -# define CAP_PERFMON 38 -#else -assert_cc(CAP_PERFMON == 38); -#endif - -/* a17b53c4a4b55ec322c132b6670743612229ee9c (5.8) */ -#ifndef CAP_BPF -# define CAP_BPF 39 -#else -assert_cc(CAP_BPF == 39); -#endif - -/* 124ea650d3072b005457faed69909221c2905a1f (5.9) */ -#ifndef CAP_CHECKPOINT_RESTORE -# define CAP_CHECKPOINT_RESTORE 40 -#else -assert_cc(CAP_CHECKPOINT_RESTORE == 40); -#endif - -#define SYSTEMD_CAP_LAST_CAP CAP_CHECKPOINT_RESTORE - -#ifdef CAP_LAST_CAP -# if CAP_LAST_CAP > SYSTEMD_CAP_LAST_CAP -# if BUILD_MODE_DEVELOPER && defined(TEST_CAPABILITY_C) -# warning "The capability list here is outdated" -# endif -# else -# undef CAP_LAST_CAP -# endif -#endif - -#ifndef CAP_LAST_CAP -# define CAP_LAST_CAP SYSTEMD_CAP_LAST_CAP -#endif diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 6f242776a0..ec30f774e8 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -27,7 +27,6 @@ #include "id128-util.h" #include "json-util.h" #include "main-func.h" -#include "missing_capability.h" #include "nulstr-util.h" #include "os-util.h" #include "parse-util.h" diff --git a/src/import/importd.c b/src/import/importd.c index 21c6d969bc..34222c133e 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -26,7 +26,6 @@ #include "json-util.h" #include "machine-pool.h" #include "main-func.h" -#include "missing_capability.h" #include "mkdir-label.h" #include "notify-recv.h" #include "os-util.h" diff --git a/src/libsystemd/sd-bus/bus-objects.c b/src/libsystemd/sd-bus/bus-objects.c index 7fdb112a5c..f23774504a 100644 --- a/src/libsystemd/sd-bus/bus-objects.c +++ b/src/libsystemd/sd-bus/bus-objects.c @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include + #include "alloc-util.h" #include "bus-internal.h" #include "bus-introspect.h" @@ -8,7 +10,6 @@ #include "bus-signature.h" #include "bus-slot.h" #include "bus-type.h" -#include "missing_capability.h" #include "string-util.h" #include "strv.h" diff --git a/src/locale/localed.c b/src/locale/localed.c index 54ab210bcd..e9177d3ea1 100644 --- a/src/locale/localed.c +++ b/src/locale/localed.c @@ -20,7 +20,6 @@ #include "localed-util.h" #include "macro.h" #include "main-func.h" -#include "missing_capability.h" #include "path-util.h" #include "selinux-util.h" #include "service-util.h" diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 5d3e2e01b5..984e60b4b4 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -39,7 +39,6 @@ #include "logind-session-dbus.h" #include "logind-user-dbus.h" #include "logind.h" -#include "missing_capability.h" #include "mkdir-label.h" #include "parse-util.h" #include "path-util.h" diff --git a/src/login/logind-polkit.c b/src/login/logind-polkit.c index 2f1523ae04..5b6c256a08 100644 --- a/src/login/logind-polkit.c +++ b/src/login/logind-polkit.c @@ -2,7 +2,6 @@ #include "bus-polkit.h" #include "logind-polkit.h" -#include "missing_capability.h" #include "user-util.h" int check_polkit_chvt(sd_bus_message *message, Manager *manager, sd_bus_error *error) { diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c index 380990c05d..18acbf25b4 100644 --- a/src/login/logind-seat-dbus.c +++ b/src/login/logind-seat-dbus.c @@ -14,7 +14,6 @@ #include "logind-seat.h" #include "logind-session-dbus.h" #include "logind.h" -#include "missing_capability.h" #include "strv.h" #include "user-util.h" diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c index 2affc32b16..126020acf1 100644 --- a/src/login/logind-session-dbus.c +++ b/src/login/logind-session-dbus.c @@ -19,7 +19,6 @@ #include "logind-session.h" #include "logind-user-dbus.h" #include "logind.h" -#include "missing_capability.h" #include "path-util.h" #include "signal-util.h" #include "strv.h" diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c index a211953932..847b611dc4 100644 --- a/src/login/logind-user-dbus.c +++ b/src/login/logind-user-dbus.c @@ -12,7 +12,6 @@ #include "logind-user-dbus.h" #include "logind-user.h" #include "logind.h" -#include "missing_capability.h" #include "signal-util.h" #include "strv.h" #include "user-util.h" diff --git a/src/machine/image-dbus.c b/src/machine/image-dbus.c index 8f18e78c7d..0e96127a05 100644 --- a/src/machine/image-dbus.c +++ b/src/machine/image-dbus.c @@ -16,7 +16,6 @@ #include "image-dbus.h" #include "io-util.h" #include "loop-util.h" -#include "missing_capability.h" #include "mount-util.h" #include "os-util.h" #include "process-util.h" diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c index 90b4c4baea..657b9e9193 100644 --- a/src/machine/machine-dbus.c +++ b/src/machine/machine-dbus.c @@ -22,7 +22,6 @@ #include "local-addresses.h" #include "machine-dbus.h" #include "machine.h" -#include "missing_capability.h" #include "mkdir.h" #include "mount-util.h" #include "mountpoint-util.h" diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c index fd6a25375a..e1969d69d8 100644 --- a/src/machine/machined-dbus.c +++ b/src/machine/machined-dbus.c @@ -25,7 +25,6 @@ #include "machine-dbus.h" #include "machine-pool.h" #include "machined.h" -#include "missing_capability.h" #include "os-util.h" #include "path-util.h" #include "process-util.h" diff --git a/src/portable/portabled-bus.c b/src/portable/portabled-bus.c index 0476796dbe..1302e5d893 100644 --- a/src/portable/portabled-bus.c +++ b/src/portable/portabled-bus.c @@ -8,7 +8,6 @@ #include "discover-image.h" #include "fd-util.h" #include "io-util.h" -#include "missing_capability.h" #include "portable.h" #include "portabled-bus.h" #include "portabled-image-bus.h" diff --git a/src/portable/portabled-image-bus.c b/src/portable/portabled-image-bus.c index ab0e44e038..be0ea53623 100644 --- a/src/portable/portabled-image-bus.c +++ b/src/portable/portabled-image-bus.c @@ -16,7 +16,6 @@ #include "fd-util.h" #include "fileio.h" #include "io-util.h" -#include "missing_capability.h" #include "os-util.h" #include "portable.h" #include "portabled-bus.h" diff --git a/src/resolve/resolved-bus.c b/src/resolve/resolved-bus.c index d5782e4687..61975de1d2 100644 --- a/src/resolve/resolved-bus.c +++ b/src/resolve/resolved-bus.c @@ -10,7 +10,6 @@ #include "dns-domain.h" #include "format-util.h" #include "memory-util.h" -#include "missing_capability.h" #include "path-util.h" #include "resolved-bus.h" #include "resolved-def.h" diff --git a/src/resolve/resolved-dnssd-bus.c b/src/resolve/resolved-dnssd-bus.c index 4857a92b01..1843382d9b 100644 --- a/src/resolve/resolved-dnssd-bus.c +++ b/src/resolve/resolved-dnssd-bus.c @@ -2,7 +2,6 @@ #include "alloc-util.h" #include "bus-polkit.h" -#include "missing_capability.h" #include "resolved-dnssd-bus.h" #include "resolved-dnssd.h" #include "resolved-link.h" diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index 64d35d2b36..d14ff5e0e7 100644 --- a/src/timedate/timedated.c +++ b/src/timedate/timedated.c @@ -32,7 +32,6 @@ #include "list.h" #include "main-func.h" #include "memory-util.h" -#include "missing_capability.h" #include "path-util.h" #include "selinux-util.h" #include "service-util.h" From bc2bb59bddaaffa74c3cf88a6063975be0a16f9a Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 Mar 2025 05:34:23 +0900 Subject: [PATCH 34/36] missing_audit: AUDIT_NLGRP_READLOG is defined since kernel v3.16 More specifically, since 451f921639fea4600dfb9ab2889332bdcc7b48d3. Now, our kernel baseline is 5.4. Hence, we can drop the definition. --- src/basic/missing_audit.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/basic/missing_audit.h b/src/basic/missing_audit.h index 3f72acf02f..e14599ebe6 100644 --- a/src/basic/missing_audit.h +++ b/src/basic/missing_audit.h @@ -24,11 +24,3 @@ assert_cc(AUDIT_SERVICE_STOP == 1131); #else assert_cc(MAX_AUDIT_MESSAGE_LENGTH == 8970); #endif - -/* Note: we check for AUDIT_NLGRP_MAX because it's a define, but we actually - * need AUDIT_NLGRP_READLOG which is an enum. */ -#ifndef AUDIT_NLGRP_MAX -# define AUDIT_NLGRP_READLOG 1 -#else -assert_cc(AUDIT_NLGRP_READLOG == 1); -#endif From ec32732043550ec311dfb0e7be4e7f114366dd24 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 3 Mar 2025 23:26:38 +0900 Subject: [PATCH 35/36] basic: introduce our own sys/mount.h implementation To resolve conflict with sys/mount.h and linux/mount.h or linux/fs.h. The conflict between sys/mount.h and linux/mount.h is resolved in glibc-2.37 (774058d72942249f71d74e7f2b639f77184160a6), but our baseline is still glibc-2.31. Also, even with the version or newer, still sys/mount.h conflicts with linux/fs.h, which is included by linux/btrfs.h. This introduces our own implementation of sys/mount.h, that can be simultaneously included with linux/mount.h and linux/fs.h. This also imports linux/fs.h, linux/mount.h, and several other dependent headers. The introduced sys/mount.h header itself may not be enough simple, but by using the header, we can drop most of workarounds in other source files. --- meson.build | 16 +- src/basic/chattr-util.c | 1 - src/basic/chattr-util.h | 1 - src/basic/efivars.c | 2 +- src/basic/fd-util.c | 3 - src/basic/linux/btrfs.h | 2 - src/basic/linux/fs.h | 564 +++++++++++++++++++++++ src/basic/linux/fscrypt.h | 195 ++++++++ src/basic/linux/limits.h | 21 + src/basic/linux/mount.h | 227 +++++++++ src/basic/linux/update.sh | 4 - src/basic/missing_fs.h | 112 ++--- src/basic/missing_mount.h | 13 - src/basic/missing_syscall.h | 196 -------- src/basic/mountpoint-util.c | 4 - src/basic/namespace-util.c | 3 - src/basic/sys/mount.h | 115 +++++ src/core/execute.c | 2 - src/core/load-fragment.c | 2 +- src/core/namespace.c | 3 - src/coredump/coredump.c | 4 - src/growfs/growfs.c | 7 +- src/home/homed-manager.c | 2 +- src/home/homework-cifs.c | 3 - src/home/homework-fscrypt.c | 2 +- src/home/homework-mount.c | 4 - src/home/homework.h | 2 +- src/import/import-raw.c | 3 +- src/import/import-tar.c | 3 +- src/import/pull-raw.c | 2 +- src/libsystemd/sd-journal/journal-file.c | 2 +- src/mountfsd/mountwork.c | 4 - src/nspawn/nspawn.c | 3 - src/nsresourced/nsresourcework.c | 2 +- src/nsresourced/test-userns-restrict.c | 2 +- src/nsresourced/userns-restrict.c | 2 +- src/repart/repart.c | 2 +- src/shared/btrfs-util.c | 3 +- src/shared/copy.c | 1 - src/shared/discover-image.c | 2 +- src/shared/dissect-image.c | 1 - src/shared/hibernate-util.c | 2 +- src/shared/loop-util.c | 2 +- src/shared/mount-util.c | 4 - src/shared/resize-fs.c | 1 - src/test/test-mount-util.c | 1 - src/test/test-stat-util.c | 1 - src/tmpfiles/tmpfiles.c | 2 +- src/udev/udev-builtin-btrfs.c | 2 +- 49 files changed, 1183 insertions(+), 374 deletions(-) create mode 100644 src/basic/linux/fs.h create mode 100644 src/basic/linux/fscrypt.h create mode 100644 src/basic/linux/limits.h create mode 100644 src/basic/linux/mount.h delete mode 100644 src/basic/missing_mount.h create mode 100644 src/basic/sys/mount.h diff --git a/meson.build b/meson.build index f69ead2ddc..6ef51069d9 100644 --- a/meson.build +++ b/meson.build @@ -567,28 +567,13 @@ conf.set_quoted('LONG_MAX_STR', '@0@'.format(long_max)) foreach ident : [ ['struct dirent64', '''##include '''], # for musl, but only for compile time check, see dirent-util.h - ['struct mount_attr', '''#include '''], # since glibc-2.36 ['struct sched_attr', '''#include '''], # since glibc-2.41 ] # We get -1 if the size cannot be determined have = cc.sizeof(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE') > 0 - - if ident[0] == 'struct mount_attr' - if have - want_linux_fs_h = false - else - have = cc.sizeof(ident[0], - prefix : ident[1] + '\n#include ', - args : '-D_GNU_SOURCE') > 0 - want_linux_fs_h = have - endif - endif - conf.set10('HAVE_' + ident[0].underscorify().to_upper(), have) endforeach -conf.set10('WANT_LINUX_FS_H', want_linux_fs_h) - foreach ident : [ ['set_mempolicy', '''#include '''], # declared at numaif.h provided by libnuma, which we do not use ['get_mempolicy', '''#include '''], # declared at numaif.h provided by libnuma, which we do not use @@ -602,6 +587,7 @@ foreach ident : [ ['fsconfig', '''#include '''], # since glibc-2.36 ['fsmount', '''#include '''], # since glibc-2.36 ['fsopen', '''#include '''], # since glibc-2.36 + ['fspick', '''#include '''], # since glibc-2.36 ['mount_setattr', '''#include '''], # since glibc-2.36 ['move_mount', '''#include '''], # since glibc-2.36 ['open_tree', '''#include '''], # since glibc-2.36 diff --git a/src/basic/chattr-util.c b/src/basic/chattr-util.c index 39fdf970a7..2f3457daa9 100644 --- a/src/basic/chattr-util.c +++ b/src/basic/chattr-util.c @@ -4,7 +4,6 @@ #include #include #include -#include #include "bitfield.h" #include "chattr-util.h" diff --git a/src/basic/chattr-util.h b/src/basic/chattr-util.h index 1fe38e32b1..17804dc1a4 100644 --- a/src/basic/chattr-util.h +++ b/src/basic/chattr-util.h @@ -2,7 +2,6 @@ #pragma once #include -#include #include #include diff --git a/src/basic/efivars.c b/src/basic/efivars.c index bebe302184..8ae36de960 100644 --- a/src/basic/efivars.c +++ b/src/basic/efivars.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -18,6 +17,7 @@ #include "io-util.h" #include "macro.h" #include "memory-util.h" +#include "missing_fs.h" #include "stdio-util.h" #include "strv.h" #include "time-util.h" diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c index 8329c44a56..a6a63454fc 100644 --- a/src/basic/fd-util.c +++ b/src/basic/fd-util.c @@ -2,9 +2,6 @@ #include #include -#if WANT_LINUX_FS_H -#include -#endif #include #include #include diff --git a/src/basic/linux/btrfs.h b/src/basic/linux/btrfs.h index c00a5b41f4..d078ee8fcf 100644 --- a/src/basic/linux/btrfs.h +++ b/src/basic/linux/btrfs.h @@ -26,9 +26,7 @@ extern "C" { #include #include -#if WANT_LINUX_FS_H #include -#endif #define BTRFS_IOCTL_MAGIC 0x94 #define BTRFS_VOL_NAME_MAX 255 diff --git a/src/basic/linux/fs.h b/src/basic/linux/fs.h new file mode 100644 index 0000000000..be1833be4d --- /dev/null +++ b/src/basic/linux/fs.h @@ -0,0 +1,564 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _LINUX_FS_H +#define _LINUX_FS_H + +/* + * This file has definitions for some important file table structures + * and constants and structures used by various generic file system + * ioctl's. Please do not make any changes in this file before + * sending patches for review to linux-fsdevel@vger.kernel.org and + * linux-api@vger.kernel.org. + */ + +#include +#include +#include +#include + +/* Use of MS_* flags within the kernel is restricted to core mount(2) code. */ +#include + +/* + * It's silly to have NR_OPEN bigger than NR_FILE, but you can change + * the file limit at runtime and only root can increase the per-process + * nr_file rlimit, so it's safe to set up a ridiculously high absolute + * upper limit on files-per-process. + * + * Some programs (notably those using select()) may have to be + * recompiled to take full advantage of the new limits.. + */ + +/* Fixed constants first: */ +#undef NR_OPEN +#define INR_OPEN_CUR 1024 /* Initial setting for nfile rlimits */ +#define INR_OPEN_MAX 4096 /* Hard limit for nfile rlimits */ + +#define BLOCK_SIZE_BITS 10 +#define BLOCK_SIZE (1</maps ioctl */ +#define PROCMAP_QUERY _IOWR(PROCFS_IOCTL_MAGIC, 17, struct procmap_query) + +enum procmap_query_flags { + /* + * VMA permission flags. + * + * Can be used as part of procmap_query.query_flags field to look up + * only VMAs satisfying specified subset of permissions. E.g., specifying + * PROCMAP_QUERY_VMA_READABLE only will return both readable and read/write VMAs, + * while having PROCMAP_QUERY_VMA_READABLE | PROCMAP_QUERY_VMA_WRITABLE will only + * return read/write VMAs, though both executable/non-executable and + * private/shared will be ignored. + * + * PROCMAP_QUERY_VMA_* flags are also returned in procmap_query.vma_flags + * field to specify actual VMA permissions. + */ + PROCMAP_QUERY_VMA_READABLE = 0x01, + PROCMAP_QUERY_VMA_WRITABLE = 0x02, + PROCMAP_QUERY_VMA_EXECUTABLE = 0x04, + PROCMAP_QUERY_VMA_SHARED = 0x08, + /* + * Query modifier flags. + * + * By default VMA that covers provided address is returned, or -ENOENT + * is returned. With PROCMAP_QUERY_COVERING_OR_NEXT_VMA flag set, closest + * VMA with vma_start > addr will be returned if no covering VMA is + * found. + * + * PROCMAP_QUERY_FILE_BACKED_VMA instructs query to consider only VMAs that + * have file backing. Can be combined with PROCMAP_QUERY_COVERING_OR_NEXT_VMA + * to iterate all VMAs with file backing. + */ + PROCMAP_QUERY_COVERING_OR_NEXT_VMA = 0x10, + PROCMAP_QUERY_FILE_BACKED_VMA = 0x20, +}; + +/* + * Input/output argument structured passed into ioctl() call. It can be used + * to query a set of VMAs (Virtual Memory Areas) of a process. + * + * Each field can be one of three kinds, marked in a short comment to the + * right of the field: + * - "in", input argument, user has to provide this value, kernel doesn't modify it; + * - "out", output argument, kernel sets this field with VMA data; + * - "in/out", input and output argument; user provides initial value (used + * to specify maximum allowable buffer size), and kernel sets it to actual + * amount of data written (or zero, if there is no data). + * + * If matching VMA is found (according to criterias specified by + * query_addr/query_flags, all the out fields are filled out, and ioctl() + * returns 0. If there is no matching VMA, -ENOENT will be returned. + * In case of any other error, negative error code other than -ENOENT is + * returned. + * + * Most of the data is similar to the one returned as text in /proc//maps + * file, but procmap_query provides more querying flexibility. There are no + * consistency guarantees between subsequent ioctl() calls, but data returned + * for matched VMA is self-consistent. + */ +struct procmap_query { + /* Query struct size, for backwards/forward compatibility */ + __u64 size; + /* + * Query flags, a combination of enum procmap_query_flags values. + * Defines query filtering and behavior, see enum procmap_query_flags. + * + * Input argument, provided by user. Kernel doesn't modify it. + */ + __u64 query_flags; /* in */ + /* + * Query address. By default, VMA that covers this address will + * be looked up. PROCMAP_QUERY_* flags above modify this default + * behavior further. + * + * Input argument, provided by user. Kernel doesn't modify it. + */ + __u64 query_addr; /* in */ + /* VMA starting (inclusive) and ending (exclusive) address, if VMA is found. */ + __u64 vma_start; /* out */ + __u64 vma_end; /* out */ + /* VMA permissions flags. A combination of PROCMAP_QUERY_VMA_* flags. */ + __u64 vma_flags; /* out */ + /* VMA backing page size granularity. */ + __u64 vma_page_size; /* out */ + /* + * VMA file offset. If VMA has file backing, this specifies offset + * within the file that VMA's start address corresponds to. + * Is set to zero if VMA has no backing file. + */ + __u64 vma_offset; /* out */ + /* Backing file's inode number, or zero, if VMA has no backing file. */ + __u64 inode; /* out */ + /* Backing file's device major/minor number, or zero, if VMA has no backing file. */ + __u32 dev_major; /* out */ + __u32 dev_minor; /* out */ + /* + * If set to non-zero value, signals the request to return VMA name + * (i.e., VMA's backing file's absolute path, with " (deleted)" suffix + * appended, if file was unlinked from FS) for matched VMA. VMA name + * can also be some special name (e.g., "[heap]", "[stack]") or could + * be even user-supplied with prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME). + * + * Kernel will set this field to zero, if VMA has no associated name. + * Otherwise kernel will return actual amount of bytes filled in + * user-supplied buffer (see vma_name_addr field below), including the + * terminating zero. + * + * If VMA name is longer that user-supplied maximum buffer size, + * -E2BIG error is returned. + * + * If this field is set to non-zero value, vma_name_addr should point + * to valid user space memory buffer of at least vma_name_size bytes. + * If set to zero, vma_name_addr should be set to zero as well + */ + __u32 vma_name_size; /* in/out */ + /* + * If set to non-zero value, signals the request to extract and return + * VMA's backing file's build ID, if the backing file is an ELF file + * and it contains embedded build ID. + * + * Kernel will set this field to zero, if VMA has no backing file, + * backing file is not an ELF file, or ELF file has no build ID + * embedded. + * + * Build ID is a binary value (not a string). Kernel will set + * build_id_size field to exact number of bytes used for build ID. + * If build ID is requested and present, but needs more bytes than + * user-supplied maximum buffer size (see build_id_addr field below), + * -E2BIG error will be returned. + * + * If this field is set to non-zero value, build_id_addr should point + * to valid user space memory buffer of at least build_id_size bytes. + * If set to zero, build_id_addr should be set to zero as well + */ + __u32 build_id_size; /* in/out */ + /* + * User-supplied address of a buffer of at least vma_name_size bytes + * for kernel to fill with matched VMA's name (see vma_name_size field + * description above for details). + * + * Should be set to zero if VMA name should not be returned. + */ + __u64 vma_name_addr; /* in */ + /* + * User-supplied address of a buffer of at least build_id_size bytes + * for kernel to fill with matched VMA's ELF build ID, if available + * (see build_id_size field description above for details). + * + * Should be set to zero if build ID should not be returned. + */ + __u64 build_id_addr; /* in */ +}; + +#endif /* _LINUX_FS_H */ diff --git a/src/basic/linux/fscrypt.h b/src/basic/linux/fscrypt.h new file mode 100644 index 0000000000..76badefbeb --- /dev/null +++ b/src/basic/linux/fscrypt.h @@ -0,0 +1,195 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * fscrypt user API + * + * These ioctls can be used on filesystems that support fscrypt. See the + * "User API" section of Documentation/filesystems/fscrypt.rst. + */ +#ifndef _LINUX_FSCRYPT_H +#define _LINUX_FSCRYPT_H + +#include +#include + +/* Encryption policy flags */ +#define FSCRYPT_POLICY_FLAGS_PAD_4 0x00 +#define FSCRYPT_POLICY_FLAGS_PAD_8 0x01 +#define FSCRYPT_POLICY_FLAGS_PAD_16 0x02 +#define FSCRYPT_POLICY_FLAGS_PAD_32 0x03 +#define FSCRYPT_POLICY_FLAGS_PAD_MASK 0x03 +#define FSCRYPT_POLICY_FLAG_DIRECT_KEY 0x04 +#define FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64 0x08 +#define FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32 0x10 + +/* Encryption algorithms */ +#define FSCRYPT_MODE_AES_256_XTS 1 +#define FSCRYPT_MODE_AES_256_CTS 4 +#define FSCRYPT_MODE_AES_128_CBC 5 +#define FSCRYPT_MODE_AES_128_CTS 6 +#define FSCRYPT_MODE_SM4_XTS 7 +#define FSCRYPT_MODE_SM4_CTS 8 +#define FSCRYPT_MODE_ADIANTUM 9 +#define FSCRYPT_MODE_AES_256_HCTR2 10 +/* If adding a mode number > 10, update FSCRYPT_MODE_MAX in fscrypt_private.h */ + +/* + * Legacy policy version; ad-hoc KDF and no key verification. + * For new encrypted directories, use fscrypt_policy_v2 instead. + * + * Careful: the .version field for this is actually 0, not 1. + */ +#define FSCRYPT_POLICY_V1 0 +#define FSCRYPT_KEY_DESCRIPTOR_SIZE 8 +struct fscrypt_policy_v1 { + __u8 version; + __u8 contents_encryption_mode; + __u8 filenames_encryption_mode; + __u8 flags; + __u8 master_key_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE]; +}; + +/* + * Process-subscribed "logon" key description prefix and payload format. + * Deprecated; prefer FS_IOC_ADD_ENCRYPTION_KEY instead. + */ +#define FSCRYPT_KEY_DESC_PREFIX "fscrypt:" +#define FSCRYPT_KEY_DESC_PREFIX_SIZE 8 +#define FSCRYPT_MAX_KEY_SIZE 64 +struct fscrypt_key { + __u32 mode; + __u8 raw[FSCRYPT_MAX_KEY_SIZE]; + __u32 size; +}; + +/* + * New policy version with HKDF and key verification (recommended). + */ +#define FSCRYPT_POLICY_V2 2 +#define FSCRYPT_KEY_IDENTIFIER_SIZE 16 +struct fscrypt_policy_v2 { + __u8 version; + __u8 contents_encryption_mode; + __u8 filenames_encryption_mode; + __u8 flags; + __u8 log2_data_unit_size; + __u8 __reserved[3]; + __u8 master_key_identifier[FSCRYPT_KEY_IDENTIFIER_SIZE]; +}; + +/* Struct passed to FS_IOC_GET_ENCRYPTION_POLICY_EX */ +struct fscrypt_get_policy_ex_arg { + __u64 policy_size; /* input/output */ + union { + __u8 version; + struct fscrypt_policy_v1 v1; + struct fscrypt_policy_v2 v2; + } policy; /* output */ +}; + +/* + * v1 policy keys are specified by an arbitrary 8-byte key "descriptor", + * matching fscrypt_policy_v1::master_key_descriptor. + */ +#define FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR 1 + +/* + * v2 policy keys are specified by a 16-byte key "identifier" which the kernel + * calculates as a cryptographic hash of the key itself, + * matching fscrypt_policy_v2::master_key_identifier. + */ +#define FSCRYPT_KEY_SPEC_TYPE_IDENTIFIER 2 + +/* + * Specifies a key, either for v1 or v2 policies. This doesn't contain the + * actual key itself; this is just the "name" of the key. + */ +struct fscrypt_key_specifier { + __u32 type; /* one of FSCRYPT_KEY_SPEC_TYPE_* */ + __u32 __reserved; + union { + __u8 __reserved[32]; /* reserve some extra space */ + __u8 descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE]; + __u8 identifier[FSCRYPT_KEY_IDENTIFIER_SIZE]; + } u; +}; + +/* + * Payload of Linux keyring key of type "fscrypt-provisioning", referenced by + * fscrypt_add_key_arg::key_id as an alternative to fscrypt_add_key_arg::raw. + */ +struct fscrypt_provisioning_key_payload { + __u32 type; + __u32 __reserved; + __u8 raw[]; +}; + +/* Struct passed to FS_IOC_ADD_ENCRYPTION_KEY */ +struct fscrypt_add_key_arg { + struct fscrypt_key_specifier key_spec; + __u32 raw_size; + __u32 key_id; + __u32 __reserved[8]; + __u8 raw[]; +}; + +/* Struct passed to FS_IOC_REMOVE_ENCRYPTION_KEY */ +struct fscrypt_remove_key_arg { + struct fscrypt_key_specifier key_spec; +#define FSCRYPT_KEY_REMOVAL_STATUS_FLAG_FILES_BUSY 0x00000001 +#define FSCRYPT_KEY_REMOVAL_STATUS_FLAG_OTHER_USERS 0x00000002 + __u32 removal_status_flags; /* output */ + __u32 __reserved[5]; +}; + +/* Struct passed to FS_IOC_GET_ENCRYPTION_KEY_STATUS */ +struct fscrypt_get_key_status_arg { + /* input */ + struct fscrypt_key_specifier key_spec; + __u32 __reserved[6]; + + /* output */ +#define FSCRYPT_KEY_STATUS_ABSENT 1 +#define FSCRYPT_KEY_STATUS_PRESENT 2 +#define FSCRYPT_KEY_STATUS_INCOMPLETELY_REMOVED 3 + __u32 status; +#define FSCRYPT_KEY_STATUS_FLAG_ADDED_BY_SELF 0x00000001 + __u32 status_flags; + __u32 user_count; + __u32 __out_reserved[13]; +}; + +#define FS_IOC_SET_ENCRYPTION_POLICY _IOR('f', 19, struct fscrypt_policy_v1) +#define FS_IOC_GET_ENCRYPTION_PWSALT _IOW('f', 20, __u8[16]) +#define FS_IOC_GET_ENCRYPTION_POLICY _IOW('f', 21, struct fscrypt_policy_v1) +#define FS_IOC_GET_ENCRYPTION_POLICY_EX _IOWR('f', 22, __u8[9]) /* size + version */ +#define FS_IOC_ADD_ENCRYPTION_KEY _IOWR('f', 23, struct fscrypt_add_key_arg) +#define FS_IOC_REMOVE_ENCRYPTION_KEY _IOWR('f', 24, struct fscrypt_remove_key_arg) +#define FS_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS _IOWR('f', 25, struct fscrypt_remove_key_arg) +#define FS_IOC_GET_ENCRYPTION_KEY_STATUS _IOWR('f', 26, struct fscrypt_get_key_status_arg) +#define FS_IOC_GET_ENCRYPTION_NONCE _IOR('f', 27, __u8[16]) + +/**********************************************************************/ + +/* old names; don't add anything new here! */ +#define fscrypt_policy fscrypt_policy_v1 +#define FS_KEY_DESCRIPTOR_SIZE FSCRYPT_KEY_DESCRIPTOR_SIZE +#define FS_POLICY_FLAGS_PAD_4 FSCRYPT_POLICY_FLAGS_PAD_4 +#define FS_POLICY_FLAGS_PAD_8 FSCRYPT_POLICY_FLAGS_PAD_8 +#define FS_POLICY_FLAGS_PAD_16 FSCRYPT_POLICY_FLAGS_PAD_16 +#define FS_POLICY_FLAGS_PAD_32 FSCRYPT_POLICY_FLAGS_PAD_32 +#define FS_POLICY_FLAGS_PAD_MASK FSCRYPT_POLICY_FLAGS_PAD_MASK +#define FS_POLICY_FLAG_DIRECT_KEY FSCRYPT_POLICY_FLAG_DIRECT_KEY +#define FS_POLICY_FLAGS_VALID 0x07 /* contains old flags only */ +#define FS_ENCRYPTION_MODE_INVALID 0 /* never used */ +#define FS_ENCRYPTION_MODE_AES_256_XTS FSCRYPT_MODE_AES_256_XTS +#define FS_ENCRYPTION_MODE_AES_256_GCM 2 /* never used */ +#define FS_ENCRYPTION_MODE_AES_256_CBC 3 /* never used */ +#define FS_ENCRYPTION_MODE_AES_256_CTS FSCRYPT_MODE_AES_256_CTS +#define FS_ENCRYPTION_MODE_AES_128_CBC FSCRYPT_MODE_AES_128_CBC +#define FS_ENCRYPTION_MODE_AES_128_CTS FSCRYPT_MODE_AES_128_CTS +#define FS_ENCRYPTION_MODE_ADIANTUM FSCRYPT_MODE_ADIANTUM +#define FS_KEY_DESC_PREFIX FSCRYPT_KEY_DESC_PREFIX +#define FS_KEY_DESC_PREFIX_SIZE FSCRYPT_KEY_DESC_PREFIX_SIZE +#define FS_MAX_KEY_SIZE FSCRYPT_MAX_KEY_SIZE + +#endif /* _LINUX_FSCRYPT_H */ diff --git a/src/basic/linux/limits.h b/src/basic/linux/limits.h new file mode 100644 index 0000000000..c3547f0760 --- /dev/null +++ b/src/basic/linux/limits.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _LINUX_LIMITS_H +#define _LINUX_LIMITS_H + +#define NR_OPEN 1024 + +#define NGROUPS_MAX 65536 /* supplemental group IDs are available */ +#define ARG_MAX 131072 /* # bytes of args + environ for exec() */ +#define LINK_MAX 127 /* # links a file may have */ +#define MAX_CANON 255 /* size of the canonical input queue */ +#define MAX_INPUT 255 /* size of the type-ahead buffer */ +#define NAME_MAX 255 /* # chars in a file name */ +#define PATH_MAX 4096 /* # chars in a path name including nul */ +#define PIPE_BUF 4096 /* # bytes in atomic write to a pipe */ +#define XATTR_NAME_MAX 255 /* # chars in an extended attribute name */ +#define XATTR_SIZE_MAX 65536 /* size of an extended attribute value (64k) */ +#define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */ + +#define RTSIG_MAX 32 + +#endif diff --git a/src/basic/linux/mount.h b/src/basic/linux/mount.h new file mode 100644 index 0000000000..f3c51f221b --- /dev/null +++ b/src/basic/linux/mount.h @@ -0,0 +1,227 @@ +#ifndef _LINUX_MOUNT_H +#define _LINUX_MOUNT_H + +#include + +/* + * These are the fs-independent mount-flags: up to 32 flags are supported + * + * Usage of these is restricted within the kernel to core mount(2) code and + * callers of sys_mount() only. Filesystems should be using the SB_* + * equivalent instead. + */ +#define MS_RDONLY 1 /* Mount read-only */ +#define MS_NOSUID 2 /* Ignore suid and sgid bits */ +#define MS_NODEV 4 /* Disallow access to device special files */ +#define MS_NOEXEC 8 /* Disallow program execution */ +#define MS_SYNCHRONOUS 16 /* Writes are synced at once */ +#define MS_REMOUNT 32 /* Alter flags of a mounted FS */ +#define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */ +#define MS_DIRSYNC 128 /* Directory modifications are synchronous */ +#define MS_NOSYMFOLLOW 256 /* Do not follow symlinks */ +#define MS_NOATIME 1024 /* Do not update access times. */ +#define MS_NODIRATIME 2048 /* Do not update directory access times */ +#define MS_BIND 4096 +#define MS_MOVE 8192 +#define MS_REC 16384 +#define MS_VERBOSE 32768 /* War is peace. Verbosity is silence. + MS_VERBOSE is deprecated. */ +#define MS_SILENT 32768 +#define MS_POSIXACL (1<<16) /* VFS does not apply the umask */ +#define MS_UNBINDABLE (1<<17) /* change to unbindable */ +#define MS_PRIVATE (1<<18) /* change to private */ +#define MS_SLAVE (1<<19) /* change to slave */ +#define MS_SHARED (1<<20) /* change to shared */ +#define MS_RELATIME (1<<21) /* Update atime relative to mtime/ctime. */ +#define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */ +#define MS_I_VERSION (1<<23) /* Update inode I_version field */ +#define MS_STRICTATIME (1<<24) /* Always perform atime updates */ +#define MS_LAZYTIME (1<<25) /* Update the on-disk [acm]times lazily */ + +/* These sb flags are internal to the kernel */ +#define MS_SUBMOUNT (1<<26) +#define MS_NOREMOTELOCK (1<<27) +#define MS_NOSEC (1<<28) +#define MS_BORN (1<<29) +#define MS_ACTIVE (1<<30) +#define MS_NOUSER (1<<31) + +/* + * Superblock flags that can be altered by MS_REMOUNT + */ +#define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION|\ + MS_LAZYTIME) + +/* + * Old magic mount flag and mask + */ +#define MS_MGC_VAL 0xC0ED0000 +#define MS_MGC_MSK 0xffff0000 + +/* + * open_tree() flags. + */ +#define OPEN_TREE_CLONE 1 /* Clone the target tree and attach the clone */ +#define OPEN_TREE_CLOEXEC O_CLOEXEC /* Close the file on execve() */ + +/* + * move_mount() flags. + */ +#define MOVE_MOUNT_F_SYMLINKS 0x00000001 /* Follow symlinks on from path */ +#define MOVE_MOUNT_F_AUTOMOUNTS 0x00000002 /* Follow automounts on from path */ +#define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */ +#define MOVE_MOUNT_T_SYMLINKS 0x00000010 /* Follow symlinks on to path */ +#define MOVE_MOUNT_T_AUTOMOUNTS 0x00000020 /* Follow automounts on to path */ +#define MOVE_MOUNT_T_EMPTY_PATH 0x00000040 /* Empty to path permitted */ +#define MOVE_MOUNT_SET_GROUP 0x00000100 /* Set sharing group instead */ +#define MOVE_MOUNT_BENEATH 0x00000200 /* Mount beneath top mount */ +#define MOVE_MOUNT__MASK 0x00000377 + +/* + * fsopen() flags. + */ +#define FSOPEN_CLOEXEC 0x00000001 + +/* + * fspick() flags. + */ +#define FSPICK_CLOEXEC 0x00000001 +#define FSPICK_SYMLINK_NOFOLLOW 0x00000002 +#define FSPICK_NO_AUTOMOUNT 0x00000004 +#define FSPICK_EMPTY_PATH 0x00000008 + +/* + * The type of fsconfig() call made. + */ +enum fsconfig_command { + FSCONFIG_SET_FLAG = 0, /* Set parameter, supplying no value */ + FSCONFIG_SET_STRING = 1, /* Set parameter, supplying a string value */ + FSCONFIG_SET_BINARY = 2, /* Set parameter, supplying a binary blob value */ + FSCONFIG_SET_PATH = 3, /* Set parameter, supplying an object by path */ + FSCONFIG_SET_PATH_EMPTY = 4, /* Set parameter, supplying an object by (empty) path */ + FSCONFIG_SET_FD = 5, /* Set parameter, supplying an object by fd */ + FSCONFIG_CMD_CREATE = 6, /* Create new or reuse existing superblock */ + FSCONFIG_CMD_RECONFIGURE = 7, /* Invoke superblock reconfiguration */ + FSCONFIG_CMD_CREATE_EXCL = 8, /* Create new superblock, fail if reusing existing superblock */ +}; + +/* + * fsmount() flags. + */ +#define FSMOUNT_CLOEXEC 0x00000001 + +/* + * Mount attributes. + */ +#define MOUNT_ATTR_RDONLY 0x00000001 /* Mount read-only */ +#define MOUNT_ATTR_NOSUID 0x00000002 /* Ignore suid and sgid bits */ +#define MOUNT_ATTR_NODEV 0x00000004 /* Disallow access to device special files */ +#define MOUNT_ATTR_NOEXEC 0x00000008 /* Disallow program execution */ +#define MOUNT_ATTR__ATIME 0x00000070 /* Setting on how atime should be updated */ +#define MOUNT_ATTR_RELATIME 0x00000000 /* - Update atime relative to mtime/ctime. */ +#define MOUNT_ATTR_NOATIME 0x00000010 /* - Do not update access times. */ +#define MOUNT_ATTR_STRICTATIME 0x00000020 /* - Always perform atime updates */ +#define MOUNT_ATTR_NODIRATIME 0x00000080 /* Do not update directory access times */ +#define MOUNT_ATTR_IDMAP 0x00100000 /* Idmap mount to @userns_fd in struct mount_attr. */ +#define MOUNT_ATTR_NOSYMFOLLOW 0x00200000 /* Do not follow symlinks */ + +/* + * mount_setattr() + */ +struct mount_attr { + __u64 attr_set; + __u64 attr_clr; + __u64 propagation; + __u64 userns_fd; +}; + +/* List of all mount_attr versions. */ +#define MOUNT_ATTR_SIZE_VER0 32 /* sizeof first published struct */ + + +/* + * Structure for getting mount/superblock/filesystem info with statmount(2). + * + * The interface is similar to statx(2): individual fields or groups can be + * selected with the @mask argument of statmount(). Kernel will set the @mask + * field according to the supported fields. + * + * If string fields are selected, then the caller needs to pass a buffer that + * has space after the fixed part of the structure. Nul terminated strings are + * copied there and offsets relative to @str are stored in the relevant fields. + * If the buffer is too small, then EOVERFLOW is returned. The actually used + * size is returned in @size. + */ +struct statmount { + __u32 size; /* Total size, including strings */ + __u32 mnt_opts; /* [str] Options (comma separated, escaped) */ + __u64 mask; /* What results were written */ + __u32 sb_dev_major; /* Device ID */ + __u32 sb_dev_minor; + __u64 sb_magic; /* ..._SUPER_MAGIC */ + __u32 sb_flags; /* SB_{RDONLY,SYNCHRONOUS,DIRSYNC,LAZYTIME} */ + __u32 fs_type; /* [str] Filesystem type */ + __u64 mnt_id; /* Unique ID of mount */ + __u64 mnt_parent_id; /* Unique ID of parent (for root == mnt_id) */ + __u32 mnt_id_old; /* Reused IDs used in proc/.../mountinfo */ + __u32 mnt_parent_id_old; + __u64 mnt_attr; /* MOUNT_ATTR_... */ + __u64 mnt_propagation; /* MS_{SHARED,SLAVE,PRIVATE,UNBINDABLE} */ + __u64 mnt_peer_group; /* ID of shared peer group */ + __u64 mnt_master; /* Mount receives propagation from this ID */ + __u64 propagate_from; /* Propagation from in current namespace */ + __u32 mnt_root; /* [str] Root of mount relative to root of fs */ + __u32 mnt_point; /* [str] Mountpoint relative to current root */ + __u64 mnt_ns_id; /* ID of the mount namespace */ + __u32 fs_subtype; /* [str] Subtype of fs_type (if any) */ + __u32 sb_source; /* [str] Source string of the mount */ + __u32 opt_num; /* Number of fs options */ + __u32 opt_array; /* [str] Array of nul terminated fs options */ + __u32 opt_sec_num; /* Number of security options */ + __u32 opt_sec_array; /* [str] Array of nul terminated security options */ + __u64 __spare2[46]; + char str[]; /* Variable size part containing strings */ +}; + +/* + * Structure for passing mount ID and miscellaneous parameters to statmount(2) + * and listmount(2). + * + * For statmount(2) @param represents the request mask. + * For listmount(2) @param represents the last listed mount id (or zero). + */ +struct mnt_id_req { + __u32 size; + __u32 spare; + __u64 mnt_id; + __u64 param; + __u64 mnt_ns_id; +}; + +/* List of all mnt_id_req versions. */ +#define MNT_ID_REQ_SIZE_VER0 24 /* sizeof first published struct */ +#define MNT_ID_REQ_SIZE_VER1 32 /* sizeof second published struct */ + +/* + * @mask bits for statmount(2) + */ +#define STATMOUNT_SB_BASIC 0x00000001U /* Want/got sb_... */ +#define STATMOUNT_MNT_BASIC 0x00000002U /* Want/got mnt_... */ +#define STATMOUNT_PROPAGATE_FROM 0x00000004U /* Want/got propagate_from */ +#define STATMOUNT_MNT_ROOT 0x00000008U /* Want/got mnt_root */ +#define STATMOUNT_MNT_POINT 0x00000010U /* Want/got mnt_point */ +#define STATMOUNT_FS_TYPE 0x00000020U /* Want/got fs_type */ +#define STATMOUNT_MNT_NS_ID 0x00000040U /* Want/got mnt_ns_id */ +#define STATMOUNT_MNT_OPTS 0x00000080U /* Want/got mnt_opts */ +#define STATMOUNT_FS_SUBTYPE 0x00000100U /* Want/got fs_subtype */ +#define STATMOUNT_SB_SOURCE 0x00000200U /* Want/got sb_source */ +#define STATMOUNT_OPT_ARRAY 0x00000400U /* Want/got opt_... */ +#define STATMOUNT_OPT_SEC_ARRAY 0x00000800U /* Want/got opt_sec... */ + +/* + * Special @mnt_id values that can be passed to listmount + */ +#define LSMT_ROOT 0xffffffffffffffff /* root mount */ +#define LISTMOUNT_REVERSE (1 << 0) /* List later mounts first */ + +#endif /* _LINUX_MOUNT_H */ diff --git a/src/basic/linux/update.sh b/src/basic/linux/update.sh index 6c17325237..31dcddaf95 100755 --- a/src/basic/linux/update.sh +++ b/src/basic/linux/update.sh @@ -21,10 +21,6 @@ for i in *.h */*.h; do # set AUTOFS_DEV_IOCTL_VERSION_MINOR to 0 sed -r -i '/^#define[[:space:]]+AUTOFS_DEV_IOCTL_VERSION_MINOR/ s/[0-9]+/0/' "$i" ;; - btrfs.h) - # guard linux/fs.h include to avoid conflict with glibc 2.36 - sed -r -i 's/^(#include )/#if WANT_LINUX_FS_H\n\1\n#endif/' "$i" - ;; dm-ioctl.h) # set DM_VERSION_MINOR to 27 sed -r -i '/^#define[[:space:]]+DM_VERSION_MINOR/ s/[0-9]+/27/' "$i" diff --git a/src/basic/missing_fs.h b/src/basic/missing_fs.h index 79c43c72f7..dfd79504bc 100644 --- a/src/basic/missing_fs.h +++ b/src/basic/missing_fs.h @@ -1,81 +1,49 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +/* temporary undef definitions in bits/uio-ext.h, which is included by sys/uio.h */ +#include + +#define __RWF_HIPRI_SAVED__ RWF_HIPRI +#undef RWF_HIPRI +#define __RWF_DSYNC_SAVED__ RWF_DSYNC +#undef RWF_DSYNC +#define __RWF_SYNC_SAVED__ RWF_SYNC +#undef RWF_SYNC +#define __RWF_NOWAIT_SAVED__ RWF_NOWAIT +#undef RWF_NOWAIT +#define __RWF_APPEND_SAVED__ RWF_APPEND +#undef RWF_APPEND +#define __RWF_NOAPPEND_SAVED__ RWF_NOAPPEND +#undef RWF_NOAPPEND +#if defined(RWF_ATOMIC) +#define __RWF_ATOMIC_SAVED__ RWF_ATOMIC +#undef RWF_ATOMIC +#else +#define __RWF_ATOMIC_SAVED__ 0x00000040 +#endif +#if defined(RWF_DONTCACHE) +#define __RWF_DONTCACHE_SAVED__ RWF_DONTCACHE +#undef RWF_DONTCACHE +#else +#define __RWF_DONTCACHE_SAVED__ 0x00000080 +#endif + +#include +#include +#include #include "macro.h" -/* linux/fs.h */ -#ifndef BLKGETDISKSEQ /* 7957d93bf32bc211415827e44fdd9cdf1388df59 (5.15) */ -#define BLKGETDISKSEQ _IOR(0x12,128,__u64) -#endif - -/* linux/fs.h or sys/mount.h */ -#ifndef MS_MOVE -# define MS_MOVE 8192 -#else -assert_cc(MS_MOVE == 8192); -#endif - -#ifndef MS_REC -# define MS_REC 16384 -#else -assert_cc(MS_REC == 16384); -#endif - -#ifndef MS_PRIVATE -# define MS_PRIVATE (1<<18) -#else -assert_cc(MS_PRIVATE == (1<<18)); -#endif - -#ifndef MS_SLAVE -# define MS_SLAVE (1<<19) -#else -assert_cc(MS_SLAVE == (1<<19)); -#endif - -#ifndef MS_SHARED -# define MS_SHARED (1<<20) -#else -assert_cc(MS_SHARED == (1<<20)); -#endif - -#ifndef MS_RELATIME -# define MS_RELATIME (1<<21) -#else -assert_cc(MS_RELATIME == (1<<21)); -#endif - -#ifndef MS_KERNMOUNT -# define MS_KERNMOUNT (1<<22) -#else -assert_cc(MS_KERNMOUNT == (1<<22)); -#endif - -#ifndef MS_I_VERSION -# define MS_I_VERSION (1<<23) -#else -assert_cc(MS_I_VERSION == (1<<23)); -#endif - -#ifndef MS_STRICTATIME -# define MS_STRICTATIME (1<<24) -#else -assert_cc(MS_STRICTATIME == (1 << 24)); -#endif - -#ifndef MS_LAZYTIME -# define MS_LAZYTIME (1<<25) -#else -assert_cc(MS_LAZYTIME == (1<<25)); -#endif - -#ifndef FS_PROJINHERIT_FL -# define FS_PROJINHERIT_FL 0x20000000 -#else -assert_cc(FS_PROJINHERIT_FL == 0x20000000); -#endif +/* check RWF_xyz are redefined by linux/fs.h */ +assert_cc(RWF_HIPRI == __RWF_HIPRI_SAVED__); +assert_cc(RWF_DSYNC == __RWF_DSYNC_SAVED__); +assert_cc(RWF_SYNC == __RWF_SYNC_SAVED__); +assert_cc(RWF_NOWAIT == __RWF_NOWAIT_SAVED__); +assert_cc(RWF_APPEND == __RWF_APPEND_SAVED__); +assert_cc(RWF_NOAPPEND == __RWF_NOAPPEND_SAVED__); +assert_cc(RWF_ATOMIC == __RWF_ATOMIC_SAVED__); +assert_cc(RWF_DONTCACHE == __RWF_DONTCACHE_SAVED__); /* Not exposed yet. Defined at fs/ext4/ext4.h */ #ifndef EXT4_IOC_RESIZE_FS diff --git a/src/basic/missing_mount.h b/src/basic/missing_mount.h deleted file mode 100644 index d6e16e556e..0000000000 --- a/src/basic/missing_mount.h +++ /dev/null @@ -1,13 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#include - -#include "macro.h" - -/* dab741e0e02bd3c4f5e2e97be74b39df2523fc6e (5.10) */ -#ifndef MS_NOSYMFOLLOW -# define MS_NOSYMFOLLOW 256 -#else -assert_cc(MS_NOSYMFOLLOW == 256); -#endif diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index ebdb1c30b9..53dcd69d9e 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -4,7 +4,6 @@ /* Missing glibc definitions to access certain kernel APIs */ #include -#include #include #include #include @@ -213,201 +212,6 @@ static inline int missing_close_range(unsigned first_fd, unsigned end_fd, unsign /* ======================================================================= */ -#if !HAVE_MOUNT_SETATTR -/* since kernel v5.12 (2a1867219c7b27f928e2545782b86daaf9ad50bd) */ - -#if !HAVE_STRUCT_MOUNT_ATTR -struct mount_attr { - uint64_t attr_set; - uint64_t attr_clr; - uint64_t propagation; - uint64_t userns_fd; -}; -#else -struct mount_attr; -#endif - -#ifndef MOUNT_ATTR_RDONLY -#define MOUNT_ATTR_RDONLY 0x00000001 /* Mount read-only */ -#endif - -#ifndef MOUNT_ATTR_NOSUID -#define MOUNT_ATTR_NOSUID 0x00000002 /* Ignore suid and sgid bits */ -#endif - -#ifndef MOUNT_ATTR_NODEV -#define MOUNT_ATTR_NODEV 0x00000004 /* Disallow access to device special files */ -#endif - -#ifndef MOUNT_ATTR_NOEXEC -#define MOUNT_ATTR_NOEXEC 0x00000008 /* Disallow program execution */ -#endif - -#ifndef MOUNT_ATTR__ATIME -#define MOUNT_ATTR__ATIME 0x00000070 /* Setting on how atime should be updated */ -#endif - -#ifndef MOUNT_ATTR_RELATIME -#define MOUNT_ATTR_RELATIME 0x00000000 /* - Update atime relative to mtime/ctime. */ -#endif - -#ifndef MOUNT_ATTR_NOATIME -#define MOUNT_ATTR_NOATIME 0x00000010 /* - Do not update access times. */ -#endif - -#ifndef MOUNT_ATTR_STRICTATIME -#define MOUNT_ATTR_STRICTATIME 0x00000020 /* - Always perform atime updates */ -#endif - -#ifndef MOUNT_ATTR_NODIRATIME -#define MOUNT_ATTR_NODIRATIME 0x00000080 /* Do not update directory access times */ -#endif - -#ifndef MOUNT_ATTR_IDMAP -#define MOUNT_ATTR_IDMAP 0x00100000 /* Idmap mount to @userns_fd in struct mount_attr. */ -#endif - -#ifndef MOUNT_ATTR_NOSYMFOLLOW -#define MOUNT_ATTR_NOSYMFOLLOW 0x00200000 /* Do not follow symlinks */ -#endif - -#ifndef MOUNT_ATTR_SIZE_VER0 -#define MOUNT_ATTR_SIZE_VER0 32 /* sizeof first published struct */ -#endif - -#ifndef AT_RECURSIVE -#define AT_RECURSIVE 0x8000 -#endif - -static inline int missing_mount_setattr( - int dfd, - const char *path, - unsigned flags, - struct mount_attr *attr, - size_t size) { - - return syscall(__NR_mount_setattr, dfd, path, flags, attr, size); -} - -# define mount_setattr missing_mount_setattr -#endif - -/* ======================================================================= */ - -#if !HAVE_OPEN_TREE -/* since kernel v5.2 (a07b20004793d8926f78d63eb5980559f7813404, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */ - -#ifndef OPEN_TREE_CLONE -#define OPEN_TREE_CLONE 1 -#endif - -#ifndef OPEN_TREE_CLOEXEC -#define OPEN_TREE_CLOEXEC O_CLOEXEC -#endif - -static inline int missing_open_tree( - int dfd, - const char *filename, - unsigned flags) { - - return syscall(__NR_open_tree, dfd, filename, flags); -} - -# define open_tree missing_open_tree -#endif - -/* ======================================================================= */ - -#ifndef MOVE_MOUNT_BENEATH -#define MOVE_MOUNT_BENEATH 0x00000200 -#endif - -#if !HAVE_MOVE_MOUNT -/* since kernel v5.2 (2db154b3ea8e14b04fee23e3fdfd5e9d17fbc6ae, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */ - -#ifndef MOVE_MOUNT_F_EMPTY_PATH -#define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */ -#endif - -#ifndef MOVE_MOUNT_T_EMPTY_PATH -#define MOVE_MOUNT_T_EMPTY_PATH 0x00000040 /* Empty to path permitted */ -#endif - -static inline int missing_move_mount( - int from_dfd, - const char *from_pathname, - int to_dfd, - const char *to_pathname, - unsigned flags) { - - return syscall(__NR_move_mount, from_dfd, from_pathname, to_dfd, to_pathname, flags); -} - -# define move_mount missing_move_mount -#endif - -/* ======================================================================= */ - -#if !HAVE_FSOPEN -/* since kernel v5.2 (24dcb3d90a1f67fe08c68a004af37df059d74005, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */ - -#ifndef FSOPEN_CLOEXEC -#define FSOPEN_CLOEXEC 0x00000001 -#endif - -static inline int missing_fsopen(const char *fsname, unsigned flags) { - return syscall(__NR_fsopen, fsname, flags); -} - -# define fsopen missing_fsopen -#endif - -/* ======================================================================= */ - -#if !HAVE_FSCONFIG -/* since kernel v5.2 (ecdab150fddb42fe6a739335257949220033b782, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */ - -#ifndef FSCONFIG_SET_FLAG -#define FSCONFIG_SET_FLAG 0 /* Set parameter, supplying no value */ -#endif - -#ifndef FSCONFIG_SET_STRING -#define FSCONFIG_SET_STRING 1 /* Set parameter, supplying a string value */ -#endif - -#ifndef FSCONFIG_SET_FD -#define FSCONFIG_SET_FD 5 /* Set parameter, supplying an object by fd */ -#endif - -#ifndef FSCONFIG_CMD_CREATE -#define FSCONFIG_CMD_CREATE 6 /* Invoke superblock creation */ -#endif - -static inline int missing_fsconfig(int fd, unsigned cmd, const char *key, const void *value, int aux) { - return syscall(__NR_fsconfig, fd, cmd, key, value, aux); -} - -# define fsconfig missing_fsconfig -#endif - -/* ======================================================================= */ - -#if !HAVE_FSMOUNT -/* since kernel v5.2 for (93766fbd2696c2c4453dd8e1070977e9cd4e6b6d, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */ - -#ifndef FSMOUNT_CLOEXEC -#define FSMOUNT_CLOEXEC 0x00000001 -#endif - -static inline int missing_fsmount(int fd, unsigned flags, unsigned ms_flags) { - return syscall(__NR_fsmount, fd, flags, ms_flags); -} - -# define fsmount missing_fsmount -#endif - -/* ======================================================================= */ - #if !HAVE_GETDENTS64 static inline ssize_t missing_getdents64(int fd, void *buffer, size_t length) { return syscall(__NR_getdents64, fd, buffer, length); diff --git a/src/basic/mountpoint-util.c b/src/basic/mountpoint-util.c index cb79d621a1..9e376e5a88 100644 --- a/src/basic/mountpoint-util.c +++ b/src/basic/mountpoint-util.c @@ -3,9 +3,6 @@ #include #include #include -#if WANT_LINUX_FS_H -#include -#endif #include "alloc-util.h" #include "chase.h" @@ -15,7 +12,6 @@ #include "fs-util.h" #include "missing_fcntl.h" #include "missing_fs.h" -#include "missing_mount.h" #include "missing_syscall.h" #include "mkdir.h" #include "mountpoint-util.h" diff --git a/src/basic/namespace-util.c b/src/basic/namespace-util.c index 99cece1674..322cba4cf3 100644 --- a/src/basic/namespace-util.c +++ b/src/basic/namespace-util.c @@ -3,9 +3,6 @@ #include #include #include -#if WANT_LINUX_FS_H -#include -#endif #include "errno-util.h" #include "fd-util.h" diff --git a/src/basic/sys/mount.h b/src/basic/sys/mount.h new file mode 100644 index 0000000000..13a3ba6851 --- /dev/null +++ b/src/basic/sys/mount.h @@ -0,0 +1,115 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "missing_fcntl.h" +#include "missing_fs.h" +#include "missing_syscall_def.h" + +/* Possible value for FLAGS parameter of `umount2'. */ +enum +{ + MNT_FORCE = 1, /* Force unmounting. */ +#define MNT_FORCE MNT_FORCE + MNT_DETACH = 2, /* Just detach from the tree. */ +#define MNT_DETACH MNT_DETACH + MNT_EXPIRE = 4, /* Mark for expiry. */ +#define MNT_EXPIRE MNT_EXPIRE + UMOUNT_NOFOLLOW = 8 /* Don't follow symlink on umount. */ +#define UMOUNT_NOFOLLOW UMOUNT_NOFOLLOW +}; + +/* Mount a filesystem. */ +extern int mount(const char *__special_file, const char *__dir, const char *__fstype, unsigned long int __rwflag, const void *__data) __THROW; + +/* Unmount a filesystem. */ +extern int umount(const char *__special_file) __THROW; + +/* Unmount a filesystem. Force unmounting if FLAGS is set to MNT_FORCE. */ +extern int umount2(const char *__special_file, int __flags) __THROW; + +/* Open the filesystem referenced by FS_NAME so it can be configured for + mouting. */ +#if HAVE_FSOPEN +extern int fsopen(const char *__fs_name, unsigned int __flags) __THROW; +#else +static inline int missing_fsopen(const char *fsname, unsigned flags) { + return syscall(__NR_fsopen, fsname, flags); +} +# define fsopen missing_fsopen +#endif + +/* Create a mount representation for the FD created by fsopen using + FLAGS with ATTR_FLAGS describing how the mount is to be performed. */ +#if HAVE_FSMOUNT +extern int fsmount(int __fd, unsigned int __flags, unsigned int __ms_flags) __THROW; +#else +static inline int missing_fsmount(int fd, unsigned flags, unsigned ms_flags) { + return syscall(__NR_fsmount, fd, flags, ms_flags); +} +# define fsmount missing_fsmount +#endif + +/* Add the mounted FROM_DFD referenced by FROM_PATHNAME filesystem returned + by fsmount in the hierarchy in the place TO_DFD reference by TO_PATHNAME + using FLAGS. */ +#if HAVE_MOVE_MOUNT +extern int move_mount(int __from_dfd, const char *__from_pathname, int __to_dfd, const char *__to_pathname, unsigned int flags) __THROW; +#else +static inline int missing_move_mount( + int from_dfd, + const char *from_pathname, + int to_dfd, + const char *to_pathname, + unsigned flags) { + + return syscall(__NR_move_mount, from_dfd, from_pathname, to_dfd, to_pathname, flags); +} +# define move_mount missing_move_mount +#endif + +/* Set parameters and trigger CMD action on the FD context. KEY, VALUE, + and AUX are used depending ng of the CMD. */ +#if HAVE_FSCONFIG +extern int fsconfig(int __fd, unsigned int __cmd, const char *__key, const void *__value, int __aux) __THROW; +#else +static inline int missing_fsconfig(int fd, unsigned cmd, const char *key, const void *value, int aux) { + return syscall(__NR_fsconfig, fd, cmd, key, value, aux); +} +# define fsconfig missing_fsconfig +#endif + +/* Equivalent of fopen for an existing mount point. */ +#if HAVE_FSPICK +extern int fspick(int __dfd, const char *__path, unsigned int __flags) __THROW; +#endif + +/* Open the mount point FILENAME in directory DFD using FLAGS. */ +#if HAVE_OPEN_TREE +extern int open_tree(int __dfd, const char *__filename, unsigned int __flags) __THROW; +#else +static inline int missing_open_tree(int dfd, const char *filename, unsigned flags) { + return syscall(__NR_open_tree, dfd, filename, flags); +} +# define open_tree missing_open_tree +#endif + +/* Change the mount properties of the mount or an entire mount tree. If + PATH is a relative pathname, then it is interpreted relative to the + directory referred to by the file descriptor dirfd. Otherwise if DFD is + the special value AT_FDCWD then PATH is interpreted relative to the current + working directory of the calling process. */ +#if HAVE_MOUNT_SETATTR +extern int mount_setattr(int __dfd, const char *__path, unsigned int __flags, struct mount_attr *__uattr, size_t __usize) __THROW; +#else +static inline int missing_mount_setattr(int dfd, const char *path, unsigned flags, struct mount_attr *attr, size_t size) { + return syscall(__NR_mount_setattr, dfd, path, flags, attr, size); +} +# define mount_setattr missing_mount_setattr +#endif diff --git a/src/core/execute.c b/src/core/execute.c index 2cc4d7e659..1b6fe5b31a 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -14,8 +14,6 @@ #include #include -#include /* Must be included after */ - #include "sd-messages.h" #include "af-list.h" diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index dde7a55f4f..2eb3ed4cf4 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -5,7 +5,6 @@ #include #include -#include #include #include #include @@ -48,6 +47,7 @@ #include "limits-util.h" #include "load-fragment.h" #include "log.h" +#include "missing_fs.h" #include "mountpoint-util.h" #include "nulstr-util.h" #include "open-file.h" diff --git a/src/core/namespace.c b/src/core/namespace.c index 54dd4abd77..c99233ce65 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -7,9 +7,6 @@ #include #include #include -#if WANT_LINUX_FS_H -#include -#endif #include "alloc-util.h" #include "base-filesystem.h" diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index fa009bdacf..a61bd01c16 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -8,9 +8,6 @@ #include #include #include -#if WANT_LINUX_FS_H -# include -#endif #include "sd-daemon.h" #include "sd-journal.h" @@ -43,7 +40,6 @@ #include "main-func.h" #include "memory-util.h" #include "memstream-util.h" -#include "missing_mount.h" #include "missing_syscall.h" #include "mkdir-label.h" #include "namespace-util.h" diff --git a/src/growfs/growfs.c b/src/growfs/growfs.c index c1ee18ac27..cb653ba0c7 100644 --- a/src/growfs/growfs.c +++ b/src/growfs/growfs.c @@ -8,12 +8,6 @@ #include #include #include -/* This needs to be included after sys/mount.h, as since [0] linux/btrfs.h - * includes linux/fs.h causing build errors - * See: https://github.com/systemd/systemd/issues/8507 - * [0] https://github.com/torvalds/linux/commit/a28135303a669917002f569aecebd5758263e4aa - */ -#include #include "sd-device.h" @@ -30,6 +24,7 @@ #include "format-util.h" #include "log.h" #include "main-func.h" +#include "missing_fs.h" #include "mountpoint-util.h" #include "parse-util.h" #include "pretty-print.h" diff --git a/src/home/homed-manager.c b/src/home/homed-manager.c index e628e1a389..d49693a2e0 100644 --- a/src/home/homed-manager.c +++ b/src/home/homed-manager.c @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include #include #include #include @@ -36,6 +35,7 @@ #include "homed-manager.h" #include "homed-varlink.h" #include "io-util.h" +#include "missing_fs.h" #include "mkdir.h" #include "notify-recv.h" #include "openssl-util.h" diff --git a/src/home/homework-cifs.c b/src/home/homework-cifs.c index f665c75d7f..e10ef9ccdd 100644 --- a/src/home/homework-cifs.c +++ b/src/home/homework-cifs.c @@ -1,9 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#if WANT_LINUX_FS_H -#include -#endif #include "dirent-util.h" #include "fd-util.h" diff --git a/src/home/homework-fscrypt.c b/src/home/homework-fscrypt.c index 3a9d4ea891..03ad3da1b2 100644 --- a/src/home/homework-fscrypt.c +++ b/src/home/homework-fscrypt.c @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include #include #include @@ -14,6 +13,7 @@ #include "homework-quota.h" #include "keyring-util.h" #include "memory-util.h" +#include "missing_fs.h" #include "missing_keyctl.h" #include "missing_syscall.h" #include "mkdir.h" diff --git a/src/home/homework-mount.c b/src/home/homework-mount.c index 8d32adb270..d6bb964973 100644 --- a/src/home/homework-mount.c +++ b/src/home/homework-mount.c @@ -2,9 +2,6 @@ #include #include -#if WANT_LINUX_FS_H -#include -#endif #include "alloc-util.h" #include "fd-util.h" @@ -13,7 +10,6 @@ #include "home-util.h" #include "homework-mount.h" #include "homework.h" -#include "missing_mount.h" #include "missing_syscall.h" #include "mkdir.h" #include "mount-util.h" diff --git a/src/home/homework.h b/src/home/homework.h index fb2b43edd6..138483bbc6 100644 --- a/src/home/homework.h +++ b/src/home/homework.h @@ -8,7 +8,7 @@ #include "cryptsetup-util.h" #include "homework-password-cache.h" #include "loop-util.h" -#include "missing_fs.h" /* for FS_KEY_DESCRIPTOR_SIZE, do not include linux/fs.h */ +#include "missing_fs.h" #include "missing_keyctl.h" #include "missing_syscall.h" #include "user-record.h" diff --git a/src/import/import-raw.c b/src/import/import-raw.c index 602d1f1ac3..6400995a9e 100644 --- a/src/import/import-raw.c +++ b/src/import/import-raw.c @@ -1,7 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "sd-daemon.h" #include "sd-event.h" @@ -18,6 +16,7 @@ #include "install-file.h" #include "io-util.h" #include "machine-pool.h" +#include "missing_fs.h" #include "mkdir-label.h" #include "path-util.h" #include "pretty-print.h" diff --git a/src/import/import-tar.c b/src/import/import-tar.c index e82159cb52..b95596c50c 100644 --- a/src/import/import-tar.c +++ b/src/import/import-tar.c @@ -1,7 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "sd-daemon.h" #include "sd-event.h" @@ -18,6 +16,7 @@ #include "install-file.h" #include "io-util.h" #include "machine-pool.h" +#include "missing_fs.h" #include "mkdir-label.h" #include "path-util.h" #include "pretty-print.h" diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c index f3e6b3af8c..ab2c6a0541 100644 --- a/src/import/pull-raw.c +++ b/src/import/pull-raw.c @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include #include #include "sd-daemon.h" @@ -17,6 +16,7 @@ #include "import-util.h" #include "install-file.h" #include "macro.h" +#include "missing_fs.h" #include "mkdir-label.h" #include "path-util.h" #include "pull-common.h" diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index 1a154d9275..40b4410060 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -29,6 +28,7 @@ #include "journal-internal.h" #include "lookup3.h" #include "memory-util.h" +#include "missing_fs.h" #include "path-util.h" #include "prioq.h" #include "random-util.h" diff --git a/src/mountfsd/mountwork.c b/src/mountfsd/mountwork.c index 96cea432ad..41a8736066 100644 --- a/src/mountfsd/mountwork.c +++ b/src/mountfsd/mountwork.c @@ -1,9 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#if WANT_LINUX_FS_H -#include -#endif #include #include "sd-daemon.h" @@ -20,7 +17,6 @@ #include "io-util.h" #include "json-util.h" #include "main-func.h" -#include "missing_mount.h" #include "missing_syscall.h" #include "namespace-util.h" #include "nsresource.h" diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 92724e53f8..1737d1ef0a 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -4,9 +4,6 @@ #include #include #include -#if HAVE_SELINUX -#include -#endif #include #include #include diff --git a/src/nsresourced/nsresourcework.c b/src/nsresourced/nsresourcework.c index f5b6a96d07..a088ff124e 100644 --- a/src/nsresourced/nsresourcework.c +++ b/src/nsresourced/nsresourcework.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -23,7 +24,6 @@ #include "lock-util.h" #include "main-func.h" #include "missing_magic.h" -#include "missing_mount.h" #include "missing_syscall.h" #include "mount-util.h" #include "mountpoint-util.h" diff --git a/src/nsresourced/test-userns-restrict.c b/src/nsresourced/test-userns-restrict.c index f509321ba8..d6df02428e 100644 --- a/src/nsresourced/test-userns-restrict.c +++ b/src/nsresourced/test-userns-restrict.c @@ -1,10 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include #include "fd-util.h" #include "main-func.h" -#include "missing_mount.h" #include "missing_syscall.h" #include "namespace-util.h" #include "process-util.h" diff --git a/src/nsresourced/userns-restrict.c b/src/nsresourced/userns-restrict.c index d57061e8fb..f23526c55f 100644 --- a/src/nsresourced/userns-restrict.c +++ b/src/nsresourced/userns-restrict.c @@ -5,13 +5,13 @@ #if HAVE_VMLINUX_H #include +#include #include "bpf-dlopen.h" #include "bpf-link.h" #include "fd-util.h" #include "fs-util.h" #include "lsm-util.h" -#include "missing_mount.h" #include "mkdir.h" #include "mount-util.h" #include "mountpoint-util.h" diff --git a/src/repart/repart.c b/src/repart/repart.c index 8833355024..dd81a9726d 100644 --- a/src/repart/repart.c +++ b/src/repart/repart.c @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -52,6 +51,7 @@ #include "logarithm.h" #include "loop-util.h" #include "main-func.h" +#include "missing_fs.h" #include "mkdir.h" #include "mkfs-util.h" #include "mount-util.h" diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c index 9ae22d8aa5..8f33691ca3 100644 --- a/src/shared/btrfs-util.c +++ b/src/shared/btrfs-util.c @@ -3,8 +3,6 @@ #include #include #include -#include -#include #include #include #include @@ -26,6 +24,7 @@ #include "fs-util.h" #include "io-util.h" #include "macro.h" +#include "missing_fs.h" #include "path-util.h" #include "rm-rf.h" #include "smack-util.h" diff --git a/src/shared/copy.c b/src/shared/copy.c index 6a008f2dbe..d780906ca9 100644 --- a/src/shared/copy.c +++ b/src/shared/copy.c @@ -2,7 +2,6 @@ #include #include -#include #include #include #include diff --git a/src/shared/discover-image.c b/src/shared/discover-image.c index d6afa53a6b..d545e0976a 100644 --- a/src/shared/discover-image.c +++ b/src/shared/discover-image.c @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -36,6 +35,7 @@ #include "log.h" #include "loop-util.h" #include "macro.h" +#include "missing_fs.h" #include "mkdir.h" #include "nulstr-util.h" #include "os-util.h" diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index b6563f9ab3..d9db618cf0 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -54,7 +54,6 @@ #include "import-util.h" #include "io-util.h" #include "json-util.h" -#include "missing_mount.h" #include "missing_syscall.h" #include "mkdir-label.h" #include "mount-util.h" diff --git a/src/shared/hibernate-util.c b/src/shared/hibernate-util.c index 658128d8bd..2aca788fb8 100644 --- a/src/shared/hibernate-util.c +++ b/src/shared/hibernate-util.c @@ -3,7 +3,6 @@ Copyright © 2018 Dell Inc. ***/ -#include #include #include #include @@ -21,6 +20,7 @@ #include "fileio.h" #include "hibernate-util.h" #include "log.h" +#include "missing_fs.h" #include "parse-util.h" #include "path-util.h" #include "proc-cmdline.h" diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index 3eba8dcb07..5b2c25067d 100644 --- a/src/shared/loop-util.c +++ b/src/shared/loop-util.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -27,6 +26,7 @@ #include "fs-util.h" #include "fileio.h" #include "loop-util.h" +#include "missing_fs.h" #include "parse-util.h" #include "path-util.h" #include "random-util.h" diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c index 3ff15a2214..b43ea73b9b 100644 --- a/src/shared/mount-util.c +++ b/src/shared/mount-util.c @@ -7,9 +7,6 @@ #include #include #include -#if WANT_LINUX_FS_H -#include -#endif #include "alloc-util.h" #include "chase.h" @@ -25,7 +22,6 @@ #include "initrd-util.h" #include "label-util.h" #include "libmount-util.h" -#include "missing_mount.h" #include "missing_syscall.h" #include "mkdir-label.h" #include "mount-util.h" diff --git a/src/shared/resize-fs.c b/src/shared/resize-fs.c index b1c4a49da1..47759a19c2 100644 --- a/src/shared/resize-fs.c +++ b/src/shared/resize-fs.c @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include #include #include diff --git a/src/test/test-mount-util.c b/src/test/test-mount-util.c index 33220abe71..ce6a43101e 100644 --- a/src/test/test-mount-util.c +++ b/src/test/test-mount-util.c @@ -10,7 +10,6 @@ #include "fs-util.h" #include "libmount-util.h" #include "missing_magic.h" -#include "missing_mount.h" #include "mkdir.h" #include "mount-util.h" #include "mountpoint-util.h" diff --git a/src/test/test-stat-util.c b/src/test/test-stat-util.c index e8091e048c..c5aacc32f1 100644 --- a/src/test/test-stat-util.c +++ b/src/test/test-stat-util.c @@ -12,7 +12,6 @@ #include "fd-util.h" #include "fs-util.h" #include "macro.h" -#include "missing_mount.h" #include "mount-util.h" #include "mountpoint-util.h" #include "namespace-util.h" diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 971e46a032..a3a36e99f4 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -45,6 +44,7 @@ #include "log.h" #include "macro.h" #include "main-func.h" +#include "missing_fs.h" #include "missing_syscall.h" #include "mkdir-label.h" #include "mount-util.h" diff --git a/src/udev/udev-builtin-btrfs.c b/src/udev/udev-builtin-btrfs.c index af711d8d88..b166b228f3 100644 --- a/src/udev/udev-builtin-btrfs.c +++ b/src/udev/udev-builtin-btrfs.c @@ -1,13 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include #include #include #include "device-util.h" #include "errno-util.h" #include "fd-util.h" +#include "missing_fs.h" #include "string-util.h" #include "strxcpyx.h" #include "udev-builtin.h" From e86a492ff08526e5adf85fa881c76f80adc3c84a Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 4 Mar 2025 03:11:58 +0900 Subject: [PATCH 36/36] dirent-util: introduce simple wrapper of posix_getdents() glibc exports getdents64 syscall as is, but musl exports it as posix_getdents(). Let's introduce a simple wrapper of posix_getdents(). Note, our baseline for glibc is 2.31. Hence, we can assume getdents64() always defined when building with glibc. --- meson.build | 2 +- src/basic/dirent-util.h | 8 ++++++++ src/basic/missing_syscall.h | 10 ---------- src/basic/recurse-dir.c | 3 +-- src/basic/stat-util.c | 3 +-- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/meson.build b/meson.build index 6ef51069d9..fdad63fd29 100644 --- a/meson.build +++ b/meson.build @@ -577,7 +577,7 @@ endforeach foreach ident : [ ['set_mempolicy', '''#include '''], # declared at numaif.h provided by libnuma, which we do not use ['get_mempolicy', '''#include '''], # declared at numaif.h provided by libnuma, which we do not use - ['getdents64', '''#include '''], # since glibc-2.30, but check it for musl + ['posix_getdents', '''#include '''], # glibc does not implement it, but musl does ['strerrorname_np', '''#include '''], # since glibc-2.32 ['mallinfo', '''#include '''], # deprecated since glibc-2.33, but check it for musl ['mallinfo2', '''#include '''], # since glibc-2.33 diff --git a/src/basic/dirent-util.h b/src/basic/dirent-util.h index 0a2fcbf957..816b28e04f 100644 --- a/src/basic/dirent-util.h +++ b/src/basic/dirent-util.h @@ -30,6 +30,14 @@ struct dirent *readdir_no_dot(DIR *dirp); continue; \ else +/* Musl provides posix_getdents(). But glibc does not, and provides their own implementation as getdents64(). + * Let's introduce a simple wrapper. */ +#if !HAVE_POSIX_GETDENTS +static inline ssize_t posix_getdents(int fd, void *buf, size_t nbyte, int flags) { + return getdents64(fd, buf, nbyte); +} +#endif + /* Maximum space one dirent structure might require at most */ #define DIRENT_SIZE_MAX CONST_MAX(sizeof(struct dirent), offsetof(struct dirent, d_name) + NAME_MAX + 1) diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index 53dcd69d9e..aae07a3f37 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -212,16 +212,6 @@ static inline int missing_close_range(unsigned first_fd, unsigned end_fd, unsign /* ======================================================================= */ -#if !HAVE_GETDENTS64 -static inline ssize_t missing_getdents64(int fd, void *buffer, size_t length) { - return syscall(__NR_getdents64, fd, buffer, length); -} - -# define getdents64 missing_getdents64 -#endif - -/* ======================================================================= */ - #if !HAVE_SCHED_SETATTR /* since kernel 3.14 (e6cfc0295c7d51b008999a8b13a44fb43f8685ea) */ static inline ssize_t missing_sched_setattr(pid_t pid, struct sched_attr *attr, unsigned int flags) { diff --git a/src/basic/recurse-dir.c b/src/basic/recurse-dir.c index 9612b7c6a5..31d19aef71 100644 --- a/src/basic/recurse-dir.c +++ b/src/basic/recurse-dir.c @@ -5,7 +5,6 @@ #include "fd-util.h" #include "fileio.h" #include "fs-util.h" -#include "missing_syscall.h" #include "mountpoint-util.h" #include "recurse-dir.h" #include "sort-util.h" @@ -51,7 +50,7 @@ int readdir_all(int dir_fd, RecurseDirFlags flags, DirectoryEntries **ret) { bs = MIN(MALLOC_SIZEOF_SAFE(de) - offsetof(DirectoryEntries, buffer), (size_t) SSIZE_MAX); assert(bs > de->buffer_size); - n = getdents64(dir_fd, (uint8_t*) de->buffer + de->buffer_size, bs - de->buffer_size); + n = posix_getdents(dir_fd, (uint8_t*) de->buffer + de->buffer_size, bs - de->buffer_size, /* flags = */ 0); if (n < 0) return -errno; if (n == 0) diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index 8ae588e2e1..f328f4a78c 100644 --- a/src/basic/stat-util.c +++ b/src/basic/stat-util.c @@ -19,7 +19,6 @@ #include "macro.h" #include "missing_fs.h" #include "missing_magic.h" -#include "missing_syscall.h" #include "mountpoint-util.h" #include "nulstr-util.h" #include "parse-util.h" @@ -172,7 +171,7 @@ int dir_is_empty_at(int dir_fd, const char *path, bool ignore_hidden_or_backup) struct dirent *de; ssize_t n; - n = getdents64(fd, buf, m); + n = posix_getdents(fd, buf, m, /* flags = */ 0); if (n < 0) return -errno; if (n == 0)