Commit Graph

1885 Commits

Author SHA1 Message Date
christos b52554b0d5 Zero out the ifreq struct for SIOCGIFCONF to avoid up to 127 bytes of stack
disclosure. From Andy Nguyen, many thanks! This is the compat code part
pointed out by ozaki-r@
2019-04-18 17:45:12 +00:00
thorpej 91bfaeb675 Overhaul the API used to fetch and store individual memory cells in
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-04-06 03:06:23 +00:00
christos 03d46ac0fc make this compile again. 2019-03-26 02:05:28 +00:00
maxv 27667013cc regen 2019-03-24 16:39:46 +00:00
maxv ddc423bf95 Remove Alpha's compat_linux dependency on compat_osf1. Each function is
copied as-is from compat_osf1 with no functional change. Discussed on
tech-kern@, ok @thorpej.
2019-03-24 16:24:19 +00:00
maxv 46e1422377 Fix a tiny race in setregs and linux_setregs. Between the moment we set
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-24 13:15:42 +00:00
pgoyette 8c2f80f160 Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.

NFCI intended.

Ride the earlier kernel bump - it;s getting crowded.
2019-03-01 11:06:55 +00:00
mrg 39e3203eaa for sysv ipc stat operations, explicitly copy the exported parts
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-21 03:37:18 +00:00
mrg fd676684f8 - avoid uninitialised memory usage 2019-02-04 04:37:50 +00:00
mrg fbffadb9f8 - add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
  this case, and thus can't be marked __dead easily
2019-02-03 03:19:25 +00:00
pgoyette d91f98a871 Merge the [pgoyette-compat] branch 2019-01-27 02:08:33 +00:00
maxv 1eb384e338 Improve my kern_time.c::rev1.192, systematically clear the buffers we get
from 'ptimer_pool' to prevent more leaks.
2018-11-29 17:40:12 +00:00
hannken d22a72be5c Apply the recent fixes to {send,recv}mmsg() to their compat variants. 2018-11-14 17:51:37 +00:00
riastradh d1579b2d70 Rename min/max -> uimin/uimax for better honesty.
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-09-03 16:29:22 +00:00
msaitoh 61e1eb0d0b - Cleanup for dynamic sysctl:
- 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-22 01:05:21 +00:00
pgoyette fb243de875 Regen 2018-08-10 21:47:14 +00:00
pgoyette 3cd7406ad8 Allow syscall_establish() to install new syscalls when the existing
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-08-10 21:44:58 +00:00
christos a03af6c5f4 - fix constants and explain limit
- use machine32 instead of hard-coded x86 stuff
2018-07-15 21:31:00 +00:00
msaitoh 9ab5372263 Fix compile error. 2018-07-09 05:43:35 +00:00
christos 8be2e96dbe Enable executing linux go binaries by using a special probe function for them. 2018-07-08 17:58:39 +00:00
ozaki-r a54c6ac17b Fix pserialize enter/exit pairs in linux_getifconf and linux32_getifconf
Tested by using a small linux program that uses ioctl(SIOCGIFCONF).
Probably fix PR kern/53259 as well.
2018-05-10 01:32:24 +00:00
kamil 2f1d1558aa Remove an element from struct emul: e_tracesig
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-06 13:40:50 +00:00
christos 331cb3c9dd Fix COMPAT_NETBSD32 cmsg handling:
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-05-03 21:43:33 +00:00
kamil d20c39ee39 Remove the rnewprocp argument from fork1(9)
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-16 14:51:59 +00:00
kamil dfb49eea50 Remove unused variable p from linux_sys_clone()
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-04-15 03:25:25 +00:00
christos 8cb1b0010b PR/53103: Timo Buhrmester: linux emulation of sendto(2) broken
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-03-16 17:25:04 +00:00
christos 516181531f union was removed 2018-01-26 09:29:15 +00:00
skrll ac34435581 Remove port-acorn26
OK core@
2018-01-24 09:04:40 +00:00
maya 45b55008a4 remove struct emul's e_fault.
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-09 20:55:42 +00:00
christos dda917e683 Ignore signal 64 for now (go uses it)
XXX: pullup-8
2018-01-07 21:14:38 +00:00
maxv 98ae6a49f7 Use the default %cs, and mask the other segregs. 2018-01-01 08:03:43 +00:00
kamil d46f49d32a Refactor pipe1() and correct a bug in sys_pipe2() (SYS_pipe2)
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-26 08:30:57 +00:00
kre a2da047f16 Finally (hopefully) return completely to the state where compat_linux is
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-10 00:43:05 +00:00
kre 9f22166744 Finish the previous change - as well as setting the default for these
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-08 15:31:13 +00:00
joerg c08407dd01 Unbreak Linux emulation by default. While not loading it automatically
is somewhat sensible, breaking functionality of GENERIC is not and has
been objected to on a regular base.
2017-12-01 22:14:52 +00:00
ozaki-r a78ad86cbf Fix and make consistent of usages of psz/psref in ifconf variants 2017-11-22 10:19:14 +00:00
maxv f5676abd4d This should be "linux_sg_version", not "version". 2017-11-21 10:45:12 +00:00
maxv 576743ba1e Include opt_user_ldt.h when needed. 2017-10-21 07:24:26 +00:00
maxv 1fe402e2a1 Always mask the 16 bits of the segregs in the trapframe. We don't zero-
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-19 10:01:09 +00:00
maxv f10c10f470 Use two separate functions: cpu_segregs32_zero and cpu_segregs64_zero. The
way segment registers work on amd64 will diverge between 32bit and 64bit
LWPs.
2017-10-15 12:49:53 +00:00
maxv aef145dda9 Remove compat_linux from the autoload list, and add a sysctl to enable or
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-29 17:08:00 +00:00
maxv 7ad103f49c Remove the second argument from USERMODE and KERNELMODE, it is unused
now that we don't have vm86 anymore.
2017-09-17 09:41:35 +00:00
kamil a69b333e73 Remove the filesystem tracing feature
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-28 00:46:06 +00:00
maxv 9e6f33ab7c Remove vm86.
Pass 3.
2017-08-12 07:21:57 +00:00
maxv 7a3268ffdb Remove vm86. Simplifies a number of critical places.
Pass 2.
2017-08-12 07:07:53 +00:00
riastradh d82060bc36 Put suser check in the right function: settimeofday, not gettimeofday.
While here, remove wrong comment.

Noted by kre@.
2017-07-29 02:31:22 +00:00
riastradh 787a001e33 Only let the superuser set the compat_linux timezone.
Not really keen to invent a new kauth cookie for this useless purpose.

From Ilja Van Sprundel.
2017-07-29 01:14:59 +00:00
riastradh 39f1e86852 Fail, don't panic, on bad dirents from file system.
Controllable via puffs from userland.

From Ilja Van Sprundel.
2017-07-28 15:34:06 +00:00
maxv e26423f71c Don't forget to clean l_md.md_flags, otherwise there may be MDL_COMPAT32,
in which case the kernel would always use iret (slower).
2017-07-14 13:21:29 +00:00
riastradh 9c32900485 regen 2017-05-10 06:19:47 +00:00