Skip to content

Commit

Permalink
Make parsers of capget and capset syscalls self-contained
Browse files Browse the repository at this point in the history
Various versions of <linux/capability.h> 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 <linux/capability.h>, remove workarounds
for problematic versions of <linux/capability.h> 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.
  • Loading branch information
ldv-alt committed Dec 6, 2014
1 parent 83034c9 commit bf7fdfa
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 35 deletions.
84 changes: 50 additions & 34 deletions capability.c
@@ -1,31 +1,61 @@
#include "defs.h"

#define _LINUX_SOCKET_H
#define _LINUX_FS_H

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#ifdef HAVE_LINUX_CAPABILITY_H
# include <linux/capability.h>
#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)
{
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion configure.ac
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions xlat/cap_version.in
@@ -1,3 +1,4 @@
#unconditional
_LINUX_CAPABILITY_VERSION_1
_LINUX_CAPABILITY_VERSION_2
_LINUX_CAPABILITY_VERSION_3
1 change: 1 addition & 0 deletions xlat/capabilities.in
@@ -1,3 +1,4 @@
#unconditional
1<<CAP_CHOWN
1<<CAP_DAC_OVERRIDE
1<<CAP_DAC_READ_SEARCH
Expand Down

0 comments on commit bf7fdfa

Please sign in to comment.