summaryrefslogtreecommitdiff
path: root/sys/compat/linux
AgeCommit message (Collapse)Author
2022-08-03Pull up following revision(s), all via patchmartin
(requested by riastradh in ticket #1487): sys/compat/linux/arch/i386/linux_machdep.c: revision 1.168 sys/compat/sunos/sunos_misc.c: revision 1.177 sys/compat/netbsd32/netbsd32_compat_50.c: revision 1.52 sys/compat/common/kern_resource_43.c: revision 1.23 sys/compat/netbsd32/netbsd32_conv.h: revision 1.46 sys/compat/linux/arch/i386/linux_ptrace.c: revision 1.35 sys/compat/common/vfs_syscalls_12.c: revision 1.38 sys/compat/ultrix/ultrix_misc.c: revision 1.126 sys/compat/common/kern_sig_43.c: revision 1.37 sys/compat/linux/common/linux_mtio.c: revision 1.8 sys/compat/freebsd/freebsd_misc.c: revision 1.34 sys/compat/freebsd/freebsd_machdep.c: revision 1.5 sys/compat/linux/common/linux_olduname.c: revision 1.67 sys/compat/linux/arch/mips/linux_machdep.c: revision 1.44 sys/compat/freebsd/freebsd_sched.c: revision 1.23 sys/compat/ossaudio/ossaudio.c: revision 1.84 sys/compat/sys/time_types.h: revision 1.6 sys/compat/linux/arch/powerpc/linux_machdep.c: revision 1.51 sys/compat/common/ieee80211_20.c: revision 1.7 sys/compat/linux/common/linux_file.c: revision 1.119 sys/compat/linux/arch/arm/linux_machdep.c: revision 1.34 sys/compat/netbsd32/netbsd32_wait.c: revision 1.25 sys/compat/linux32/common/linux32_time.c: revision 1.38 sys/compat/linux/arch/powerpc/linux_ptrace.c: revision 1.33 sys/compat/linux/arch/alpha/linux_machdep.c: revision 1.52 sys/compat/linux32/arch/amd64/linux32_machdep.c: revision 1.46 sys/compat/netbsd32/netbsd32_compat_12.c: revision 1.36 sys/compat/ultrix/ultrix_ioctl.c: revision 1.39 sys/compat/linux/common/linux_misc.c: revision 1.252 sys/compat/linux/common/linux_hdio.c: revision 1.19 sys/compat/sunos/sunos_ioctl.c: revision 1.71 sys/compat/linux/common/linux_sched.c: revision 1.79 sys/compat/common/kern_info_43.c: revision 1.40 sys/compat/linux32/common/linux32_exec_elf32.c: revision 1.20 sys/compat/linux/common/linux_socket.c: revision 1.153 sys/compat/linux/arch/amd64/linux_machdep.c: revision 1.60 sys/compat/common/vfs_syscalls_43.c: revision 1.68 sys/compat/linux/arch/powerpc/linux_exec_powerpc.c: revision 1.25 sys/compat/netbsd32/netbsd32_ptrace.c: revision 1.9 sys/compat/common/kern_time_50.c: revision 1.37 sys/compat/netbsd32/netbsd32_compat_20.c: revision 1.42 sys/compat/linux/common/linux_cdrom.c: revision 1.28 sys/compat/linux/arch/m68k/linux_machdep.c: revision 1.43 sys/compat/common/kern_info_09.c: revision 1.22 sys/compat/linux32/common/linux32_resource.c: revision 1.12 sys/compat/linux/common/linux_oldolduname.c: revision 1.67 sys/compat/common/if_media_80.c: revision 1.4 sys/compat/linux/arch/alpha/linux_osf1.c: revision 1.5 sys/compat/netbsd32/netbsd32_nfssvc.c: revision 1.8 sys/compat/linux32/common/linux32_signal.c: revision 1.21 sys/compat/common/kern_sig_13.c: revision 1.22 sys/compat/sunos32/sunos32_ioctl.c: revision 1.36 sys/compat/netbsd32/netbsd32_compat_43.c: revision 1.62 sys/compat/linux/arch/arm/linux_ptrace.c: revision 1.23 sys/compat/netbsd32/netbsd32_time.c: revision 1.56 sys/compat/linux/common/linux_signal.c: revision 1.84 sys/compat/netbsd32/netbsd32_signal.c: revision 1.52 sys/compat/sunos32/sunos32_misc.c: revision 1.85 sys/compat/linux/common/linux_time.c: revision 1.40 sys/compat/linux/common/linux_fdio.c: revision 1.14 sys/compat/common/vfs_syscalls_30.c: revision 1.43 sys/compat: Memset zero before copyout. Just in case of uninitialized padding which would lead to kernel stack disclosure. If the compiler can prove the memset redundant then it can optimize it away; otherwise better safe than sorry.
2020-11-08Pull up following revision(s) (requested by kamil in ticket #1127):martin
sys/compat/linux/common/linux_socket.c: revision 1.151 Fix compat with Linux programs that use longer namelen for sockets Linux is less strict than NetBSD and permits namelen to be larger than valid struct sockaddr_in*. If this is the case, truncate the value to the correct size, so that NetBSD networking does not return an error. Reviewed by kamil
2020-07-17Pull up following revision(s) (requested by msaitoh in ticket #1018):martin
sys/net/if.c: revision 1.479 sys/compat/common/uipc_syscalls_40.c: revision 1.23 sys/compat/linux/common/linux_socket.c: revision 1.150 sys/compat/linux32/common/linux32_socket.c: revision 1.31 Don't accept negative value.
2019-09-13Pull up following revision(s) (requested by maxv in ticket #194):martin
sys/compat/linux/common/linux_socket.c: revision 1.146 sys/compat/linux/common/linux_socket.c: revision 1.147 sys/compat/linux/common/linux_socket.c: revision 1.148 sys/compat/linux/common/linux_socket.c: revision 1.149 sys/compat/linux/arch/amd64/linux_machdep.c: revision 1.59 sys/compat/linux32/common/linux32_sysinfo.c: revision 1.8 sys/kern/sysv_shm.c: revision 1.138 sys/compat/linux/common/linux_file64.c: revision 1.61 sys/compat/linux/common/linux_file64.c: revision 1.62 sys/compat/netbsd32/netbsd32_compat_43.c: revision 1.58 sys/compat/linux32/common/linux32_dirent.c: revision 1.20 sys/compat/linux32/common/linux32_utsname.c: revision 1.10 sys/compat/linux/common/linux_termios.h: revision 1.22 sys/compat/linux32/common/linux32_termios.c: revision 1.15 sys/compat/linux32/common/linux32_misc.c: revision 1.27 sys/compat/linux32/common/linux32_ioctl.c: revision 1.14 sys/compat/linux/common/linux_statfs.h: revision 1.7 sys/compat/linux/common/linux_ipc.c: revision 1.57 sys/compat/linux/common/linux_fcntl.h: revision 1.18 sys/compat/linux/common/linux_socket.h: revision 1.24 sys/sys/shm.h: revision 1.54 sys/compat/ossaudio/ossaudio.c: revision 1.75 sys/compat/linux32/common/linux32_signal.c: revision 1.20 sys/miscfs/procfs/procfs_linux.c: revision 1.75 sys/compat/linux/common/linux_signal.c: revision 1.81 sys/compat/linux/common/linux_termios.c: revision 1.38 sys/compat/linux/common/linux_misc.c: revision 1.241 sys/compat/linux/common/linux_misc.c: revision 1.242 sys/compat/linux/common/linux_misc.c: revision 1.243 sys/compat/linux/common/linux_misc.c: revision 1.244 Fix info leaks. Fix stupid bugs in linux_sys_shmctl(): the index could be out of bound (page fault) and there was no proper locking. Maybe we should just remove LINUX_SHM_STAT, like compat_linux32. Remove printf. When dealing with an unknown value, set -1, to prevent (harmless) uninitialized accesses later. Add a default case, don't call sys_ioctl() with an uninitialized 'com' argument. Fix error handling, returns an errno, not -1. Put the printf under DEBUG_LINUX. Hum, don't forget the 'pid' argument, otherwise we're not gonna go very far. Don't read data from userland directly. This simply does not work on any recent x86 CPU (thanks to SMAP) and all architectures that forbid direct access to userland from the kernel. But I guess no one noticed because no one ever uses compat_linux, right? Hum, don't pass an mbuf to realloc(). Inspired from copyin32_msg_control(). Fix memory leak. I don't see the point in having this useless printf, but add a '\n' to it, so that it at least displays useless stuff correctly. Hum, remove incorrect assignment. Userland could have passed a smaller namelen, and the uninitialized bytes from sb_data were being used later in the network stack.
2019-06-18Drop unused retval pointer from do_sys_mknod{,at}()kamil
No functional change intended.
2019-05-19Renamemaxv
fpu_save_area_clear -> fpu_clear fpu_save_area_reset -> fpu_sigreset Clearer, and reduces a future diff. No real functional change.
2019-04-18Zero out the ifreq struct for SIOCGIFCONF to avoid up to 127 bytes of stackchristos
disclosure. From Andy Nguyen, many thanks! This is the compat code part pointed out by ozaki-r@
2019-04-06Overhaul the API used to fetch and store individual memory cells inthorpej
userspace. The old fetch(9) and store(9) APIs (fubyte(), fuword(), subyte(), suword(), etc.) are retired and replaced with new ufetch(9) and ustore(9) APIs that can return proper error codes, etc. and are implemented consistently across all platforms. The interrupt-safe variants are no longer supported (and several of the existing attempts at fuswintr(), etc. were buggy and not actually interrupt-safe). Also augmement the ucas(9) API, making it consistently available on all plaforms, supporting uniprocessor and multiprocessor systems, even those that do not have CAS or LL/SC primitives. Welcome to NetBSD 8.99.37.
2019-03-26make this compile again.christos
2019-03-24regenmaxv
2019-03-24Remove Alpha's compat_linux dependency on compat_osf1. Each function ismaxv
copied as-is from compat_osf1 with no functional change. Discussed on tech-kern@, ok @thorpej.
2019-03-24Fix a tiny race in setregs and linux_setregs. Between the moment we setmaxv
pcb_flags to zero, and the moment cpu_segregs64_zero resets pcb_gs, we may be preempted. If this happens, and if the calling LWP was a 32bit thread, when switching back to that LWP, the context switcher sees that PCB_COMPAT32 is not set in pcb_flags and tries to perform a 64bit context switch; but pcb_gs contains a 32bit GDT descriptor, and not a 64bit GS.base value. The wrmsr therefore faults because the value is non-canonical, and this fault is fatal. Rearrange the code so that the update of pcb_flags and pcb_gs/pcb_fs is non interruptible. This fixes the problem, tested with a reproducer (which therefore doesn't work anymore). Likely fixes PR/53993.
2019-03-01Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as brieflypgoyette
discussed on irc. NFCI intended. Ride the earlier kernel bump - it;s getting crowded.
2019-02-21for sysv ipc stat operations, explicitly copy the exported partsmrg
instead of the whole ds structure. besides triggering a recently added assert in netbsd32, this stops exposing kernel addresses. copy the mode clamping to 0777 from sem to shm and msg. while here, make sure that the compat callers to sysv_ipc clear the contents of the compat structure before setting the result members to ensure padding bytes are cleared. don't set/copy _sem_base, _msg_first, _msg_last or _shm_internal. even if used, which seems very dodgy, they leak KVAs as well. possibly this may affect linux binaries, in particular, the comments around _shm_internal ("XXX Oh well.") may mean apps rely upon these but hopefully not -- the comments date back to rev 1.1 in 1995. the _key, _seq and _msg_cbytes members are exported as before as i found multiple consumers of these (no less than ipcs(1), and they appear to be useful for debugging and more. XXX: the naming of compat functions have too many styles. there are at least 3 different ones changed here.
2019-02-04- avoid uninitialised memory usagemrg
2019-02-03- add or adjust /* FALLTHROUGH */ where appropriatemrg
- add __unreachable() after functions that can return but won't in this case, and thus can't be marked __dead easily
2019-01-27Merge the [pgoyette-compat] branchpgoyette
2018-11-29Improve my kern_time.c::rev1.192, systematically clear the buffers we getmaxv
from 'ptimer_pool' to prevent more leaks.
2018-11-14Apply the recent fixes to {send,recv}mmsg() to their compat variants.hannken
2018-09-03Rename min/max -> uimin/uimax for better honesty.riastradh
These functions are defined on unsigned int. The generic name min/max should not silently truncate to 32 bits on 64-bit systems. This is purely a name change -- no functional change intended. HOWEVER! Some subsystems have #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) even though our standard name for that is MIN/MAX. Although these may invite multiple evaluation bugs, these do _not_ cause integer truncation. To avoid `fixing' these cases, I first changed the name in libkern, and then compile-tested every file where min/max occurred in order to confirm that it failed -- and thus confirm that nothing shadowed min/max -- before changing it. I have left a handful of bootloaders that are too annoying to compile-test, and some dead code: cobalt ews4800mips hp300 hppa ia64 luna68k vax acorn32/if_ie.c (not included in any kernels) macppc/if_gm.c (superseded by gem(4)) It should be easy to fix the fallout once identified -- this way of doing things fails safe, and the goal here, after all, is to _avoid_ silent integer truncations, not introduce them. Maybe one day we can reintroduce min/max as type-generic things that never silently truncate. But we should avoid doing that for a while, so that existing code has a chance to be detected by the compiler for conversion to uimin/uimax without changing the semantics until we can properly audit it all. (Who knows, maybe in some cases integer truncation is actually intended!)
2018-08-22- Cleanup for dynamic sysctl:msaitoh
- Remove unused *_NAMES macros for sysctl. - Remove unused *_MAXID for sysctls. - Move CTL_MACHDEP sysctl definitions for m68k into m68k/include/cpu.h and use them on all m68k machines.
2018-08-10Regenpgoyette
2018-08-10Allow syscall_establish() to install new syscalls when the existingpgoyette
entry-point is either sys_nomodule or sys_nosys. Update the makesyscalls.sh script to create a const array of bits to allow syscall_disestablish() to properly restore the original entry-point. Update all the initializers of struct emul to initialize the pointer to the bit array struct emul. XXX Regen of all files created by makesyscalls.sh will come soon, XXX followed by a kernel version bump (since struct emul is being XXX modified). This commit should address PR kern/45781 and also removes the need for the work-around for that PR in file sys/arch/usermode/modules/syscallemu/syscallemu.c
2018-07-15- fix constants and explain limitchristos
- use machine32 instead of hard-coded x86 stuff
2018-07-09 Fix compile error.msaitoh
2018-07-08Enable executing linux go binaries by using a special probe function for them.christos
2018-05-10Fix pserialize enter/exit pairs in linux_getifconf and linux32_getifconfozaki-r
Tested by using a small linux program that uses ioctl(SIOCGIFCONF). Probably fix PR kern/53259 as well.
2018-05-06Remove an element from struct emul: e_tracesigkamil
e_tracesig used to be implemented for Darwin compat. Nowadays the Darwin compatiblity layer is gone and there are no other users. This functionality isn't used where it shall be used in the existing codebase. If we want to emulate debugging interfaces in compat layers we would need to implement that from scratch anyway. We would need to be bug compatible with other OSes too. Proposed on tech-kern@. Welcome to NetBSD 8.99.16! Sponsored by <The NetBSD Foundation>
2018-05-03Fix COMPAT_NETBSD32 cmsg handling:christos
1. alignment was wrong for > 1 message 2. macros were doing incorrect pointer comparisons, fortunately ending the iteration early after the fists cmsg instead of crashing. 3. don't output 32 bit ktrace records for cmsg. 32 bit programs running under emulation on 64 bit systems should produce 64 bit ktrace records so that the native ktrace can handle the records; remove extra arguments that are now not needed (the 32 bit msghdr). 4. output the correct type for cmsg trace records. 5. output all the cmsg records in traces instead of just the first one. Welcome to 8.99.15 because of the argument removal. XXX: Really all the code should be changed to use the CMSG_{FIRST,NXT}HDR macros...
2018-04-16Remove the rnewprocp argument from fork1(9)kamil
It's now unused and it can cause use-after-free scenarios as noted by <Mateusz Guzik>. Reference: http://mail-index.netbsd.org/tech-kern/2017/09/08/msg022267.html Sponsored by <The NetBSD Foundation>
2018-04-15Remove unused variable p from linux_sys_clone()kamil
After refactoring by <chs> in 2010 (r. 1.63) the p variable is no longer used. As noted by <Mateusz Guzik> its usage is also unsafe and might cause use-after-free scenarios. No functional change intended. Reference: http://mail-index.netbsd.org/tech-kern/2017/09/08/msg022267.html Sponsored by <The NetBSD Foundation>
2018-03-16PR/53103: Timo Buhrmester: linux emulation of sendto(2) brokenchristos
The sockargs refactoring broke it, because sockargs only works with a user address. Added an argument to sockargs to indicate where the address is coming from. Welcome to 8.99.14.
2018-01-26union was removedchristos
2018-01-24Remove port-acorn26skrll
OK core@
2018-01-09remove struct emul's e_fault.maya
It used to be used by COMPAT_IRIX for the purpose of overriding uvm_fault (only implemented in MIPS), now removed. Ride 8.99.12 version bump.
2018-01-07Ignore signal 64 for now (go uses it)christos
XXX: pullup-8
2018-01-01Use the default %cs, and mask the other segregs.maxv
2017-12-26Refactor pipe1() and correct a bug in sys_pipe2() (SYS_pipe2)kamil
sys_pipe2() returns two integers (values), the 2nd one is a copy of the 2nd file descriptor that lands in fildes[2]. This is a side effect of reusing the code for sys_pipe() (SYS_pipe) and not cleaning it up. The first returned value is (on success) 0. Introduced a small refactoring in pipe1() that it does not operate over retval[], but on an array int[2]. A user sets retval[] for pipe() when desired and needed. This refactoring touches compat code: netbsd32, linux, linux32. Before the changes on NetBSD/amd64: $ ktruss -i ./a.out [...] 15131 1 a.out pipe2(0x7f7fff2e62b8, 0) = 0, 4 [...] After the changes: $ ktruss -i ./a.out [...] 782 1 a.out pipe2(0x7f7fff97e850, 0) = 0 [...] There should not be a visible change for current users. Sponsored by <The NetBSD Foundation>
2017-12-10Finally (hopefully) return completely to the state where compat_linux iskre
enabled by default. While here make it possible to enable this if already enabled, or disable if already disabled, without error. Some minor KNF.
2017-12-08Finish the previous change - as well as setting the default for thesekre
compat modules back to enabled, stop forcing it to switch back to disabled any time the module is init'd (which is truly barbaric behaviour.)
2017-12-01Unbreak Linux emulation by default. While not loading it automaticallyjoerg
is somewhat sensible, breaking functionality of GENERIC is not and has been objected to on a regular base.
2017-11-22Fix and make consistent of usages of psz/psref in ifconf variantsozaki-r
2017-11-21This should be "linux_sg_version", not "version".maxv
2017-10-21Include opt_user_ldt.h when needed.maxv
2017-10-19Always mask the 16 bits of the segregs in the trapframe. We don't zero-maxv
extend the uint64_t's when building it, so we're leaking 48 bits of kernel stack to userland. Having said that, it appears that I unintentionally fixed most of this issue in locore.S::rev1.127 - by building the frame with interrupts disabled, we are implicitly guaranteeing that the structure doesn't get overwritten by the kernel. Which means, we are leaking to userland data that comes from userland anyway. (still other places with this issue, but I'll fix them differently)
2017-10-15Use two separate functions: cpu_segregs32_zero and cpu_segregs64_zero. Themaxv
way segment registers work on amd64 will diverge between 32bit and 64bit LWPs.
2017-09-29Remove compat_linux from the autoload list, and add a sysctl to enable ormaxv
disable it - which defaults to disabled. The following command is now required to use linux binaries: sysctl -w emul.linux.enabled=1 After a discussion on tech-kern@. All the other ideas to reduce the attack surface have drawbacks, and this sysctl seems to be the best option.
2017-09-17Remove the second argument from USERMODE and KERNELMODE, it is unusedmaxv
now that we don't have vm86 anymore.
2017-08-28Remove the filesystem tracing featurekamil
This is a legacy interface from 4.4BSD, and it was introduced to overcome shortcomings of ptrace(2) at that time, which are no longer relevant (performance). Today /proc/#/ctl offers a narrow subset of ptrace(2) commands and is not applicable for modern applications use beyond simplistic tracing scenarios. This removal will simplify kernel internals. Users will still be able to use all the other /proc files. This change won't affect other procfs files neither Linux compat features within mount_procfs(8). /proc/#/ctl isn't available on Linux. Remove: - /proc/#/ctl from mount_procfs(8) - P_FSTRACE note from the documentation of ps(1) - /proc/#/ctl and filesystem tracing documentation from mount_procfs(8) - KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9) - source code file miscfs/procfs/procfs_ctl.c - PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h - KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h - PSL_FSTRACE (0x00010000) from sys/sys/proc.h - P_FSTRACE (0x00010000) from sys/sys/sysctl.h Reduce code complexity after removal of this functionality. Update TODO.ptrace accordingly: remove two entries about /proc tracing. Do not keep legacy notes as comments in the headers about removed PSL_FSTRACE / P_FSTRACE, as this interface had little number of users (close or equal to zero). Proposed on tech-kern@. All filesystem tracing utility users are encouraged to switch to ptrace(2). Sponsored by <The NetBSD Foundation>
2017-08-12Remove vm86.maxv
Pass 3.