Commit Graph

10132 Commits

Author SHA1 Message Date
kamil
85b6812c20 Avoid undefined behavior in lwp_ctl_alloc()
Do not left shift signed integer in a way that the signedness bit is
changed.

sys/kern/kern_lwp.c:1849:27, left shift of 1 by 31 places cannot be represented in type 'int'

Detected with Kernel Undefined Behavior Sanitizer.

Reported by <Harry Pantazis>
2018-07-04 18:13:01 +00:00
kamil
3884f1a8ff Avoid undefined behavior in mq_send1()
Do not shift a signed integer causing change of the signed bit.

sys/kern/sys_mqueue.c:881:23, left shift of 1 by 31 places cannot be represented in type 'int'

Detected with Kernel Undefined Behavior Sanitizer.

Reported by <Harry Pantazis>
2018-07-04 17:50:18 +00:00
kamil
98eac77405 Avoid undefined behavior in mq_recv1()
Do not shift a signed integer causing change of the signed bit.

sys/kern/sys_mqueue.c:712:24, left shift of 1 by 31 places cannot be represented in type 'int'

Detected with Kernel Undefined Behavior Sanitizer.

Reported by <Harry Pantazis>
2018-07-04 17:39:12 +00:00
msaitoh
bf88e6fa0d Don't allocate memory and return EFTYPE if sc->sc_blobsize==0 to prevent
panic in firmware_malloc().
2018-07-04 07:25:47 +00:00
kamil
235e36ecf7 Avoid undefined behavior in pr_item_notouch_put()
Do not left shift a signed integer changing its signedness bit.

sys/kern/subr_pool.c:251:30, left shift of 1 by 31 places cannot be represented in type 'int'

Detected with Kernel Undefined Behavior Sanitizer.

Reported by <Harry Pantazis>
2018-07-04 02:19:02 +00:00
kamil
501bcee4da Avoid Undefined Behavior in pr_item_notouch_get()
Change the type of left shifted integer from signed to unsigned.

sys/kern/subr_pool.c:274:13, left shift of 1 by 31 places cannot be represented in type 'int'

Detected with Kernel Undefined Behavior Sanitizer.

Reported by <Harry Pantazis>
2018-07-04 01:42:37 +00:00
kamil
bf95c9b8f0 Avoid unportable signed integer left shift in fd_unused()
Detected with Kernel Undefined Behavior Sanitizer.

There were at least a single place reported, for consistency fix all the
left bit shift operations.
sys/kern/kern_descrip.c:345:2, left shift of 1 by 31 places cannot be represented in type 'int'
sys/kern/kern_descrip.c:346:28, left shift of 1 by 31 places cannot be represented in type 'int'

Reported by <Harry Pantazis>
2018-07-03 23:14:57 +00:00
kamil
11d85a2701 Avoid unportable signed integer left shift in fd_copy()
Detected with Kernel Undefined Behavior Sanitizer.

There were at least a single place reported, for consistency fix all the
left bit shift operations.
sys/kern/kern_descrip.c:1492:3, left shift of 1 by 31 places cannot be represented in type 'int'
sys/kern/kern_descrip.c:1493:28, left shift of 1 by 31 places cannot be represented in type 'int'

Reported by <Harry Pantazis>
2018-07-03 23:11:06 +00:00
kamil
4c40a51b4d Avoid unportable signed integer left shift in fd_isused()
Detected with Kernel Undefined Behavior Sanitizer.

sys/kern/kern_descrip.c:188:34, left shift of 1 by 31 places cannot be represented in type 'int'

Reported by <Harry Pantazis>
2018-07-03 22:49:51 +00:00
jdolecek
d11231318a add DIAGNOSTIC check for rnd_attach_source() being called twice for same
rnd source; it's driver error, and it breaks rnd source list pointers
2018-07-03 18:09:28 +00:00
kamil
af399e1ecf Avoid unportable signed integer left shift in fd_used()
Detected with Kernel Undefined Behavior Sanitizer.

There were at least a single place reported, for consistency fix all the
left bit shift operations.
sys/kern/kern_descrip.c:302:26, left shift of 1 by 31 places cannot be represented in type 'int'

