Commit Graph

10725 Commits

Author SHA1 Message Date
ad
bacf374405 lwp_start(): don't try to change the target CPU. Fixes potential panic
in setrunnable(). Oops, experimental change that escaped.
2019-11-24 13:23:57 +00:00
ad
7b708f2a89 Put section attribute for turnstile0 in the correct place. For LLVM. 2019-11-24 13:14:23 +00:00
ad
c9afc9987a Pull in sys/atomic.h. 2019-11-23 22:35:08 +00:00
ad
11ba4e1830 Minor scheduler cleanup:
- Adapt to cpu_need_resched() changes. Avoid lost & duplicate IPIs and ASTs.
  sched_resched_cpu() and sched_resched_lwp() contain the logic for this.
- Changes for LSIDL to make the locking scheme match the intended design.
- Reduce lock contention and false sharing further.
- Numerous small bugfixes, including some corrections for SCHED_FIFO/RT.
- Use setrunnable() in more places, and merge cut & pasted code.
2019-11-23 19:42:52 +00:00
ad
398a7522b9 sched_tick: examine the correct LWP, and lock it. 2019-11-22 20:07:53 +00:00
ad
3cec1e7660 Minor correction to previous. 2019-11-22 20:04:03 +00:00
pgoyette
1fc74345e4 Use __diagused 2019-11-22 15:57:49 +00:00
maxv
ce425234cc Ah, strcat/strchr/strrchr are ASM functions, so instrument them. 2019-11-22 14:28:46 +00:00
rin
6df93363ad Fix regression introduced to ptrace_regs() in rev 1.27:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/kern/sys_ptrace_common.c#rev1.27

Size of registers should be determined from tracer, NOT tracee.

Now, 64-bit tracer can manipulate registers of 32-bit tracee again.
gdb for amd64 works for i386 binaries to some extent.

XXX
pullup to netbsd-9 and -8.
2019-11-22 05:01:44 +00:00
ad
b5034f0391 Minor improvements to select/poll:
- Increase the maximum number of clusters from 32 to 64 for large systems.
  kcpuset_t could potentially be used here but that's an excursion I don't
  want to go on right now.  uint32_t -> uint64_t is very simple.

- In the case of a non-blocking select/poll, or where we won't block
  because there are events ready to report, stop registering interest in
  the back-end objects early.

- Change the wmesg for poll back to "poll".
2019-11-21 21:42:30 +00:00
ad
c825105bdc - Don't give up kpriority boost in preempt(). That's unfair and bad for
interactive response.  It should only be dropped on final return to user.
- Clear l_dopreempt with atomics and add some comments around concurrency.
- Hold proc_lock over the lightning bolt and loadavg calc, no reason not to.
- cpu_did_preempt() is useless - don't call it.  Will remove soon.
2019-11-21 20:51:05 +00:00
ad
0e70dcbe0f lwp_setlock(): return pointer to the kmutex_t that we replaced 2019-11-21 19:47:21 +00:00
ad
faff59d5f7 Sleep queues & turnstiles:
- Avoid false sharing.
- Make the turnstile hash function more suitable.
- Increase turnstile hash table size.
- Make amends by having only one set of system wide sleep queue hash locks.
2019-11-21 18:56:55 +00:00
ad
f15dda4bcb lwp_create:
- Don't need to check for PK_SYSTEM when inheriting an affinity mask.
- Inherit processor set ID under proc_lock, to sync with pset syscalls.
2019-11-21 18:22:05 +00:00
ad
e57dd2ba56 - lwp_need_userret(): only do it if ONPROC and !curlwp, and explain why.
- Use signotify() in a couple more places.
2019-11-21 18:17:36 +00:00
ad
298a9247c2 Break the slow path for callout_halt() out into its own routine.
No functional change.
2019-11-21 17:57:40 +00:00
ad
bec282a611 Simplify pset locking, making it easier to sync with LWP creation, etc. 2019-11-21 17:54:04 +00:00
ad
b2d41f4afd calcru: ignore running softints, unless softint_timing is on.
Fixes crazy times reported for proc0.
2019-11-21 17:50:49 +00:00
ad
c8b094aa25 - Put back a microoptimisation that was accidentally removed.
- Comments.
2019-11-20 21:49:00 +00:00
pgoyette
1d577fe379 Move all non-emulation-specific coredump code into the coredump module,
and remove all #ifdef COREDUMP conditional compilation.  Now, the
coredump module is completely separated from the emulation modules, and
they can all be independently loaded and unloaded.

