From bf7fdfa96eb5d052b0535a6ce0d3179a770830f9 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Wed, 3 Dec 2014 20:39:20 +0000 Subject: [PATCH] Make parsers of capget and capset syscalls self-contained Various versions of used to require different workarounds to avoid conflicts with types defined by libc headers. Define all required types and constants locally to fix this issue. * configure.ac (AC_CHECK_HEADERS): Remove linux/capability.h. * capability.c: Do not include , remove workarounds for problematic versions of file. Define CAP_* and _LINUX_CAPABILITY_VERSION_* constants as enums. (struct __user_cap_header_struct, struct __user_cap_data_struct): Define. * xlat/cap_version.in: Add #unconditional. * xlat/capabilities.in: Likewise. --- capability.c | 84 ++++++++++++++++++++++++++------------------ configure.ac | 1 - xlat/cap_version.in | 1 + xlat/capabilities.in | 1 + 4 files changed, 52 insertions(+), 35 deletions(-) diff --git a/capability.c b/capability.c index 18a5691c..3c7666fc 100644 --- a/capability.c +++ b/capability.c @@ -1,31 +1,61 @@ #include "defs.h" -#define _LINUX_SOCKET_H -#define _LINUX_FS_H - -#include -#include -#include -#ifdef HAVE_LINUX_CAPABILITY_H -# include -#endif - -#ifdef SYS_capget +enum { + CAP_CHOWN, + CAP_DAC_OVERRIDE, + CAP_DAC_READ_SEARCH, + CAP_FOWNER, + CAP_FSETID, + CAP_KILL, + CAP_SETGID, + CAP_SETUID, + CAP_SETPCAP, + CAP_LINUX_IMMUTABLE, + CAP_NET_BIND_SERVICE, + CAP_NET_BROADCAST, + CAP_NET_ADMIN, + CAP_NET_RAW, + CAP_IPC_LOCK, + CAP_IPC_OWNER, + CAP_SYS_MODULE, + CAP_SYS_RAWIO, + CAP_SYS_CHROOT, + CAP_SYS_PTRACE, + CAP_SYS_PACCT, + CAP_SYS_ADMIN, + CAP_SYS_BOOT, + CAP_SYS_NICE, + CAP_SYS_RESOURCE, + CAP_SYS_TIME, + CAP_SYS_TTY_CONFIG, + CAP_MKNOD, + CAP_LEASE, + CAP_AUDIT_WRITE, + CAP_AUDIT_CONTROL, + CAP_SETFCAP +}; #include "xlat/capabilities.h" -#ifndef _LINUX_CAPABILITY_VERSION_1 -# define _LINUX_CAPABILITY_VERSION_1 0x19980330 -#endif -#ifndef _LINUX_CAPABILITY_VERSION_2 -# define _LINUX_CAPABILITY_VERSION_2 0x20071026 -#endif -#ifndef _LINUX_CAPABILITY_VERSION_3 -# define _LINUX_CAPABILITY_VERSION_3 0x20080522 -#endif +enum { + _LINUX_CAPABILITY_VERSION_1 = 0x19980330, + _LINUX_CAPABILITY_VERSION_2 = 0x20071026, + _LINUX_CAPABILITY_VERSION_3 = 0x20080522 +}; #include "xlat/cap_version.h" +typedef struct user_cap_header_struct { + uint32_t version; + int pid; +} *cap_user_header_t; + +typedef struct user_cap_data_struct { + uint32_t effective; + uint32_t permitted; + uint32_t inheritable; +} *cap_user_data_t; + static void print_cap_header(struct tcb *tcp, unsigned long addr) { @@ -92,17 +122,3 @@ sys_capset(struct tcb *tcp) } return 0; } - -#else - -int sys_capget(struct tcb *tcp) -{ - return printargs(tcp); -} - -int sys_capset(struct tcb *tcp) -{ - return printargs(tcp); -} - -#endif diff --git a/configure.ac b/configure.ac index aec1d47d..8dba8afd 100644 --- a/configure.ac +++ b/configure.ac @@ -232,7 +232,6 @@ AC_CHECK_HEADERS(m4_normalize([ elf.h inttypes.h ioctls.h - linux/capability.h linux/perf_event.h linux/ptrace.h linux/utsname.h diff --git a/xlat/cap_version.in b/xlat/cap_version.in index 70d6caee..3d5b7446 100644 --- a/xlat/cap_version.in +++ b/xlat/cap_version.in @@ -1,3 +1,4 @@ +#unconditional _LINUX_CAPABILITY_VERSION_1 _LINUX_CAPABILITY_VERSION_2 _LINUX_CAPABILITY_VERSION_3 diff --git a/xlat/capabilities.in b/xlat/capabilities.in index 59f24f74..4c48b847 100644 --- a/xlat/capabilities.in +++ b/xlat/capabilities.in @@ -1,3 +1,4 @@ +#unconditional 1<