Reported by <Harry Pantazis>
2018-07-03 12:17:54 +00:00
ozaki-r
1350b04367 Fix net.inet6.ip6.ifq node doesn't exist
The node (and child nodes) is initialized in sysctl_net_pktq_setup, but the call
of sysctl_net_pktq_setup is skipped unexpectedly.

sysctl_net_pktq_setup is skipped if in6_present is false that indicates the
netinet6 component isn't loaded on rump kernels.  However the flag is
accidentally always false because the flag is turned on in in6_dom_init that is
called after if_sysctl_setup on both normal and rump kernels.

Fix the issue by moving if_sysctl_setup after in6_dom_init (domaininit on normal
kernels).  This fix is ad-hoc but good enough for netbsd-8.  We should refine
the initialization order of network components in the future.

Pointed out by hikaru@
2018-07-03 03:37:03 +00:00
riastradh
92e1684438 Revert "Sprinkle cold conditionals to make tc_ticktock before inittimecounter."
Not needed if we're no longer doing tc_ticktock in printf.
2018-07-01 15:12:06 +00:00
jmcneill
aeec0e9736 Revert previous 2018-07-01 09:53:54 +00:00
riastradh
79ad738888 Sprinkle cold conditionals to make tc_ticktock before inittimecounter.
Enables Xen to boot again.

XXX Maybe we should have a tc_ticktock_cold instead or something so we
don't have to reach this far into the call graph.
2018-06-30 22:47:51 +00:00
jmcneill
ca5cdadb4c When cold, manually update timecounters before calling getnanouptime. Now
kernel printf timestamps are updated properly before interrupts are
enabled.
2018-06-30 17:15:01 +00:00
kre
873631e713 Fix module build.
Options SUIDSCRIPTS and FDSCRIPTS will be off for the module.
If one (or both) should be enabled, add it to CPPFLAGSin the module Makefile.
2018-06-30 11:10:54 +00:00
christos
f3e9eebed2 defflag {SETUID,FD}SCRIPTS 2018-06-30 00:37:37 +00:00
thorpej
feee3a19f4 In my quest to make device_compatible_entry (and associated goo)
super-general, it turns out I also made it a little to cumbersome
to use (if my tired fingers are any indication).  So, this is a
course-correction -- one string per entry (like of_compat_data,
which it will soon replace), and remove the over-verbose macros.
2018-06-26 06:03:57 +00:00
thorpej
408f5aa571 Change device_compatible_match() and iic_compatible_match() to return
the weighted match value and take an optional compatible-entry pointer,
rather than the other way around.
2018-06-26 04:32:35 +00:00
jakllsch
b853854c44 add a kobj_error() to a recently added error case 2018-06-23 14:22:30 +00:00
christos
d2ef544d72 Add some debugging in case someone else wants to debug gdb... 2018-06-23 03:32:48 +00:00
thorpej
31877e2554 Sigh, fix another stupid mistake in previous that squeaked by because,
again, I booted the wrong test kernel.
2018-06-19 04:10:51 +00:00
thorpej
bd0f6c9df4 Fix a silly mistake in device_compatible_entry_matches() that I made
while re-factoring this from a prior version.

(I booted the wrong kernel when testing, oops.)
2018-06-18 16:31:42 +00:00
thorpej
3afafc8ac9 Add device_compatible_match(), a generalized routine for weighted
matching of device_compatible_entry data to a device's "compatible"
strings.
2018-06-18 15:36:54 +00:00
ozaki-r
21f6c0a11a Don't wait on workqueue_wait if called from worker itself
Otherwise workqueue_wait never return in such a case.  This treatment
is the same as callout_halt.
2018-06-13 05:26:12 +00:00
jdolecek
3d8c9e20d7 convert the (still disabled) 'direct write' for pipes to use the
experimental PMAP_DIRECT if available; the direct code paths now survive
longer than the pmap_enter() variant, but still triggers panic during
build.sh tools run; remove some obsolete sysctls

add some XXXs to mark places which need attention to make this more stable