Welcome to 9.99.18 !
2019-11-20 19:37:51 +00:00
nia
3b8d461bce Update comment to reflect third-party software's usage of KERN_ARND.
Changing it as the comment suggests would be a very terrible idea due to
the common usage of this variable.

Returning only 32 or 64 bits also seems to be the purpose of KERN_URND,
so that functionality is already present.
2019-11-17 12:32:31 +00:00
rin
82833002ac Fix pointer arithmetic for 32-bit process on LP64 kernel in
process_auxv_offset().

Now, PIOD_READ_AUXV works fine with COMPAT_NETBSD32.

XXX
pullup to netbsd-9 and netbsd-8
2019-11-17 02:22:14 +00:00
maxv
1bb344ad1f NULL-check the structure pointer, not the address of its first field. Also
add KASSERT. For clarity, and to appease kUBSan.
2019-11-16 10:07:53 +00:00
maxv
c723c2d9ac Add a NULL check on the structure (same logic as my previous change in this
file). For clarity, and to appease kUBSan.
2019-11-16 10:05:44 +00:00
pgoyette
3cc6aaf161 Remove some XXX'd comments that were remnants of when I was working
on the [pgoyette-compat] code.

NFC
2019-11-16 03:26:19 +00:00
maxv
473e202ba1 NULL-check the structure pointer, not the address of its first field. This
is clearer and also appeases syzbot.

Reported-by: syzbot+d27bc1be926b3641c0ad@syzkaller.appspotmail.com
2019-11-15 15:51:57 +00:00
maxv
4602d0f902 Instrument ufetch/ustore in kMSan, these were the last remaining functions. 2019-11-15 12:18:46 +00:00
maxv
65ee926c5a Make kMSan compatible with KCOV. With kMSan we are forced to stay with the
fsanitize flag on subr_kcov.c, which means that kMSan will instrument KCOV.
We add a bunch of __nomsan attributes to reduce this instrumentation, but
it does not remove it completely. That's fine.
2019-11-15 09:44:44 +00:00
maxv
072e3fce8b Instrument copyout() in kCSan, for parity with kMSan. 2019-11-15 08:11:36 +00:00
maxv
59b172a87d Don't include "opt_kcsan.h" since there's already <sys/csan.h> included. 2019-11-14 16:56:13 +00:00
maxv
10c5b02320 Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
 - "shad", to track uninitialized memory with a bit granularity (1:1).
   Each bit set to 1 in the shad corresponds to one uninitialized bit of
   real kernel memory.
 - "orig", to track the origin of the memory with a 4-byte granularity
   (1:1). Each uint32_t cell in the orig indicates the origin of the
   associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
 - a code designating the type of memory (Stack, Pool, etc), and
 - a compressed pointer, which points either (1) to a string containing
   the name of the variable associated with the cell, or (2) to an area
   in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
2019-11-14 16:23:52 +00:00
pgoyette
86069f283e Return success if no coredump module is loaded/hooked. 2019-11-13 15:48:36 +00:00
mrg
d96b7a130a put the ucode not found message under #ifdef DEBUG. use printf()
instead of aprint_error().

there's an error returned to userland and displayed by cpuctl.
2019-11-13 01:31:47 +00:00
maxv
0cc65d2126 Remove lockless reads of 'xc_donep'. This is an uint64_t, and we cannot
expect the accesses to be MP-safe on 32bit arches.

Found by KCSAN.
2019-11-11 09:50:11 +00:00
joerg
ffac73eb32 Ensure that the second LWP of a new process uses a free LWP ID.
Document overflow behavior.
2019-11-10 23:39:03 +00:00
pgoyette
7384474702 Convert the coredump_vec modular function pointer to use the new
compat_hook mechanism.

