mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-01 03:53:33 +00:00
98254a7c1f
This change reconciles our pledge() implementation with the OpenBSD kernel source code. We now a polyfill that's much closer to OpenBSD's behavior. For example, it was discovered that "stdio" permits threads. There were a bunch of Linux system calls that needed to be added, like sched_yield(). The exec / execnative category division is now dropped. We're instead using OpenBSD's "prot_exec" promise for launching APE binaries and dynamic shared objects. We also now filter clone() flags. The pledge.com command has been greatly improved. It now does unveiling by default when Landlock is available. It's now smart enough to unveil a superset of paths that OpenBSD automatically unveils with pledge(), such as /etc/localtime. pledge.com also now checks if the executable being launched is a dynamic shared object, in which case it unveils libraries. These changes now make it possible to pledge curl on ubuntu 20.04 glibc: pledge.com -p 'stdio rpath prot_exec inet dns tty sendfd recvfd' \ curl -s https://justine.lol/hello.txt Here's what pledging curl on Alpine 3.16 with Musl Libc looks like: pledge.com -p 'stdio rpath prot_exec dns inet' \ curl -s https://justine.lol/hello.txt Here's what pledging curl.com w/ ape loader looks like: pledge.com -p 'stdio rpath prot_exec dns inet' \ o//examples/curl.com https://justine.lol/hello.txt The most secure sandbox, is curl.com converted to static ELF: o//tool/build/assimilate.com o//examples/curl.com pledge.com -p 'stdio rpath dns inet' \ o//examples/curl.com https://justine.lol/hello.txt A weird corner case needed to be handled when resolving symbolic links during the unveiling process, that's arguably a Landlock bug. It's not surprising since Musl and Glibc are also inconsistent here too.
62 lines
3 KiB
C
62 lines
3 KiB
C
#ifndef COSMOPOLITAN_LIBC_CALLS_TERMIOS_H_
|
|
#define COSMOPOLITAN_LIBC_CALLS_TERMIOS_H_
|
|
#include "libc/calls/ioctl.h"
|
|
#include "libc/calls/struct/termios.h"
|
|
#include "libc/calls/struct/winsize.h"
|
|
#include "libc/sysv/consts/termios.h"
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
COSMOPOLITAN_C_START_
|
|
|
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
|
│ cosmopolitan § teletypewriter control ─╬─│┼
|
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
|
|
|
int tcgetattr(int, struct termios *);
|
|
int tcsetattr(int, int, const struct termios *);
|
|
int tcsetpgrp(int, int32_t);
|
|
int32_t tcgetpgrp(int);
|
|
|
|
int openpty(int *, int *, char *, const struct termios *,
|
|
const struct winsize *) paramsnonnull((1, 2)) dontdiscard;
|
|
int forkpty(int *, char *, const struct termios *, const struct winsize *)
|
|
paramsnonnull((1, 2)) dontdiscard;
|
|
char *ptsname(int);
|
|
errno_t ptsname_r(int, char *, size_t);
|
|
|
|
int grantpt(int);
|
|
int unlockpt(int);
|
|
int posix_openpt(int) dontdiscard;
|
|
|
|
int tcdrain(int);
|
|
int tcgetsid(int);
|
|
int tcflow(int, int);
|
|
int tcflush(int, int);
|
|
int tcsendbreak(int, int);
|
|
void cfmakeraw(struct termios *);
|
|
int cfsetospeed(struct termios *, int);
|
|
int cfsetispeed(struct termios *, int);
|
|
uint32_t cfgetospeed(const struct termios *);
|
|
uint32_t cfgetispeed(const struct termios *);
|
|
|
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
|
│ cosmopolitan § teletypewriter » undiamonding ─╬─│┼
|
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
|
|
|
#define tcsetattr(FD, OPT, TIO) tcsetattr_dispatch(FD, OPT, TIO)
|
|
forceinline int tcsetattr_dispatch(int fd, int opt, const struct termios *tio) {
|
|
if (__EQUIVALENT(opt, TCSANOW)) return ioctl(fd, TCSETS, (void *)tio);
|
|
if (__EQUIVALENT(opt, TCSADRAIN)) return ioctl(fd, TCSETSW, (void *)tio);
|
|
if (__EQUIVALENT(opt, TCSAFLUSH)) return ioctl(fd, TCSETSF, (void *)tio);
|
|
return (tcsetattr)(fd, opt, tio);
|
|
}
|
|
|
|
#define tcgetattr(FD, TIO) tcgetattr_dispatch(FD, TIO)
|
|
forceinline int tcgetattr_dispatch(int fd, const struct termios *tio) {
|
|
return ioctl(fd, TCGETS, (void *)tio);
|
|
}
|
|
|
|
#endif /* GNUC && !ANSI */
|
|
COSMOPOLITAN_C_END_
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
#endif /* COSMOPOLITAN_LIBC_CALLS_TERMIOS_H_ */
|