Note: the loan case is now actually significantly slower than the
non-loan case on MP systems, due to synchronous IPIs triggered by
marking the page read-only by uvm_loan(); this is being discussed
in the email thread
https://mail-index.netbsd.org/tech-kern/2018/05/21/msg023441.html

that is basically the same issue due to which loaning was disabled
for sosend()
2018-06-10 17:54:51 +00:00
roy
ac571c1616 Separate receive socket errors from general socket errors. 2018-06-06 09:46:46 +00:00
jakllsch
a7c48ad938 Make identification of accounted aprint_error()s possible by putting a
big ugly "autoconfiguration error: " in the log when they occur.
2018-06-03 15:26:03 +00:00
kamil
edd6979004 Simplify comparison of two processes
No need to check p_pid to compare whether two processes are the same.

No functional change intended.

Sponsored by <The NetBSD Foundation>
2018-05-30 23:54:03 +00:00
kamil
be7413dae4 Harden PT_ATTACH in ptrace(2)
Don't allow to PT_ATTACH from a vfork(2)ed child (before exec(3)/_exit(3))
to its parent. Return error with EPERM errno.

This scenario does not have a purpose and there is no clear picture how to
route signals.

Sponsored by <The NetBSD Foundation>
2018-05-29 23:34:18 +00:00
chs
ba2539a980 merge a new version of the CDDL dtrace and ZFS code.
this changes the upstream vendor from OpenSolaris to FreeBSD,
and this version is based on FreeBSD svn r315983.

in addition to the 10 years of improvements from upstream,
this version also has these NetBSD-specific enhancements:
 - dtrace FBT probes can now be placed in kernel modules.
 - ZFS now supports mmap().
2018-05-28 21:04:59 +00:00
chs
5131193704 add copyin_pid(), to copyin from a different user address space. 2018-05-28 21:04:41 +00:00
chs
d5abe492a8 add more accessor functions for various struct module fields.
add a mechanism for registering callbacks to be called upon module load/unload.
2018-05-28 21:04:40 +00:00
kamil
616431328e Revert previous
There is a regression not covered by tests.
2018-05-28 14:07:37 +00:00
kamil
e30cee8d3c Enhance the signal routing of a trapsignal under a debugger
Stop resetting signal masks for crash signals under a debugger.

If we set a trap (either software or hardware one) in the code, we don't
want to see reset of signal handlers in a traced child as a knock-on effect
in the original code.

Maintain the vfork(2) + ptrace(2) special case functional.

No regressions are observed in ATF ptrace(2) and kernel/t_trapsignal tests.

Sponsored by <The NetBSD Foundation>
2018-05-28 13:12:54 +00:00
kamil
91c86a0a28 Correct reporting SIGTRAP TRAP_EXEC when SIGTRAP is masked
Switch from kpsignal(9) to sigswitch() as it allows to bypass signal
masking rules of a crash signal.

There are no regressions in existing tests.

Sponsored by <The NetBSD Foundation>
2018-05-28 11:32:20 +00:00
kamil
20c051d726 Make stopsigmask a non-static symbol now as it's used in ptrace(2) code
This is a missing part of the previous commit.

While there fix a typo in a newly added comment in the ptrace(2) code.

Sponsored by <The NetBSD Foundation>
2018-05-20 04:00:35 +00:00
kamil
7f2cb72e7e Fix and enable traceme_signal_nohandler2 in ATF ptrace(2) tests
traceme_signal_nohandler2 checks emitting SIGSTOP to a traced process
with the PT_CONTINUE operation.

The expected behavior is to simulate a behavior of receiving SIGSTOP,
generating SIGCHLD to its parent (in this case the debugger) and ability
to call wait(2)-like function receiving the stopped child event.

The previous behavior was unstopping the process and it has been adjusted
in the kernel code.

FreeBSD keeps unstopping a process for emitting SIGSTOP.
Linux handles this scenario in the same way as NetBSD now.

While there, implement the missing bits in the userland ATF test for
traceme_signal_nohandler2: receiving and validating 2nd SIGSTOP event and
continuing the process, followed by its normal termination.

Sponsored by <The NetBSD Foundation>
2018-05-20 03:51:31 +00:00
jdolecek
482e5d893a Remove emap support. Unfortunately it never got to state where it would be
used and usable, due to reliability and limited & complicated MD support.