XXX Should be pulled up to -9 despite the kernel <--> module ABI
XXX change.
2019-11-10 14:20:50 +00:00
pgoyette
7b0f5c9e07 Convert the sendsig_sigcontext_16 function pointer to use the new
compat_hook mechanism.

XXX Despite being a kernel<-->module abi change, this should be
XXX pulled up to -9
2019-11-10 13:28:06 +00:00
mlelstv
ab2ce32b2b Add functions to open devices by device number or path. 2019-11-10 06:47:30 +00:00
pgoyette
a87c3088cd If we need to handle old-version signals, load the version-specific
"compat_16" module.  There is no longer a monolithic "compat" module!

XXX pullup-9 needed
2019-11-09 23:34:13 +00:00
jdolecek
1d1057a273 do not try to rm sysautoload when it's not actually used for given compat;
script tried to rm /dev/null which failed
2019-11-09 22:05:50 +00:00
maxv
b081609ec2 Exclude the PTE space from KCSAN, since there the same VA can point to
different PAs.
2019-11-08 12:36:10 +00:00
kamil
ff408de6a7 Revert subr_disk_mbr.c r.1.54
Requested by <christos> as there can be a better way to fix the original
problem with alignment.
2019-11-07 20:34:29 +00:00
kamil
23fe401f2f Decorate check_label_magic() with __noubsan
Requested by <christos>
2019-11-07 20:30:49 +00:00
joerg
280b4162f9 Preserve the LWP ID of the calling thread on (v)fork. This ensures that
_lwp_self() remains invariant as necessary for the locking in the
dynamic linker. Otherwise if a process creates a thread and forks from
it, the main thread of the parent would share the LWP ID of the main
thread of the child, even though they have different origins.

Partial fix for pkg/54192.
2019-11-07 19:45:18 +00:00
kamil
185882ca80 Revert src/sys/kern/subr_disk_mbr.c r.1.52
Addressed in a better way in r. 1.53.
2019-11-07 18:35:41 +00:00
kamil
077b1ebea2 Ensure in validate_label() that struct disklabel pointer is 8-byte aligned
The label is searched each 4 bytes and can be detected in an unaligned
location. Before any operations on it, copy it to promptly aligned local
copy on the stack.

This is a missing part of the following change:

revision 1.108
date: 2011-01-18 20:52:24 +0100;  author: matt;  state: Exp;  lines: +2 -1;
Make struct disklabel 8 byte aligned.  This increases its size by 4 bytes
on IPL32 platforms so add code in sys_ioctl (and netbsd32_ioctl) to deal
with the older/smaller diskabel size.  This change makes disklabel the
same for both IPL32 and LP64 platforms

OK by <martin>
2019-11-07 18:30:27 +00:00
kamil
4e5cb50b58 Avoid unaligned pointer arithmetic in check_label_magic()
Replace the logic of calculating the address with with base + offset.

Reported by GCC8.

Reported-by: syzbot+56769dece0ec3e35731e@syzkaller.appspotmail.com
2019-11-06 13:07:32 +00:00
maxv
9cce0b0a08 Change kcsan_md_is_avail() to always return true; I was testing with
interrupts disabled as debugging. Change the delay/sample parameters
to have better fluidity.
2019-11-06 06:57:22 +00:00
maxv
b7edd3d132 Add Kernel Concurrency Sanitizer (kCSan) support. This sanitizer allows us
to detect race conditions at runtime. It is a variation of TSan that is
easy to implement and more suited to kernel internals, albeit theoretically
less precise than TSan's happens-before.

We do basically two things:

 - On every KCSAN_NACCESSES (=2000) memory accesses, we create a cell
   describing the access, and delay the calling CPU (10ms).

 - On all memory accesses, we verify if the memory we're reading/writing
   is referenced in a cell already.

The combination of the two means that, if for example cpu0 does a read that
is selected and cpu1 does a write at the same address, kCSan will fire,
because cpu1's write collides with cpu0's read cell.

The coverage of the instrumentation is the same as that of kASan. Also, the
code is organized in a way similar to kASan, so it is easy to add support
for more architectures than amd64. kCSan is compatible with KCOV.

