Release pledge.com 1.7 and landlockmake.com 1.3

- pledge("chown") now supported
- pledge("stdio") now allows killing self
- Write tests for pselect() and ppoll()
This commit is contained in:
Justine Tunney 2022-08-15 19:52:00 -07:00
parent 255d834f8f
commit ce588dd56b
19 changed files with 190 additions and 39 deletions

View file

@ -17,7 +17,9 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/pledge.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/kprintf.h"
#include "libc/log/libfatal.internal.h"
#include "libc/nexgen32e/rdtsc.h"
@ -39,10 +41,21 @@
#include "tool/decode/lib/flagger.h"
#include "tool/decode/lib/pollnames.h"
bool gotsig;
void SetUpOnce(void) {
__pledge_mode = PLEDGE_PENALTY_KILL_PROCESS | PLEDGE_STDERR_LOGGING;
ASSERT_SYS(0, 0, pledge("stdio proc inet", 0));
}
void SetUp(void) {
gotsig = false;
}
void OnSig(int sig) {
gotsig = true;
}
dontdiscard char *FormatPollFd(struct pollfd p[2]) {
return xasprintf("fd:%d revents:%s\n"
"fd:%d revents:%s\n",
@ -50,10 +63,32 @@ dontdiscard char *FormatPollFd(struct pollfd p[2]) {
p[1].fd, gc(RecreateFlags(kPollNames, p[1].revents)));
}
TEST(poll, allZero_doesNothing_exceptValidateAndCheckForSignals) {
TEST(poll, allZero_doesNothingPrettyMuch) {
EXPECT_SYS(0, 0, poll(0, 0, 0));
}
TEST(ppoll, weCanProveItChecksForSignals) {
if (IsXnu()) return;
if (IsNetbsd()) return;
int pipefds[2];
sigset_t set, old;
struct sigaction oldss;
struct sigaction sa = {.sa_handler = OnSig};
EXPECT_SYS(0, 0, pipe(pipefds));
struct pollfd fds[] = {{pipefds[0], POLLIN}};
ASSERT_SYS(0, 0, sigaction(SIGUSR1, &sa, &oldss));
ASSERT_SYS(0, 0, sigfillset(&set));
ASSERT_SYS(0, 0, sigprocmask(SIG_SETMASK, &set, &old));
EXPECT_SYS(0, 0, kill(getpid(), SIGUSR1));
EXPECT_FALSE(gotsig);
EXPECT_SYS(EINTR, -1, ppoll(fds, 1, 0, &old));
EXPECT_TRUE(gotsig);
EXPECT_SYS(0, 0, sigprocmask(SIG_SETMASK, &old, 0));
EXPECT_SYS(0, 0, sigaction(SIGUSR1, &oldss, 0));
EXPECT_SYS(0, 0, close(pipefds[0]));
EXPECT_SYS(0, 0, close(pipefds[1]));
}
TEST(poll, testNegativeOneFd_isIgnored) {
ASSERT_SYS(0, 3, socket(AF_INET, SOCK_STREAM, IPPROTO_TCP));
struct sockaddr_in addr = {AF_INET, 0, {htonl(INADDR_LOOPBACK)}};

View file

@ -48,6 +48,7 @@ TEST_LIBC_CALLS_DIRECTDEPS = \
LIBC_TESTLIB \
LIBC_X \
LIBC_ZIPOS \
TOOL_DECODE_LIB \
THIRD_PARTY_XED
TEST_LIBC_CALLS_DEPS := \
@ -96,6 +97,9 @@ o/$(MODE)/test/libc/calls/life-classic.com.zip.o: private \
o/$(MODE)/test/libc/calls/ioctl_siocgifconf_test.com.runs: \
private .PLEDGE =
o/$(MODE)/test/libc/calls/poll_test.com.runs: \
private .PLEDGE = stdio rpath wpath cpath fattr proc inet
.PHONY: o/$(MODE)/test/libc/calls
o/$(MODE)/test/libc/calls: \
$(TEST_LIBC_CALLS_BINS) \

View file

View file

@ -17,20 +17,47 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/pledge.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/sigset.h"
#include "libc/calls/struct/timeval.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/select.h"
#include "libc/sock/sock.h"
#include "libc/sysv/consts/sig.h"
#include "libc/testlib/testlib.h"
#include "libc/time/time.h"
bool gotsig;
void SetUpOnce(void) {
__pledge_mode = PLEDGE_PENALTY_KILL_PROCESS | PLEDGE_STDERR_LOGGING;
ASSERT_SYS(0, 0, pledge("stdio", 0));
}
// TEST(select, allZero) {
// // todo: figure out how to test block until signal w/ select
// EXPECT_SYS(0, 0, select(0, 0, 0, 0, 0));
// }
void SetUp(void) {
gotsig = false;
}
void OnSig(int sig) {
gotsig = true;
}
TEST(select, allZero1) {
sigset_t set, old;
struct sigaction oldss;
struct sigaction sa = {.sa_handler = OnSig};
ASSERT_SYS(0, 0, sigaction(SIGQUIT, &sa, &oldss));
ASSERT_SYS(0, 0, sigfillset(&set));
ASSERT_SYS(0, 0, sigprocmask(SIG_SETMASK, &set, &old));
EXPECT_SYS(0, 0, kill(getpid(), SIGQUIT));
EXPECT_SYS(EINTR, -1, pselect(0, 0, 0, 0, 0, &old));
EXPECT_TRUE(gotsig);
EXPECT_SYS(0, 0, sigprocmask(SIG_SETMASK, &old, 0));
EXPECT_SYS(0, 0, sigaction(SIGQUIT, &oldss, 0));
}
TEST(select, pipe_hasInputFromSameProcess) {
fd_set rfds;