Going forward, we need to concentrate on interface which do not map anything
into kernel in first place (such as direct map or KVA-less I/O), rather
than making those mappings cheaper to do.
2018-05-19 11:39:37 +00:00
kamil
be40f4a1f5 Stop masking raise(SIGSTOP) in a vfork(2)ed child that called PT_TRACE_ME.
Sponsored by <The NetBSD Foundation>
2018-05-19 05:01:42 +00:00
kamil
73bcea99d7 Stop masking SIGSTOP in a vfork(2)ed child
Keep the traditional BSD behavior masking SIGTSTP, SIGTTIN and SIGTTOU in
a vfork(2)ed child before exec(3)/exit(3). This is useful in shells and
prevents deadlocking, when a parent cannot unstop the sleeping child.

Change the behavior for SIGSTOP. This signal is by design not maskable and
this property shall be obeyed without exceptions. The STOP behavior is
expected in the context of debuggers and useful in standalone programs.

It is still possible to stop a vfork(2)ed child, however it requires
proc.curproc.stopfork=1, but it is not a flexible solution.

FreeBSD and OpenBSD keep masking SIGSTOP in a vfork(2)ed child.
Linux does not mask stop signals in the same scenarios.

This fixes ATF test: t_vfork:raise2.
No known regressions reported in the existing ATF tests.

Discussed with <kre>

Sponsored by <The NetBSD Foundation>
2018-05-19 02:42:58 +00:00
kamil
108bf35cd1 Correct handling of: vfork(2) + PT_TRACE_ME + raise(2)
Follow the FreeBSD approach of not routing signals to the parent that is
a became tracer after calling PT_TRACE_ME by the vfork(2)ed child (before
exec(3)/exit(3)).

Now if a child calls raise(3), the signal is processed directly to this
child.

Add new ATF ptrace(2) tests:
 - traceme_vfork_raise1 (SIGKILL)
 - traceme_vfork_raise2 (SIGSTOP) // temporarily disabled
 - traceme_vfork_raise3 (SIGABRT)
 - traceme_vfork_raise4 (SIGHUP)
 - traceme_vfork_raise5 (SIGCONT)

The FreeBSD implementation introduces P_PPTRACE for this special case.
Right know keep opencoding check of this case in the kernel. It might be
refactored in future.

The Linux kernel does not follow this approach and causes dead locking of
the processes (parent and child).

Defer handling SIGSTOP into future.

This is an intermediate step towards correct handling of fork(2) and
vfork(2) in the context of ptrace(2).

All new tests pass.
There are no regressions in existing ATF ptrace(2) tests.

Sponsored by <The NetBSD Foundation>
2018-05-16 00:42:15 +00:00
christos
9f866c5113 correct the function name. 2018-05-13 14:45:23 +00:00
roy
0cac5dca10 Increase the default size of some receive buffers from 8k to 16k.
This mitigates recent reports of socket overflow errors
and fixes PR bin/53247.
2018-05-11 09:43:59 +00:00
kre
ebee088dbd Cause a process's user and system times to become non-decreasing.
This alters the invented values (ie: statistically calculated)
that are returned - for small values, the values are likely going to
be different than they were, but that's largely nonsense anyway
(except that the sum of utime & stime does equal cpu time consumed
by the process).   Once the values get large enough to be meaningful
the difference made by this change will be in the noise, and irrelevant.

This needs a couple of additions to struct proc, so we are now into 8.99.17
2018-05-09 19:55:35 +00:00
christos
4656c477fd get the maxrss from the vmspace field, and handle platforms that don't
have pmap statistics here.
2018-05-08 19:34:54 +00:00
christos
e0983e96df Load the struct rusage text, data, and stack fields from the vmspace struct.
Before they were all 0. We update them when we call getrusage() or on
process exit() so that the children rusage is accounted for.
2018-05-07 21:03:45 +00:00
maxv
45e9b67bb8 Copy some KASSERTs from m_move_pkthdr into m_copy_pkthdr, and reorder the
latter to reduce the diff with the former.
2018-05-07 09:57:37 +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