Reviewed by Kamil.
2019-11-05 20:19:17 +00:00
mgorny
050caffe42 Fix a race condition when handling concurrent LWP signals and add a test
Fix a race condition that caused PT_GET_SIGINFO to return incorrect
information when multiple signals were delivered concurrently
to different LWPs.  Add a regression test that verifies that when 50
threads concurrently use pthread_kill() on themselves, the debugger
receives all signals with correct information.

The kernel uses separate signal queues for each LWP.  However,
the signal context used to implement PT_GET_SIGINFO is stored in 'struct
proc' and therefore common to all LWPs in the process.  Previously,
this member was filled in kpsignal2(), i.e. when the signal was sent.
This meant that if another LWP managed to send another signal
concurrently, the data was overwritten before the process was stopped.

As a result, PT_GET_SIGINFO did not report the correct LWP and signal
(it could even report a different signal than wait()).  This can be
quite reliably reproduced with the number of 20 LWPs, however it can
also occur with 10.

This patch moves setting of signal context to issignal(), just before
the process is actually stopped.  The data is taken from per-LWP
or per-process signal queue.  The added test confirms that the debugger
correctly receives all signals, and PT_GET_SIGINFO reports both correct
LWP and signal number.

Reviewed by kamil.
2019-10-21 17:07:00 +00:00
christos
0263994f06 regen 2019-10-21 14:23:53 +00:00
tnn
4d0eb0fca4 mcl_cache: align items to COHERENCY_UNIT
Because we do cache incoherent DMA to/from mbufs we cannot safely share
share cache lines with adjacent items that may be concurrently accessed.
2019-10-19 06:36:47 +00:00
christos
626e72c16b print which process asked for an unsupported event so we can fix it. 2019-10-18 19:43:49 +00:00
christos
176ada4b2b Add and use __FPTRCAST, requested by uwe@ 2019-10-16 18:29:49 +00:00
christos
d2348edc56 Add void * function pointer casts. There are different ways to "fix" those
warnings:
    1. this one: add a void * cast (which I think is the least intrusive)
    2. add pragmas to elide the warning
    3. add intermediate inline conversion functions
    4. change the called function prototypes, adding unused arguments and
       converting some of the pointer arguments to void *.
    5. make the functions varyadic (which defeats the purpose of checking)
    6. pass command line flags to elide the warning
I did try 3 and 4 and I was not pleased with the result (sys_ptrace_common.c)
(3) added too much code and defines, and (4) made the regular use clumsy.
2019-10-16 15:27:38 +00:00
kamil
29be9f8e91 Remove the short-circuit lwp_exit() path from sigswitch()
sigswitch() can be called from exit1() through:

   ttywait()->ttysleep()-> cv_timedwait_sig()->sleepq_block()->issignal()->sigswitch()

lwp_exit() called for the last LWP triggers exit1() and this causes a panic.

The debugger related signals have short-circuit demise paths in
eventswitch() and other functions, before calling sigswitch().

This change restores the original behavior, but there is an open question
whether the kernel crash is a red herring of misbehavior of ttywait().

This should fix PR kern/54618 by David H. Gutteridge
2019-10-15 13:59:57 +00:00
maxv
7b43da9e77 Add a check before the memcpy. memcpy is defined to never take NULL as
second argument, and the compiler is free to perform optimizations knowing
that this argument is never NULL.

In this particular case, it was harmless. But still good to fix.

Reported-by: syzbot+6f504255accb795eb6b7@syzkaller.appspotmail.com
2019-10-14 16:27:03 +00:00
christos
843ff516d3 cast nullop though void * 2019-10-13 22:31:19 +00:00
kamil
305335a1e9 Avoid double lwp_exit() in eventswitch()
For the PTRACE_LWP_EXIT event, the eventswitch() call is triggered from
lwp_exit(). In the case of setting the program status to PS_WEXIT, do not
try to demise in place, by calling lwp_exit() as it causes panic.

In this scenario bail out from the function and resume the lwp_exit()
procedure.
2019-10-13 03:50:26 +00:00
kamil
130e572a10 Fix one the the root causes of unreliability of the ptrace(2)ed threads
In case of sigswitchin away in issignal() and continuing the execution on
PT_CONTINUE (or equivalent call), there is a time window when another
thread could cause the process state to be changed to PS_STOPPING.

