}
key = add_key(argv[1], argv[2], argv[3], strlen(argv[3]),
- KEY_SPEC_SESSION_KEYRING);
+ KEY_SPEC_SESSION_KEYRING);
if (key == \-1) {
perror("add_key");
exit(EXIT_FAILURE);
sizeof(my_addr.sun_path) \- 1);
if (bind(sfd, (struct sockaddr *) &my_addr,
- sizeof(my_addr)) == \-1)
+ sizeof(my_addr)) == \-1)
handle_error("bind");
if (listen(sfd, LISTEN_BACKLOG) == \-1)
}
printf("%\-15s: %10jd.%03ld (", name,
- (intmax_t) ts.tv_sec, ts.tv_nsec / 1000000);
+ (intmax_t) ts.tv_sec, ts.tv_nsec / 1000000);
long days = ts.tv_sec / SECS_IN_DAY;
if (days > 0)
printf("%ld days + ", days);
printf("%2dh %2dm %2ds",
- (int) (ts.tv_sec % SECS_IN_DAY) / 3600,
- (int) (ts.tv_sec % 3600) / 60,
- (int) ts.tv_sec % 60);
+ (int) (ts.tv_sec % SECS_IN_DAY) / 3600,
+ (int) (ts.tv_sec % 3600) / 60,
+ (int) ts.tv_sec % 60);
printf(")\en");
if (clock_getres(clock, &ts) == \-1) {
if (showRes)
printf(" resolution: %10jd.%09ld\en",
- (intmax_t) ts.tv_sec, ts.tv_nsec);
+ (intmax_t) ts.tv_sec, ts.tv_nsec);
}
int
ones suffixed "_PRIVATE"). */
iaddr = mmap(NULL, sizeof(*iaddr) * 2, PROT_READ | PROT_WRITE,
- MAP_ANONYMOUS | MAP_SHARED, \-1, 0);
+ MAP_ANONYMOUS | MAP_SHARED, \-1, 0);
if (iaddr == MAP_FAILED)
errExit("mmap");
(d_type == DT_BLK) ? "block dev" :
(d_type == DT_CHR) ? "char dev" : "???");
printf("%4d %10jd %s\en", d\->d_reclen,
- (intmax_t) d\->d_off, d\->d_name);
+ (intmax_t) d\->d_off, d\->d_name);
bpos += d\->d_reclen;
}
}
if (prlimit(pid, RLIMIT_CPU, newp, &old) == \-1)
errExit("prlimit\-1");
printf("Previous limits: soft=%jd; hard=%jd\en",
- (intmax_t) old.rlim_cur, (intmax_t) old.rlim_max);
+ (intmax_t) old.rlim_cur, (intmax_t) old.rlim_max);
/* Retrieve and display new CPU time limit */
if (prlimit(pid, RLIMIT_CPU, NULL, &old) == \-1)
errExit("prlimit\-2");
printf("New limits: soft=%jd; hard=%jd\en",
- (intmax_t) old.rlim_cur, (intmax_t) old.rlim_max);
+ (intmax_t) old.rlim_cur, (intmax_t) old.rlim_max);
exit(EXIT_SUCCESS);
}
if (userns_fd == \-1) {
if (errno == EPERM)
printf("The owning user namespace is outside "
- "your namespace scope\en");
+ "your namespace scope\en");
else
perror("ioctl\-NS_GET_USERNS");
exit(EXIT_FAILURE);
exit(EXIT_FAILURE);
}
printf("Device/Inode of owning user namespace is: "
- "[%jx,%jx] / %ju\en",
- (uintmax_t) major(sb.st_dev),
- (uintmax_t) minor(sb.st_dev),
- (uintmax_t) sb.st_ino);
+ "[%jx,%jx] / %ju\en",
+ (uintmax_t) major(sb.st_dev),
+ (uintmax_t) minor(sb.st_dev),
+ (uintmax_t) sb.st_ino);
close(userns_fd);
}
if (parent_fd == \-1) {
if (errno == EINVAL)
printf("Can\(aq get parent namespace of a "
- "nonhierarchical namespace\en");
+ "nonhierarchical namespace\en");
else if (errno == EPERM)
printf("The parent namespace is outside "
- "your namespace scope\en");
+ "your namespace scope\en");
else
perror("ioctl\-NS_GET_PARENT");
exit(EXIT_FAILURE);
exit(EXIT_FAILURE);
}
printf("Device/Inode of parent namespace is: [%jx,%jx] / %ju\en",
- (uintmax_t) major(sb.st_dev),
- (uintmax_t) minor(sb.st_dev),
- (uintmax_t) sb.st_ino);
+ (uintmax_t) major(sb.st_dev),
+ (uintmax_t) minor(sb.st_dev),
+ (uintmax_t) sb.st_ino);
close(parent_fd);
}
{
printf("\et%s\en", msg);
printf("\et\etkcmp(%jd, %jd, KCMP_FILE, %d, %d) ==> %s\en",
- (intmax_t) pid1, (intmax_t) pid2, fd_a, fd_b,
- (kcmp(pid1, pid2, KCMP_FILE, fd_a, fd_b) == 0) ?
+ (intmax_t) pid1, (intmax_t) pid2, fd_a, fd_b,
+ (kcmp(pid1, pid2, KCMP_FILE, fd_a, fd_b) == 0) ?
"same" : "different");
}
printf("PID of child of fork() is %jd\en", (intmax_t) getpid());
test_kcmp("Compare duplicate FDs from different processes:",
- getpid(), getppid(), fd1, fd1);
+ getpid(), getppid(), fd1, fd1);
fd2 = open(pathname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (fd2 == \-1)
printf("Child opened file on FD %d\en", fd2);
test_kcmp("Compare FDs from distinct open()s in same process:",
- getpid(), getpid(), fd1, fd2);
+ getpid(), getpid(), fd1, fd2);
fd3 = dup(fd1);
if (fd3 == \-1)
printf("Child duplicated FD %d to create FD %d\en", fd1, fd3);
test_kcmp("Compare duplicated FDs in same process:",
- getpid(), getpid(), fd1, fd3);
+ getpid(), getpid(), fd1, fd3);
break;
default:
* Fetch the description of the key that is to be instantiated.
*/
if (keyctl(KEYCTL_DESCRIBE, key_to_instantiate,
- dbuf, sizeof(dbuf)) == \-1) {
+ dbuf, sizeof(dbuf)) == \-1) {
fprintf(fp, "KEYCTL_DESCRIBE failed: %s\en", strerror(errno));
exit(EXIT_FAILURE);
}
* display it.
*/
auth_key = keyctl(KEYCTL_GET_KEYRING_ID,
- KEY_SPEC_REQKEY_AUTH_KEY);
+ KEY_SPEC_REQKEY_AUTH_KEY);
if (auth_key == \-1) {
fprintf(fp, "KEYCTL_GET_KEYRING_ID failed: %s\en",
strerror(errno));
* string representing the ID of the key to be instantiated.
*/
if (keyctl(KEYCTL_DESCRIBE, KEY_SPEC_REQKEY_AUTH_KEY,
- dbuf, sizeof(dbuf)) == \-1) {
+ dbuf, sizeof(dbuf)) == \-1)
+ {
fprintf(fp, "KEYCTL_DESCRIBE failed: %s\en", strerror(errno));
exit(EXIT_FAILURE);
}
* in the payload of the authorization key.
*/
if (keyctl(KEYCTL_INSTANTIATE, key_to_instantiate,
- auth_key_payload, akp_size + 1, dest_keyring) == \-1) {
+ auth_key_payload, akp_size + 1, dest_keyring) == \-1)
+ {
fprintf(fp, "KEYCTL_INSTANTIATE failed: %s\en",
strerror(errno));
exit(EXIT_FAILURE);
errExit("truncate");
printf("PID: %jd; fd: %d; /proc/%jd/fd/%d\en",
- (intmax_t) getpid(), fd, (intmax_t) getpid(), fd);
+ (intmax_t) getpid(), fd, (intmax_t) getpid(), fd);
/* Code to map the file and populate the mapping with data
omitted. */
printf("Start of region: %p\en", buffer);
if (mprotect(buffer + pagesize * 2, pagesize,
- PROT_READ) == \-1)
+ PROT_READ) == \-1)
handle_error("mprotect");
for (char *p = buffer ; ; )
time(&t);
snprintf(msg.mtext, sizeof(msg.mtext), "a message at %s",
- ctime(&t));
+ ctime(&t));
if (msgsnd(qid, &msg, sizeof(msg.mtext),
- IPC_NOWAIT) == \-1) {
+ IPC_NOWAIT) == \-1)
+ {
perror("msgsnd error");
exit(EXIT_FAILURE);
}
flags = 0; /* For name_to_handle_at() calls */
fhp\->handle_bytes = 0;
if (name_to_handle_at(dirfd, pathname, fhp,
- &mount_id, flags) != \-1 || errno != EOVERFLOW) {
+ &mount_id, flags) != \-1
+ || errno != EOVERFLOW)
+ {
fprintf(stderr, "Unexpected result from name_to_handle_at()\en");
exit(EXIT_FAILURE);
}
Line 2: <handle_bytes> <handle_type> <bytes of handle in hex>
*/
- if ((fgets(line1, sizeof(line1), stdin) == NULL) ||
- (fgets(line2, sizeof(line2), stdin) == NULL)) {
+ if (fgets(line1, sizeof(line1), stdin) == NULL ||
+ fgets(line2, sizeof(line2), stdin) == NULL)
+ {
fprintf(stderr, "Missing mount_id / file handle\en");
exit(EXIT_FAILURE);
}
int ret;
ret = syscall(SYS_perf_event_open, hw_event, pid, cpu,
- group_fd, flags);
+ group_fd, flags);
return ret;
}
}
printf("Events (%#x): POLLIN is %sset\en", pollfd.revents,
- (pollfd.revents & POLLIN) ? "" : "not ");
+ (pollfd.revents & POLLIN) ? "" : "not ");
close(pidfd);
exit(EXIT_SUCCESS);
static int
pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
- unsigned int flags)
+ unsigned int flags)
{
return syscall(SYS_pidfd_send_signal, pidfd, sig, info, flags);
}
errExit("mmap");
if (clone(child, stack + STACK_SIZE,
- CLONE_NEWNS | SIGCHLD, &argv[1]) == \-1)
+ CLONE_NEWNS | SIGCHLD, &argv[1]) == \-1)
errExit("clone");
/* Parent falls through to here; wait for child. */
if (pfds[j].revents != 0) {
printf(" fd=%d; events: %s%s%s\en", pfds[j].fd,
- (pfds[j].revents & POLLIN) ? "POLLIN " : "",
- (pfds[j].revents & POLLHUP) ? "POLLHUP " : "",
- (pfds[j].revents & POLLERR) ? "POLLERR " : "");
+ (pfds[j].revents & POLLIN) ? "POLLIN " : "",
+ (pfds[j].revents & POLLHUP) ? "POLLHUP " : "",
+ (pfds[j].revents & POLLERR) ? "POLLERR " : "");
if (pfds[j].revents & POLLIN) {
ssize_t s = read(pfds[j].fd, buf, sizeof(buf));
if (s == \-1)
errExit("read");
printf(" read %zd bytes: %.*s\en",
- s, (int) s, buf);
+ s, (int) s, buf);
} else { /* POLLERR | POLLHUP */
printf(" closing fd %d\en", pfds[j].fd);
if (close(pfds[j].fd) == \-1)
/* Check the validity of the \(aqcmsghdr\(aq */
- if (cmsgp == NULL ||
- cmsgp\->cmsg_len != CMSG_LEN(sizeof(int)) ||
- cmsgp\->cmsg_level != SOL_SOCKET ||
- cmsgp\->cmsg_type != SCM_RIGHTS) {
+ if (cmsgp == NULL
+ || cmsgp\->cmsg_len != CMSG_LEN(sizeof(int))
+ || cmsgp\->cmsg_level != SOL_SOCKET
+ || cmsgp\->cmsg_type != SCM_RIGHTS)
+ {
errno = EINVAL;
return \-1;
}
#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \e
BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \e
- (offsetof(struct seccomp_data, arch))), \e
+ (offsetof(struct seccomp_data, arch))), \e
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \e
BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \e
(offsetof(struct seccomp_data, nr))), \e
static void
allocSeccompNotifBuffers(struct seccomp_notif **req,
- struct seccomp_notif_resp **resp,
- struct seccomp_notif_sizes *sizes)
+ struct seccomp_notif_resp **resp,
+ struct seccomp_notif_sizes *sizes)
{
/* Discover the sizes of the structures that are used to receive
notifications and send notification responses, and allocate
}
printf("\etS: got notification (ID %#llx) for PID %d\en",
- req\->id, req\->pid);
+ req\->id, req\->pid);
/* The only system call that can generate a notification event
is mkdir(2). Nevertheless, we check that the notified system
if (req\->data.nr != SYS_mkdir) {
printf("\etS: notification contained unexpected "
- "system call number; bye!!!\en");
+ "system call number; bye!!!\en");
exit(EXIT_FAILURE);
}
if (!pathOK) {
resp->error = -EINVAL;
printf("\etS: spoofing error for invalid pathname (%s)\en",
- strerror(-resp->error));
+ strerror(-resp->error));
} else if (strncmp(path, "/tmp/", strlen("/tmp/")) == 0) {
printf("\etS: executing: mkdir(\e"%s\e", %#llo)\en",
- path, req\->data.args[1]);
+ path, req\->data.args[1]);
if (mkdir(path, req\->data.args[1]) == 0) {
resp\->error = 0; /* "Success" */
resp\->val = strlen(path); /* Used as return value of
mkdir() in target */
printf("\etS: success! spoofed return = %lld\en",
- resp\->val);
+ resp\->val);
} else {
/* If mkdir() failed in the supervisor, pass the error
resp\->error = \-errno;
printf("\etS: failure! (errno = %d; %s)\en", errno,
- strerror(errno));
+ strerror(errno));
}
} else if (strncmp(path, "./", strlen("./")) == 0) {
resp\->error = resp\->val = 0;
} else {
resp\->error = \-EOPNOTSUPP;
printf("\etS: spoofing error response (%s)\en",
- strerror(\-resp\->error));
+ strerror(\-resp\->error));
}
/* Send a response to the notification */
printf("\etS: sending response "
- "(flags = %#x; val = %lld; error = %d)\en",
- resp\->flags, resp\->val, resp\->error);
+ "(flags = %#x; val = %lld; error = %d)\en",
+ resp\->flags, resp\->val, resp\->error);
if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == \-1) {
if (errno == ENOENT)
printf("\etS: response failed with ENOENT; "
- "perhaps target process\(aqs syscall was "
- "interrupted by a signal?\en");
+ "perhaps target process\(aqs syscall was "
+ "interrupted by a signal?\en");
else
perror("ioctl\-SECCOMP_IOCTL_NOTIF_SEND");
}
yes = 1;
if (setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR,
- &yes, sizeof(yes)) == \-1) {
+ &yes, sizeof(yes)) == \-1)
+ {
perror("setsockopt");
close(lfd);
return \-1;
if (argc != 4) {
fprintf(stderr, "Usage\en\etfwd <listen\-port> "
- "<forward\-to\-port> <forward\-to\-ip\-address>\en");
+ "<forward\-to\-port> <forward\-to\-ip\-address>\en");
exit(EXIT_FAILURE);
}
SHUT_FD1;
else
printf("connect from %s\en",
- inet_ntoa(client_addr.sin_addr));
+ inet_ntoa(client_addr.sin_addr));
/* Skip any events on the old, closed file
descriptors. */
}
if (fd1 > 0 && FD_ISSET(fd1, &readfds)) {
nbytes = read(fd1, buf1 + buf1_avail,
- BUF_SIZE \- buf1_avail);
+ BUF_SIZE \- buf1_avail);
if (nbytes < 1)
SHUT_FD1;
else
}
if (fd2 > 0 && FD_ISSET(fd2, &readfds)) {
nbytes = read(fd2, buf2 + buf2_avail,
- BUF_SIZE \- buf2_avail);
+ BUF_SIZE \- buf2_avail);
if (nbytes < 1)
SHUT_FD2;
else
}
if (fd1 > 0 && FD_ISSET(fd1, &writefds) && buf2_avail > 0) {
nbytes = write(fd1, buf2 + buf2_written,
- buf2_avail \- buf2_written);
+ buf2_avail \- buf2_written);
if (nbytes < 1)
SHUT_FD1;
else
}
if (fd2 > 0 && FD_ISSET(fd2, &writefds) && buf1_avail > 0) {
nbytes = write(fd2, buf1 + buf1_written,
- buf1_avail \- buf1_written);
+ buf1_avail \- buf1_written);
if (nbytes < 1)
SHUT_FD2;
else
{
struct sigaction oldact;
- if (sigaction(SIGSEGV, NULL, &oldact) == \-1 ||
- (oldact.sa_flags & SA_UNSUPPORTED) ||
- !(oldact.sa_flags & SA_EXPOSE_TAGBITS)) {
+ if (sigaction(SIGSEGV, NULL, &oldact) == \-1
+ || (oldact.sa_flags & SA_UNSUPPORTED)
+ || !(oldact.sa_flags & SA_EXPOSE_TAGBITS))
+ {
_exit(EXIT_FAILURE);
}
_exit(EXIT_SUCCESS);
}
printf("ID of containing device: [%jx,%jx]\en",
- (uintmax_t) major(sb.st_dev),
- (uintmax_t) minor(sb.st_dev));
+ (uintmax_t) major(sb.st_dev),
+ (uintmax_t) minor(sb.st_dev));
printf("File type: ");
printf("I\-node number: %ju\en", (uintmax_t) sb.st_ino);
printf("Mode: %jo (octal)\en",
- (uintmax_t) sb.st_mode);
+ (uintmax_t) sb.st_mode);
printf("Link count: %ju\en", (uintmax_t) sb.st_nlink);
printf("Ownership: UID=%ju GID=%ju\en",
- (uintmax_t) sb.st_uid, (uintmax_t) sb.st_gid);
+ (uintmax_t) sb.st_uid, (uintmax_t) sb.st_gid);
printf("Preferred I/O block size: %jd bytes\en",
- (intmax_t) sb.st_blksize);
+ (intmax_t) sb.st_blksize);
printf("File size: %jd bytes\en",
- (intmax_t) sb.st_size);
+ (intmax_t) sb.st_size);
printf("Blocks allocated: %jd\en",
- (intmax_t) sb.st_blocks);
+ (intmax_t) sb.st_blocks);
printf("Last status change: %s", ctime(&sb.st_ctime));
printf("Last file access: %s", ctime(&sb.st_atime));
printf("\enfault_handler_thread():\en");
printf(" poll() returns: nready = %d; "
- "POLLIN = %d; POLLERR = %d\en", nready,
- (pollfd.revents & POLLIN) != 0,
- (pollfd.revents & POLLERR) != 0);
+ "POLLIN = %d; POLLERR = %d\en", nready,
+ (pollfd.revents & POLLIN) != 0,
+ (pollfd.revents & POLLERR) != 0);
/* Read an event from the userfaultfd. */
errExit("ioctl\-UFFDIO_COPY");
printf(" (uffdio_copy.copy returned %"PRId64")\en",
- uffdio_copy.copy);
+ uffdio_copy.copy);
}
}