8ac5aef8f3
This change takes capsicum-test from upstream and applies some local changes to make the tests work on FreeBSD when executed via Kyua. The local modifications are as follows: 1. Make `OpenatTest.WithFlag` pass with the new dot-dot lookup behavior in FreeBSD 12.x+. 2. capsicum-test references a set of helper binaries: `mini-me`, `mini-me.noexec`, and `mini-me.setuid`, as part of the execve/fexecve tests, via execve, fexecve, and open. It achieves this upstream by assuming `mini-me*` is in the current directory, however, in order for Kyua to execute `capsicum-test`, it needs to provide a full path to `mini-me*`. In order to achieve this, I made `capsicum-test` cache the executable's path from argv[0] in main(..) and use the cached value to compute the path to `mini-me*` as part of the execve/fexecve testcases. 3. The capsicum-test test suite assumes that it's always being run on CAPABILITIES enabled kernels. However, there's a chance that the test will be run on a host without a CAPABILITIES enabled kernel, so we must check for the support before running the tests. The way to achieve this is to add the relevant `feature_present("security_capabilities")` check to SetupEnvironment::SetUp() and skip the tests when the support is not available. While here, add a check for `kern.trap_enotcap` being enabled. As noted by markj@ in https://github.com/google/capsicum-test/issues/23, this sysctl being enabled can trigger non-deterministic failures. Therefore, the tests should be skipped if this sysctl is enabled. All local changes have been submitted to the capsicum-test project (https://github.com/google/capsicum-test) and are in various stages of review. Please see the following pull requests for more details: 1. https://github.com/google/capsicum-test/pull/35 2. https://github.com/google/capsicum-test/pull/41 3. https://github.com/google/capsicum-test/pull/42 Reviewed by: asomers Discussed with: emaste, markj Approved by: emaste (mentor) MFC after: 2 months Differential Revision: https://reviews.freebsd.org/D19758
74 lines
2.0 KiB
C
74 lines
2.0 KiB
C
#ifndef __CAPSICUM_FREEBSD_H__
|
|
#define __CAPSICUM_FREEBSD_H__
|
|
#ifdef __FreeBSD__
|
|
/************************************************************
|
|
* FreeBSD Capsicum Functionality.
|
|
************************************************************/
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* FreeBSD definitions. */
|
|
#include <errno.h>
|
|
#include <sys/param.h>
|
|
#if __FreeBSD_version >= 1100014 || \
|
|
(__FreeBSD_version >= 1001511 && __FreeBSD_version < 1100000)
|
|
#include <sys/capsicum.h>
|
|
#else
|
|
#include <sys/capability.h>
|
|
#endif
|
|
#include <sys/procdesc.h>
|
|
|
|
#if __FreeBSD_version >= 1000000
|
|
#define AT_SYSCALLS_IN_CAPMODE
|
|
#define HAVE_CAP_RIGHTS_GET
|
|
#define HAVE_CAP_RIGHTS_LIMIT
|
|
#define HAVE_PROCDESC_FSTAT
|
|
#define HAVE_CAP_FCNTLS_LIMIT
|
|
// fcntl(2) takes int, cap_fcntls_limit(2) takes uint32_t.
|
|
typedef uint32_t cap_fcntl_t;
|
|
#define HAVE_CAP_IOCTLS_LIMIT
|
|
// ioctl(2) and cap_ioctls_limit(2) take unsigned long.
|
|
typedef unsigned long cap_ioctl_t;
|
|
|
|
#if __FreeBSD_version >= 1101000
|
|
#define HAVE_OPENAT_INTERMEDIATE_DOTDOT
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
// Use fexecve_() in tests to allow Linux variant to bypass glibc version.
|
|
#define fexecve_(F, A, E) fexecve(F, A, E)
|
|
|
|
#ifdef ENOTBENEATH
|
|
#define E_NO_TRAVERSE_CAPABILITY ENOTBENEATH
|
|
#define E_NO_TRAVERSE_O_BENEATH ENOTBENEATH
|
|
#else
|
|
#define E_NO_TRAVERSE_CAPABILITY ENOTCAPABLE
|
|
#define E_NO_TRAVERSE_O_BENEATH ENOTCAPABLE
|
|
#endif
|
|
|
|
// FreeBSD limits the number of ioctls in cap_ioctls_limit to 256
|
|
#define CAP_IOCTLS_LIMIT_MAX 256
|
|
|
|
// Too many links
|
|
#define E_TOO_MANY_LINKS EMLINK
|
|
|
|
// TODO(FreeBSD): uncomment if/when FreeBSD propagates rights on accept.
|
|
// FreeBSD does not generate a capability from accept(cap_fd,...).
|
|
// https://bugs.freebsd.org/201052
|
|
// #define CAP_FROM_ACCEPT
|
|
// TODO(FreeBSD): uncomment if/when FreeBSD propagates rights on sctp_peeloff.
|
|
// FreeBSD does not generate a capability from sctp_peeloff(cap_fd,...).
|
|
// https://bugs.freebsd.org/201052
|
|
// #define CAP_FROM_PEELOFF
|
|
|
|
#endif /* __FreeBSD__ */
|
|
|
|
#endif /*__CAPSICUM_FREEBSD_H__*/
|