In the current logic, a thread would receive signal 0 (no-signal) and exit
from issignal(), returning to userland and never finishing the process of
stopping all LWPs. This causes hangs waitpid() waiting for SIGCHLD and
the callout polling for the state of the process in an infinite loop.

Instead of prompting for a returned signal from a debugger, repeat the
issignal() loop, this will cause checking the PS_STOPPING flag again and
sigswitching away in the scenario of stopping the process.
2019-10-13 03:19:57 +00:00
kamil
0998dd273e Add sigswitch_unlock_and_switch_away(), extracted from sigswitch()
Use sigswitch_unlock_and_switch_away() whenever there is no need for
sigswitch().
2019-10-13 03:10:22 +00:00
kamil
1249b6bf7e Refactor sigswitch()
Make the function static as it is now local to kern_sig.c.

Rename the 'relock' argument to 'proc_lock_held' as it is more verbose.
This was suggested by mjg@freebsd. While there this flips the users between
true<->false.

Add additional KASSERT(9) calls here to validate whethe proc_lock is used
accordingly.
2019-10-12 19:57:09 +00:00
kamil
c18c9a670f Avoid signed integer overflow for -lwp where lwp is INT_MIN
Reported-by: syzbot+68b80b44b898e66da3fc@syzkaller.appspotmail.com
2019-10-12 12:04:37 +00:00
kamil
b3bca7a74f Remove p_oppid from struct proc
This field is not needed as it duplicated p_opptr that is alread safe to
use, unless proven otherwise.

eventswitch() already contained a check for != initproc (pid1).

Ride ABI bump for 9.99.16.
2019-10-12 10:55:23 +00:00
hannken
1abb473536 Regen. 2019-10-11 08:05:19 +00:00
hannken
f8da5187dc As VOP_STRATEGY() usually calls itself on the file system holding "/dev"
it may deadlock on suspension of this file system.

Add fstrans type LAZY and use it for VOP_STRATEGY().

Adress PR kern/53624 (dom0 freeze on domU exit) is still there
2019-10-11 08:04:52 +00:00
maxv
1677a78849 Add KASAN instrumentation on ucas and ufetch. 2019-10-10 13:45:14 +00:00
chs
cf529c6de1 simpler fix for the race between shmat() and shmdt():
change shmat() to hold shm_lock until it is completely done.
2019-10-09 17:47:13 +00:00
chs
a851cc5747 revert rev 1.139 (fixing a race between shmat() and shmdt())
that approach turned out to be too complicated.
2019-10-09 17:44:45 +00:00
kamil
2e7e73e2ed Introduce new ptrace(2) operation PT_STOP
It works like:

 - kill(SIGSTOP) for unstopped tracee
 - ptrace(PT_CONTINUE,SIGSTOP) for stopped tracee

The child will be stopped and always possible to be waited (with wait(2)
like calls).

For stopped traccee kill(SIGSTOP) has no effect. PT_CONTINUE+SIGSTOP cannot
be used on an unstopped process (EBUSY).

This operation is modeled after PT_KILL that is similar for the SIGKILL
call. While there, allow PT_KILL on unstopped traced child.

This operation is useful in an abnormal exit of a debugger from a signal
handler, usually followed by waitpid(2) and ptrace(PT_DETACH).
2019-10-09 13:19:43 +00:00
skrll
208170f3b1 Traiing whitespace 2019-10-09 05:59:51 +00:00
christos
b0424b9dde - cast through void * for rump
- don't generate bogus filenames /dev/null.bottom etc.
2019-10-09 01:43:00 +00:00
kamil
f3a317a980 Enhance reliability of ptrace(2) in a debuggee with multiple LWPs
Stop competing between threads which one emits event signal quicker and
overwriting the signal from another thread.

This fixes missed in action signals.

NetBSD truss can now report reliably all TRAP_SCE/SCX/etc events without
reports of missed ones.

his was one of the reasons why debuggee with multiple threads misbehaved
under a debugger.


This change is v.2 of the previously reverted commit for the same fix.

