-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add linux/securebits.h to CentOS docker container, to have it present in linux build artifacts And exclude the .git folder from format checks. (The branch name ending in ".h" causes false positives.) Signed-off-by: Bob Weinand <[email protected]> * Handle an additional case of capabilities being dropped within our background sender (#1287) This specific case occurs (at least) when the thread was cloned after a setuid(2) call after prctl(PR_SET_KEEPCAPS, 1): the effective capability set will be empty, but the permitted set of capabilities contains all capabilities we need. Signed-off-by: Bob Weinand <[email protected]> * Version bump 0.62.1 Signed-off-by: Bob Weinand <[email protected]>
- Loading branch information
Showing
10 changed files
with
143 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#ifndef PHP_DDTRACE_VERSION | ||
// Must begin with a number for Debian packaging requirements | ||
#define PHP_DDTRACE_VERSION "0.62.0" | ||
#define PHP_DDTRACE_VERSION "0.62.1" | ||
#endif |
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
76 changes: 76 additions & 0 deletions
76
tests/ext/background-sender/background_sender_restores_capabilities.phpt
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 @@ | ||
--TEST-- | ||
background sender restores effective capabilities from permitted set | ||
--DESCRIPTION-- | ||
The effective set may be cleared, e.g. when prctl(PR_SET_KEEPCAPS), followed by setuid(2) has been used. | ||
Hence we exec() ourselves on top of a process with no effective capabilities. | ||
--SKIPIF-- | ||
<?php if (PHP_OS != "Linux") die('skip: Linux specific test for capabilities(7)'); ?> | ||
<?php if (!extension_loaded("ffi")) die("skip: requires ext/ffi"); ?> | ||
<?php if (posix_getuid() != 0 && getenv("ZEND_DONT_UNLOAD_MODULES")) die("skip: detected ZEND_DONT_UNLOAD_MODULES - the test is most likely executed as non-root via valgrind"); ?> | ||
<?php if (posix_getuid() != 0 && trim(shell_exec("sudo echo 1")) !== "1") die("skip: user is not root and has no password-less sudo"); ?> | ||
--FILE-- | ||
<?php | ||
|
||
if (posix_getuid() != 0) { | ||
$sudoPath = trim(`which sudo`); | ||
$cmdAndArgs = explode("\0", file_get_contents("/proc/" . getmypid() . "/cmdline")); | ||
pcntl_exec($sudoPath, [-2 => '-E', -1 => '--'] + $cmdAndArgs); | ||
} | ||
|
||
$ffi = FFI::cdef(<<<DEFS | ||
int setgroups(size_t size, const uint32_t *list); | ||
typedef struct { | ||
uint32_t version; | ||
int pid; | ||
} cap_user_header_t; | ||
typedef struct { | ||
uint32_t effective; | ||
uint32_t permitted; | ||
uint32_t inheritable; | ||
} cap_user_data_t; | ||
int capset(cap_user_header_t *hdrp, const cap_user_data_t *datap); | ||
DEFS | ||
, "libc.so.6"); | ||
|
||
const _LINUX_CAPABILITY_VERSION_1 = 0x19980330; | ||
const CAP_SETGID = 6; | ||
|
||
$capheader = $ffi->new("cap_user_header_t"); | ||
$capheader->version = _LINUX_CAPABILITY_VERSION_1; | ||
|
||
$capdata = $ffi->new("cap_user_data_t"); | ||
$capdata->inheritable = 0; | ||
$capdata->effective = 0; | ||
$capdata->permitted = 1 << CAP_SETGID; | ||
|
||
if (!getenv("BACKGROUND_SENDER_RESTORES_CAPABILITIES")) { | ||
$ffi->capset(FFI::addr($capheader), FFI::addr($capdata)); | ||
|
||
putenv("BACKGROUND_SENDER_RESTORES_CAPABILITIES=1"); | ||
$cmdAndArgs = explode("\0", file_get_contents("/proc/" . getmypid() . "/cmdline")); | ||
pcntl_exec(array_shift($cmdAndArgs), $cmdAndArgs); | ||
|
||
die("exec failed?"); | ||
} | ||
|
||
$capdata->effective = $capdata->permitted; | ||
$ffi->capset(FFI::addr($capheader), FFI::addr($capdata)); | ||
|
||
$groups = $ffi->new("uint32_t"); | ||
$groups->cdata = 1; | ||
var_dump($ffi->setgroups(1, FFI::addr($groups))); | ||
|
||
// payload = [[]] | ||
$payload = "\x91\x90"; | ||
|
||
var_dump(dd_trace_send_traces_via_thread(1, [], $payload)); | ||
|
||
echo "Done."; | ||
?> | ||
--EXPECT-- | ||
int(0) | ||
bool(true) | ||
Done. |