summaryrefslogtreecommitdiff
path: root/sys/kern/kern_pledge.c
AgeCommit message (Collapse)Author
2023-12-12put pinsyscalls(2) into the "always" groupTheo de Raadt
2023-09-29Extend single_thread_set() mode with additional flag attributes.Claudio Jeker
The mode can now be or-ed with SINGLE_DEEP or SINGLE_NOWAIT to alter the behaviour of single_thread_set(). This allows explicit control of the SINGLE_DEEP behaviour. If SINGLE_DEEP is set the deep flag is passed to the initial check call and by that the check will error out instead of suspending (SINGLE_UNWIND) or exiting (SINGLE_EXIT). The SINGLE_DEEP flag is required in calls to single_thread_set() outside of userret. E.g. at the start of sys_execve because the proc is not allowed to call exit1() in that location. SINGLE_NOWAIT skips the wait at the end of single_thread_set() and therefor returns BEFORE all threads have been parked. Currently this is only used by the ptrace code and should not be used anywhere else. Not waiting for all threads to settle is asking for trouble. This solves an issue by using SINGLE_UNWIND in the coredump case where the code should actually exit in case another thread crashed moments earlier. Also the SINGLE_UNWIND in pledge_fail() is now marked SINGLE_DEEP since the call to pledge_fail() is for sure not at the kernel boundary. OK mpi@
2023-09-19Before coredump or in pledge_fail use SINGLE_UNWIND to stop all threads.Claudio Jeker
SINGLE_UNWIND unwinds to the kernel boundary. On the other hand SINGLE_SUSPEND will sleep inside tsleep(9) and other sleep functions. Since the code will exit1() very soon after it is better to already unwind. Now one could argue that for coredumps all threads should stop asap to get a clean dump. Using SINGLE_UNWIND the sleep will fail with ERESTART and no copyout should happen in that case. This is a bit of a workaround since SINGLE_SUSPEND has a small race where single_thread_wait() returns before all threads are really stopped. When SINGLE_EXIT is called quickly after this can blow up inside sleep_finish. Reported-by: syzbot+3ef066fcfaf991f2ac2c@syzkaller.appspotmail.com OK mpi@ kettenis@
2023-08-20Add kqueue1() system callVisa Hankala
kqueue1() takes the flags argument. This lets the kqueue file descriptor be opened with O_CLOEXEC. Adapted from NetBSD. OK guenther@
2023-06-02pledge(2): stdio: permit restricted profil(2) for moncontrol(3)Scott Soule Cheloha
Currently, pledged '-pg' binaries get killed in _mcleanup() when they try to disable profil(2) via moncontrol(3). Disabling profil(2) is harmless. Add profil(2) to the "stdio" pledge(2) promise and permit profil(2) calls when the scale argument is zero. Enabling profil(2) remains forbidden in pledged processes. This gets us one step closer to making '-pg' binaries compatible with pledge(2). The next step is to decide how to exfiltrate the profiling data from the process during _mcleanup(). Prompted by semarie@. Cleaned up by deraadt@. With input from deraadt@, espie@, and semarie@. "Looks good" deraadt@ pledge(2) pieces ok semarie@
2023-05-19Since waitid(2) shares code with wait4(2) and doesn't expose anyPhilip Guenther
non-trivial new information or code-paths over wait4(), include it in pledge("stdio") discussed with deraadt@
2023-02-19Make pinsyscall(2) always available for pledged processes. Needed by pledgeAnton Lindqvist
execpromises, as noted by regress/sys/kern/pledge/execpromise. sure deraadt@
2023-02-11non-padded 64-bit system calls arrived 2021/12/23, over a year ago.Theo de Raadt
time to delete the backwards compat padded functions in the kernel.
2023-01-07Add {get,set}thrname(2) for putting thread names in the kernel andPhilip Guenther
exposed in a new field returned by sysctl(KERN_PROC). Update pthread_{get,set}_name_np(3) to use the syscalls. Show them, when set, in ps -H and top -H output. libc and libpthread minor bumps ok mpi@, mvs@, deraadt@
2022-12-23wrap a line betterTheo de Raadt
2022-12-05zap a pile of dangling tabsTheo de Raadt
2022-11-10fix build after 1.298Jonathan Gray
2022-11-09Some limited setsockopt/getsockopt are allowed in pledge "stdio".Theo de Raadt
Also allow IPPROTO_TCP:TCP_NODELAY It is very small kernel code, and will allow some software to drop "inet" requested by djm
2022-11-08allow the KERN_AUTOCONF_SERIAL sysctl in pledge'd processesRobert Nagy
ok deraadt@
2022-10-07Add mimmutable(2) system call which locks the permissions (PROT_*) ofTheo de Raadt
memory mappings so they cannot be changed by a later mmap(), mprotect(), or munmap(), which will error with EPERM instead. ok kettenis
2022-09-05Pledge sendmmsg and recvmmsg with stdio similar to their non-loopMoritz Buhl
counter parts. Input deraadt. ok bluhm
2022-08-14remove unneeded includes in sys/kernJonathan Gray
ok mpi@ miod@
2022-08-11Add TCP_INFO support to getsockopt for tcp sessions.Claudio Jeker
TCP_INFO provides a lot of information about the TCP session of this socket. Many processes like to peek at the rtt of a connection but this also provides a lot of more special info for use by e.g. tcpbench(1). While the basic minimal info is available all the time the more specific data is only populated for privileged processes. This is done to not share data back to userland that may allow to attack a session. TCP_INFO is available to pledge "inet" since pledged processes like chrome tend to use TCP_INFO when available. OK bluhm@
2022-08-08Before ypconnect(2) addition, "getpw" was a horrible "hole" that triggeredTheo de Raadt
on libc trying to open /var/run/ypbind.lock, so pledge had to BYPASSUNVEIL accesses to this file. We accepted the opening of that file for a small period for build cross-over, but that waiting period ends now.
2022-08-02some ports bootstraps, and go internals, need a bit more time to adaptTheo de Raadt
to the padded syscalls going away.
2022-07-18Restrict pledge("vminfo") callers to read-only swapctl(2) operations.Jeremie Courreges-Anglas
Those are the read-only operations allowed for non-root users: SWAP_NSWAP and SWAP_STATS. Users of pledge("vminfo") in base which also call swapctl(2) with said commands: top(1) and pstat(8). No regression spotted with top(1) and pstat(8) -s/-T. ok deraadt@
2022-07-18Delete the YPACTIVE toggling code when "getpw" code access/open are done toTheo de Raadt
/var/run/ypbind.lock. "getpw" is now only allows ypconnect(2) and the minimum unveil bypasses. Still allow open/acesss to file for a little while, because getpwent/getgrent/etc were opening it unconditionally to hint for YPACTIVE. That code should be deleted before 7.2
2022-07-17backout last step: the path checks are too strong until everyone has aTheo de Raadt
new libc..
2022-07-17the PLEDGE_YPACTIVE "hack" bit related to "getpw" pledge goes away. libcTheo de Raadt
no longer does accesses /var/run/ypbind.lock to trigger extra permissions for userland-opening of files & sockets to engage with ypserver for YP/LDAP lookups. libc now uses the super secret special ypconnect() system call to perform socket-setup. Delete some other things which are no longer reached via libc/rpc ok jmatthew, miod
2022-07-15Allow ypconnect() in "getpw"Theo de Raadt
Annotate two blocks relating to ypbind.lock that will be deleted once libc switches over to the new mechanism.
2022-06-30Allow sysctl mib CTL_NET.PF_INET6 with a length of 3 in PLEDGE_VMINFO.Claudio Jeker
This will be used for sysconf(3) and getconf(1) to handle _POSIX_IPV6 without opening a socket. OK sthen@ deraadt@
2022-06-29Unlock the pledge(2) system callJeremie Courreges-Anglas
Protect the ps_pledge/ps_execpledge fields with ps_mtx. Shuffle the code to call unveil_destroy() outside the critical section. Only writes to those fields are protected. Since we may only remove bits from those fields, garbage values should do no harm even when a read crosses a write on 32 bits systems. Input claudio@ kettenis@ deraadt@, ok deraadt@
2022-06-29Use READ_ONCE() when saving pr->ps_pledge to a local variableJeremie Courreges-Anglas
This prevents the compiler from reloading a possibly different value from memory. Even if it doesn't matter in this code it's just better practice. Discussed with kettenis@ and deraadt@, ok deraadt@
2022-06-26allow HW_USERMEM64 in sysctl pledgeJonathan Gray
chromium loads vulkan when going to chrome://gpu anv, the Intel vulkan driver in Mesa uses HW_USERMEM64 ok sthen@ deraadt@
2022-03-25add an exception to the CPU_ID_AA64ISAR0 in pledged applications so thatRobert Nagy
libcrypto can access this sysctl on arm64 without restrictions to determine cpu features ok deraadt@, kettenis@
2022-02-25add setrtable to pledge("id"). from Matthew MartinTed Unangst
ok deraadt
2022-02-04whitelist resolv.conf for stat. go dns library does this.Ted Unangst
ok deraadt
2022-01-20initial support for drm sync files, fences associated with fileJonathan Gray
descriptors for explicit fencing tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on intel broadwell with Mesa 21.3 (which hangs without sync file support after the 'anv: Assume syncobj support' Mesa commit) feedback and ok visa@
2021-12-23Roll the syscalls that have an off_t argument to remove the explicit padding.Philip Guenther
Switch libc and ld.so to the generic stubs for these calls. WARNING: reboot to updated kernel before installing libc or ld.so! Time for a story... When gcc (back in 1.x days) first implemented long long, it didn't (always) pass 64bit arguments in 'aligned' registers/stack slots, with the result that argument offsets didn't match structure offsets. This affected the nine system calls that pass off_t arguments: ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate To avoid having to do custom ASM wrappers for those, BSD put an explicit pad argument in so that the off_t argument would always start on a even slot and thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use __syscall() and pass an extra '0' argument. The ABIs for different CPUs eventually settled how things should be passed on each and gcc 2.x followed them. The only arch now where it helps is landisk, which needs to skip the last argument register if it would be the first half of a 64bit argument. So: add new syscalls without the pad argument and on landisk do that skipping directly in the syscall handler in the kernel. Keep compat support for the existing syscalls long enough for the transition. ok deraadt@
2021-11-15Copy p_p->ps_pledge into a local variable (called pledge) in every functionTheo de Raadt
which checks PLEDGE_* bits more than once. Some functions are called without locking, and this avoids misinterpreting bits which have some coupled behaviour. ok cheloha kettenis
2021-06-29remove arch ifdefs around drm.h includeJonathan Gray
ok deraadt@ kettenis@
2021-06-26Add powerpc64 and riscv64 to the list of architectures that have DRM.Mark Kettenis
ok matthieu@, deraadt@, jsg@
2021-06-09unveil: small cleanup for UNVEIL_INSPECTSebastien Marie
remove two leftover checks which were used when ni_unveil was used with UNVEIL_INSPECT. it was used by: - readlink(2) - removed 2019-08-31 - stat(2) and access(2) - removed 2019-03-24 ok claudio@
2021-04-30When terminating via pledge_fail() stop all threads, before issuing aTheo de Raadt
(delayed action) sigabort() and disabling all syscalls for this process (ie. all threads). This resulted in multiple-threads crashing over top of themselves, and a poor debugging experience. We keep using sigabort() rather than sigexit(), to keep the debugging process good. Diagnosed from a report from brynet, and followup discussion with many.
2021-03-25Permit kern.somaxconn when the unix pledge is used. Previously this was onlyAaron Bieber
allowed when inet was used. This lets Go programs use 'unix' without also including 'inet'. from Josh Rickmar ok / tree review from deraadt@, commit message cluestick from tb@
2021-02-03Add SIOCAIFADDR_IN and SIOCDIFADDR_IN to the wroute pledgetobhe
to allow setting and removing IPv4 addresses. Needed for future iked(8) improvements. Discussed with sthen@ and florian@ ok bluhm@ deraadt@
2021-01-20If pledge "wroute" is missing for setsockopt SO_RTABLE, print failureAlexander Bluhm
message "wroute" into dmesg. Since revision 1.263 pledge "wroute" allows to change the routing table of a socket. OK florian@ semarie@
2021-01-19/etc/malloc.conf path-approval in pledge is no longer needed since 6.5Theo de Raadt
moved option control into a sysctl. reminder that we can delete this from benjamin baier
2020-10-29Add feature to force the selection of source IP addressdenis
Based/previous work on an idea from deraadt@ Input from claudio@, djm@, deraadt@, sthen@ OK deraadt@
2020-09-16Move duplicated code to send an uncatchable SIGABRT into a function.Martin Pieuchot
ok claudio@
2020-09-16put HW_PHYSMEM64 case under CTL_HW not CTL_KERNJonathan Gray
Fixes previous. Problem spotted by kettenis@
2020-09-16As discovered by kettenis, recent mesa wants sysctl hw.physmem64, andTheo de Raadt
in pledged programs that is unfortable. My snark levels are a bit drained, but I must say I'm always dissapointed when programs operating on virtual resources enquire about total physical resource availability, the only reason to ask is so they can act unfair relative to others in the shared environment. SIGH.
2020-07-17Allow setsockopt SO_RTABLE when pleding "wroute" soon to be neededFlorian Obser
by slaacd(8). "wroute" allows changes to the routing table so this is a good fit. Nothing else in base is effected by this. dhclient might use the wroute pledge in the future and might also want SO_RTABLE in a more distant future. OK deraadt
2020-04-05Declare pledgenames[] as const.Visa Hankala
OK deraadt@
2020-02-15Consistently perform atomic writes to the ps_flags field of structanton
process. ok bluhm@ claudio@ visa@