This version contains recovery path that stopps triggering event SIGTRAP
for a detached debugger.
2019-10-08 18:02:46 +00:00
kamil
60274cdd77 Correct the same expression on both sides of |
PR sw-bug/54610 by David Binderman
2019-10-08 12:29:57 +00:00
mrg
a2fd483377 steal an idea from uwe@ and implement gcc-8 function type cast
friendly methods for sys/conf.h that needs it.

one alias per return type and first function are are needed,
though they can be stubbed to existing code.  the only cost is
the symbol itself, the codegen it the same.
2019-10-08 07:33:14 +00:00
kamil
815185c6dc Fix typo in a comment 2019-10-07 21:32:51 +00:00
uwe
edcef67ec2 xc_barrier - convenience function to xc_broadcast() a nop.
Make the intent more clear and also avoid a bunch of (xcfunc_t)nullop
casts that gcc 8 -Wcast-function-type is not happy about.
2019-10-06 15:11:16 +00:00
uwe
9d5b26a9e3 Define cpu_xc_* functions with unused second argument to make them
conform to xcfunc_t callback typedef (-Wcast-function-type).
Same object code is generated.
2019-10-06 02:04:26 +00:00
kamil
8e3fd5b698 Check for valid timespec in clock_settime1()
An alternative approach would be to check the valie in settime1(), but
it would result in multiple checks for valid tv_nsec, as there are
settime1() users that need to check the ranges earlier.

Reported-by: syzbot+96e5ce2c2c704d96c2f0@syzkaller.appspotmail.com
2019-10-05 12:57:40 +00:00
kamil
fa6363e636 Avoid -LONG_MIN msgtyp in msgrcv(2) and treat it as LONG_MAX
This logic (found in Linux) avoids undefined behavior.

Reported-by: syzbot+8af00519a8688d9903ca@syzkaller.appspotmail.com
2019-10-04 23:20:22 +00:00
kamil
ffd5d3e30b Avoid signed integer overflow in ts2timo() for ts->tv_nsec
The condition would be rechecked later again after subtracting start time
and most invalid inputs rejected. In corner cases the current code can
accept certain invalid inputs that will pass checks later and behave like
valid ones (due to signed integer overflow).

Reported-by: syzbot+3a4a07b62558bbbd3baa@syzkaller.appspotmail.com
2019-10-04 14:17:07 +00:00
maxv
36beaf9ddd Add DMA instrumentation in KASAN. We note the original buffer and length in
the map, and check the buffer on each bus_dmamap_sync. This allows us to
find DMA buffer overflows and UAFs, which couldn't be found before because
the device accesses to memory are outside of KASAN's control.
2019-10-04 06:27:42 +00:00
kamil
96755fb8d4 Add two KASSERTS in the ptrace(2) kernel code
Verify that we will never return empty ptrace_state for CHILD/LWP event.
2019-10-03 23:11:11 +00:00
kamil
a35a4fe3b8 Separate flag for suspended by _lwp_suspend and suspended by a debugger
Once a thread was stopped with ptrace(2), userland process must not
be able to unstop it deliberately or by an accident.

This was a Windows-style behavior that makes threading tracing fragile.
2019-10-03 22:48:44 +00:00
kamil
2b5fbe86ad Remove compile-time asserts checking whether intptr_t and void* are compat
The checks were requested by core@ as a prerequisite for kevent::udata type
switch from intptr_t to void*.
2019-10-03 22:29:17 +00:00
kamil
2f629ee89a Remove 2 static asserts from the kernel ptrace code
sizeof(pid) and sizeof(lwp) will unlikely ever change and the check can
confuse.

The assert has been moved to ATF t_ptrace_wait.c r.1.132.

Requested by <christos>
2019-10-01 21:49:50 +00:00
kamil
c1b8181461 Restore the old behavior in PT_GET_PROCESS_STATE
For !child and !lwp events return zeroed struct ptrace_state.

There is code that depends on it (GDB).

Fixes PR toolchain/54590 by martin@
2019-10-01 18:44:22 +00:00
chs
db38f3713d in shmdt(), wait until shmat() completes before detaching.
Reported-by: syzbot+8f470a1bf36b47ae0040@syzkaller.appspotmail.com
Reported-by: syzbot+45810b4c41ed65d9148d@syzkaller.appspotmail.com
2019-10-01 16:36:58 +00:00
cnst
da5825f8ed kern/subr_disk: bounds_check_with_label: really protect against div by zero
Solves kernel panic in NetBSD 8.1 amd64 on VirtualBox 6.0.12 r133076.

