forked from GerbilSoft/rom-properties
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[librpsecure] New consolidated security library.
The os-secure files from rpcli and rp-download have been consolidated into a single library. seccomp-debug.h has also been moved here and converted into a .c file with a public interface in the .h file. rpcli and rp-download can now call rp_secure_enable() with an OS-specific parameter. A struct is provided that makes the parameter type-safe. NOTE: syscall_wl (seccomp syscall whitelist) can't be NULL-terminated, since syscall 0 is valid on most architectures. On x86, it's read(). Hence, we're specifying an explicit array size. Also moved the Win32 security options and integrity level files here. Updated Win32 code for this change. integrity_level.c: Removed the pthread_once() usage for the Windows Vista check, since we're not linking to librpthreads. The worst that could happen is both threads set isVista to the same value. [cmake] Adjusted security options: - USE_SECCOMP: Moved from cmake/options.cmake to librpsecure/CMakeLists.txt. - ENABLE_SECCOMP_DEBUG: Added to librpsecure/CMakeLists.txt. Replaces the hard-coded SECCOMP_DEBUG in seccomp-debug.h. [svrplus] Removed the libwin32common dependency. It was only used for the Windows security options, and that's now handled by librpsecure. [tests] Updated gtest_init.cpp to use librpsecure. Link all test suites to librpsecure instead of libwin32common. - TODO: seccomp() on Linux, pledge() on OpenBSD.
- Loading branch information
1 parent
fb62b29
commit 6234bd0
Showing
43 changed files
with
588 additions
and
666 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Security functionality. | ||
PROJECT(librpsecure) | ||
|
||
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") | ||
OPTION(USE_SECCOMP "Use libseccomp filters in rp-download and rpcli." ON) | ||
OPTION(ENABLE_SECCOMP_DEBUG "Enable libseccomp debugging." OFF) | ||
ELSE() | ||
SET(USE_SECCOMP OFF CACHE INTERNAL "Use libseccomp filters in rp-download and rpcli." FORCE) | ||
SET(ENABLE_SECCOMP_DEBUG OFF CACHE INTERNAL "Enable libseccomp debugging." FORCE) | ||
ENDIF() | ||
|
||
IF(WIN32) | ||
SET(librpsecure_SRCS | ||
win32/integrity_level.c | ||
win32/secoptions.c | ||
) | ||
SET(librpsecure_H | ||
os-secure.h | ||
win32/integrity_level.h | ||
win32/secoptions.h | ||
win32/secoptions_win8.h | ||
) | ||
SET(librpsecure_OS_SRCS os-secure_win32.c) | ||
ELSEIF(UNIX AND NOT APPLE) | ||
# Check for system security functionality. | ||
IF(USE_SECCOMP) | ||
# Linux: Use seccomp(). | ||
FIND_PACKAGE(Seccomp REQUIRED) | ||
IF(SECCOMP_FOUND) | ||
SET(librpsecure_OS_SRCS os-secure_linux.c) | ||
IF(ENABLE_SECCOMP_DEBUG) | ||
SET(librpsecure_OS_SRCS ${librpsecure_OS_SRCS} seccomp-debug.c) | ||
SET(librpsecure_OS_H ${librpsecure_OS_H} seccomp-debug.h) | ||
ENDIF(ENABLE_SECCOMP_DEBUG) | ||
SET(HAVE_SECCOMP 1) | ||
ENDIF(SECCOMP_FOUND) | ||
ELSE() | ||
# OpenBSD: Use pledge()/tame(). | ||
INCLUDE(CheckOpenBSDPledge) | ||
CHECK_OPENBSD_PLEDGE() | ||
IF(HAVE_PLEDGE OR HAVE_TAME) | ||
SET(librpsecure_OS_SRCS os-secure_openbsd.c) | ||
ENDIF() | ||
ENDIF() | ||
ENDIF() | ||
|
||
IF(NOT librpsecure_OS_SRCS) | ||
# TODO: Add support for other systems. | ||
SET(librpsecure_OS_SRCS os-secure_dummy.c) | ||
ENDIF(NOT librpsecure_OS_SRCS) | ||
|
||
# Write the config.h file. | ||
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/config.librpsecure.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config.librpsecure.h") | ||
|
||
###################### | ||
# Build the library. # | ||
###################### | ||
|
||
ADD_LIBRARY(rpsecure STATIC | ||
${librpsecure_SRCS} | ||
${librpsecure_H} | ||
${librpsecure_OS_SRCS} | ||
${librpsecure_OS_H} | ||
) | ||
INCLUDE(SetMSVCDebugPath) | ||
SET_MSVC_DEBUG_PATH(rpsecure) | ||
# Exclude from ALL builds. | ||
SET_TARGET_PROPERTIES(rpsecure PROPERTIES EXCLUDE_FROM_ALL TRUE) | ||
IF(USE_SECCOMP AND SECCOMP_FOUND) | ||
TARGET_LINK_LIBRARIES(rpsecure PUBLIC Seccomp::seccomp) | ||
ENDIF(USE_SECCOMP AND SECCOMP_FOUND) | ||
|
||
TARGET_INCLUDE_DIRECTORIES(rpsecure | ||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> # librpsecure | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> # librpsecure | ||
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..> # src | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/..> # src | ||
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/*************************************************************************** | ||
* ROM Properties Page shell extension. (librpsecure) * | ||
* config.librpsecure.h.in: librpsecure configuration. (source file) * | ||
* * | ||
* Copyright (c) 2016-2020 by David Korth. * | ||
* SPDX-License-Identifier: GPL-2.0-or-later * | ||
***************************************************************************/ | ||
|
||
#ifndef __ROMPROPERTIES_LIBRPSECURE_CONFIG_H__ | ||
#define __ROMPROPERTIES_LIBRPSECURE_CONFIG_H__ | ||
|
||
/* Define to 1 if you have the OpenBSD 5.8 `tame` function. */ | ||
#cmakedefine HAVE_TAME 1 | ||
|
||
/* Define to 1 if you have the OpenBSD 5.9+ `pledge` function. */ | ||
#cmakedefine HAVE_PLEDGE 1 | ||
|
||
/* Define to 1 if you have the OpenBSD 6.3+ `pledge` function with `execpromises`. */ | ||
#cmakedefine HAVE_PLEDGE_EXECPROMISES 1 | ||
|
||
/* Define to 1 if you have the Linux `seccomp` library. */ | ||
#cmakedefine HAVE_SECCOMP 1 | ||
|
||
/* Define to 1 to enable seccomp debugging. */ | ||
#cmakedefine ENABLE_SECCOMP_DEBUG 1 | ||
|
||
#endif /* __ROMPROPERTIES_LIBRPSECURE_CONFIG_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/*************************************************************************** | ||
* ROM Properties Page shell extension. (librpsecure) * | ||
* os-secure.h: OS security functions. * | ||
* * | ||
* Copyright (c) 2016-2020 by David Korth. * | ||
* SPDX-License-Identifier: GPL-2.0-or-later * | ||
***************************************************************************/ | ||
|
||
#ifndef __ROMPROPERTIES_LIBRPSECURE_OS_SECURE_H__ | ||
#define __ROMPROPERTIES_LIBRPSECURE_OS_SECURE_H__ | ||
|
||
#include "config.librpsecure.h" | ||
|
||
#ifdef _WIN32 | ||
# include <windows.h> | ||
#else /* !_WIN32 */ | ||
# include <unistd.h> | ||
# ifdef HAVE_SECCOMP | ||
# include <seccomp.h> | ||
# elif HAVE_TAME | ||
# include <sys/tame.h> | ||
# endif | ||
#endif /* _WIN32 */ | ||
|
||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* Reduce the process integrity level to Low. | ||
* (Windows only; no-op on other platforms.) | ||
* @return 0 on success; negative POSIX error code on error. | ||
*/ | ||
#ifdef _WIN32 | ||
int rp_secure_reduce_integrity(void); | ||
#else /* !_WIN32 */ | ||
static inline int rp_secure_reduce_integrity(void) | ||
{ | ||
return 0; | ||
} | ||
#endif /* _WIN32 */ | ||
|
||
/** | ||
* OS-specific security parameter. | ||
* | ||
* NOTE: This should be sizeof(void*) or less so it can be | ||
* passed by value. | ||
*/ | ||
typedef struct _rp_secure_param_t { | ||
#if defined(_WIN32) | ||
BOOL bHighSec; // High security mode | ||
#elif defined(HAVE_SECCOMP) | ||
const int *syscall_wl; // Array of allowed syscalls. (-1 terminated) | ||
#elif defined(HAVE_PLEDGE) | ||
const char *promises; // pledge() promises | ||
#elif defined(HAVE_TAME) | ||
int tame_flags; // tame() flags | ||
#else | ||
# warning rp_secure_enable() not implemented for this OS | ||
int dummy; // to prevent having an empty struct | ||
#endif | ||
} rp_secure_param_t; | ||
|
||
/** | ||
* Enable OS-specific security functionality. | ||
* @param param OS-specific parameter. | ||
* @return 0 on success; negative POSIX error code on error. | ||
*/ | ||
int rp_secure_enable(rp_secure_param_t param); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* __ROMPROPERTIES_LIBRPSECURE_OS_SECURE_H__ */ |
Oops, something went wrong.