Triggered with an NVMe controller without any actual discs behind it:

nvme0 at pci0 dev 14 function 0: vendor 80ee product 4e56 (rev. 0x00)
nvme0: NVMe 1.2
nvme0: interrupting at ioapic0 pin 22
nvme0: ORCL-VBOX-NVME-VER12, firmware 1.0, serial VB1234-56789
ld0 at nvme0 nsid 1
ld0: 0, 0 cyl, 16 head, 63 sec, 1 bytes/sect x 0 sectors

Code path is reached 4 times during normal boot, each time after wd0a
is already mounted; this patch avoids a crash with a dirty filesystem.
2019-09-30 23:23:59 +00:00
kamil
5e4bbc4985 Move TRAP_CHLD/TRAP_LWP ptrace information from struct proc to siginfo
Storing struct ptrace_state information inside struct proc was vulnerable
to synchronization bugs, as multiple events emitted in the same time were
overwritting other ones.

Cache the original parent process id in p_oppid. Reusing here p_opptr is
in theory prone to slight race codition.

Change the semantics of PT_GET_PROCESS_STATE, reutning EINVAL for calls
prompting for the value in cases when there wasn't registered an
appropriate event.

Add an alternative approach to check the ptrace_state information, directly
from the siginfo_t value returned from PT_GET_SIGINFO. The original
PT_GET_PROCESS_STATE approach is kept for compat with older NetBSD and
OpenBSD. New code is recommended to keep using PT_GET_PROCESS_STATE.

Add a couple of compile-time asserts for assumptions in the code.

No functional change intended in existing ptrace(2) software.

All ATF ptrace(2) and ATF GDB tests pass.

This change improves reliability of the threading ptrace(2) code.
2019-09-30 21:13:33 +00:00
rhialto
1c7f0224e7 Do all delta calculations strictly using uint32_t. Avoid integer
overflows in calculating absolute deltas by subtracting the right way
around.

Reported-by: syzbot+68c37d09c833f8ec1341@syzkaller.appspotmail.com
2019-09-29 12:07:52 +00:00
jmcneill
a20d501e5a mbstat_conver_to_user_cb -> mbstat_convert_to_user_cb 2019-09-28 16:02:12 +00:00
pgoyette
ccc3f35b62 Actually return the updated pointer-to-mbuf-pointer to the caller
rather than discarding-after-assignment.  Introduced from the
[pgoyette-compat] branch work.

Welcome to 9.99.14 !!!  (Module hook routine prototype changed.)

Found by the lgtm bot, reported via private Email from maxv@
2019-09-27 00:32:03 +00:00
christos
fc72d154af make nmountcompatnames unsigned (assigned from __arraycount, compared with
unsigned in compat code)
2019-09-26 01:34:16 +00:00
kamil
6f22d54e25 Add a temporary ctassert checking whether void* and intptr_t are compatible 2019-09-24 19:21:45 +00:00
skrll
aeef4b9a0b Enable POOL_REDZONE with DIAGNOSTIC.
The bug in the arm pmap was fixed long ago.
2019-09-23 05:39:59 +00:00
christos
ff17893526 regen 2019-09-22 23:03:20 +00:00
christos
02cdd248ec Add a new member to struct vfsstat and grow the unused members
The new member is caled f_mntfromlabel and it is the dkw_wname
of the corresponding wedge. This is now used by df -W to display
the mountpoint name as NAME=
2019-09-22 22:59:37 +00:00
maxv
7b2608b508 Fix KASAN on aarch64: the bus_space_* functions are macros, so we can't
redefine them. Introduce __HAVE_KASAN_INSTR_BUS, which indicates whether
to instrument the bus functions. Defined on amd64 only.
2019-09-22 10:35:12 +00:00
kamil
0af3675487 Validate usec ranges in sys___select50()
Later in the code selcommon() checks for proper timespec, check only
correct usec of timeval before type conversions.
2019-09-20 15:00:47 +00:00