Commit Graph

9870 Commits

Author SHA1 Message Date
christos
7869295617 use the same string for the log and uprintf. 2017-08-06 09:14:14 +00:00
mrg
65d1d4aa12 normalise a BIOHIST log message 2017-08-04 07:00:17 +00:00
riastradh
56272c962e Don't walk off the end of the dirent buffer.
From Ilja Van Sprundel.
2017-07-28 15:37:23 +00:00
riastradh
cf5a000fe5 Clamp the length we use, not the length we don't.
Avoids uninitialized memory disclosure to userland.

From Ilja Van Sprundel.
2017-07-28 15:16:39 +00:00
martin
f08cc415b0 Avoid integer overflow in kern_malloc(). Reported by Ilja Van Sprundel.
XXX Time to kill malloc() completely!
2017-07-28 12:28:48 +00:00
skrll
111cbb5944 Add a condition variable (ex_flwanted) to struct extent so that ex_flags
becomes an invariant.

Remove strange locking for ex_flags as a result.
2017-07-24 19:56:07 +00:00
maxv
d245e6f22a Should be loadfactor(). 2017-07-14 13:23:48 +00:00
maxv
bcdfaccefa Revert rev1.26. l_estcpu is increased by only one cpu, not all of them. 2017-07-14 13:02:20 +00:00
hannken
31624a0218 Regen. 2017-07-12 09:31:59 +00:00
hannken
d29c150b3b As VOP_ADVLOCK() may block indefinitely we cannot take fstrans here.
Fixes PR kern/52364: System hangs not much before showing the login prompt
2017-07-12 09:31:07 +00:00
dholland
9a94872476 Fix vnode leak on error, introduced by the openat family changes in -r1.200.
From mjg@freebsd.
2017-07-09 22:48:44 +00:00
maxv
5dc461da23 explain a bit 2017-07-08 15:15:43 +00:00
christos
c85be1e9c7 move the timestamp stuff to uipc_socket.c because it already has the compat
includes.
2017-07-06 17:42:39 +00:00
christos
2b50acc97b Merge the two copies SO_TIMESTAMP/SO_OTIMESTAMP processing to a single
function, and add a SOOPT_TIMESTAMP define reducing compat pollution from
5 places to 1.
2017-07-06 17:08:57 +00:00
christos
c3a5f17a00 don't print diagnostic for AF_LINK 2017-07-05 17:54:46 +00:00
riastradh
0a89dacf06 Add cv_timedwaitbt, cv_timedwaitbt_sig.
Takes struct bintime maximum delay, and decrements it in place so
that you can use it in a loop in case of spurious wakeup.

Discussed on tech-kern a couple years ago:

https://mail-index.netbsd.org/tech-kern/2015/03/23/msg018557.html

Added a parameter for expressing desired precision -- not currently
interpreted, but intended for a future tickless kernel with a choice
of high-resolution timers.
2017-07-03 02:12:47 +00:00
riastradh
a18efaac6b Nix trailing whitespace. No functional change. 2017-07-03 00:53:33 +00:00
joerg
5f391f4ae2 Export the guard size of the main thread via vm.guard_size. Add a
complementary writable sysctl for the initial guard size of threads
created via pthread_create. Let the existing attribut accessors do the
right thing. Raise the default guard size for threads to 64KB.
2017-07-02 16:41:32 +00:00
christos
6d52cc85b8 don't warn about AF_LINK sockets with sa_len less than the size of the sockaddr 2017-07-02 02:39:18 +00:00
christos
c4aed00fad fix file descriptor locking (from joerg).
fixes kernel crashes by running go
XXX: pullup-7
2017-07-01 20:08:56 +00:00
christos
7700e78cab put the code that returns the sizeof the socket by family in one place. 2017-07-01 16:59:12 +00:00
snj
4e609ee710 fix typo 2017-06-25 04:10:47 +00:00
joerg
b77121f193 Recommit exec_subr.c revision 1.79:
Always include a 1MB guard area beyond the end of stack. While ASLR will
  normally create a guard area as well, this provides a deterministic area
  for all binaries.

  Mitigates the rest of CVE-2017-1000374 and CVE-2017-1000375 from
  Qualys.

Additionally, change VM_DEFAULT_ADDRESS_TOPDOWN to include
user_stack_guard_size in the size reservation.
2017-06-23 21:28:38 +00:00
skrll
34397172e3 Unwrap two lines. NFC. 2017-06-22 09:05:09 +00:00
martin
8ee7e18703 Change a KASSERT to KASSERTMSG and print the xcall function to be
invoked as a debugging help.
2017-06-21 07:39:04 +00:00
christos
f4961bd8ed Change len type to be unsigned int for consistency with the input type.
Don't check for negative; it does not matter we clamp anyway. This
broke the compat32 getsockname() where an unitialized socklen_t ended
up randomly negative causing it to fail.
2017-06-20 20:34:49 +00:00
joerg
2e851f5508 Revert for the moment, creates problems on i386. 2017-06-19 19:02:16 +00:00
joerg
5bcc4a51d6 Always include a 1MB guard area beyond the end of stack. While ASLR will
normally create a guard area as well, this provides a deterministic area
for all binaries.

Mitigates the rest of CVE-2017-1000374 and CVE-2017-1000375 from
Qualys.
2017-06-19 15:53:16 +00:00
hannken
a94bf97d25 Make the fast path of fstrans_get_lwp_info() "static inline". 2017-06-18 14:00:17 +00:00
hannken
90e2dee24a Clear fstrans entries whose mount is gone from the last fstrans_done() only. 2017-06-18 13:59:45 +00:00
chs
2b3f157429 create an nmap table for module symtabs too.
needed by dtrace.
2017-06-14 00:52:37 +00:00
riastradh
26bd73f202 Add heading comment for private localcount_adjust subroutine. 2017-06-12 21:08:34 +00:00
riastradh
44df486bb8 Move forward declaration to top of file.
Keep header comment above localcount_init adjoined to it.

No functional change.
2017-06-12 21:07:14 +00:00
chs
20bf3061d4 define a copy of getnanotime() named dtrace_getnanotime() so that
dtrace can know from the name that it should not allow setting
fbt probes on it.  needed by dtrace.
2017-06-09 01:16:33 +00:00
chs
3756187172 add some pool_allocators for pool item sizes larger than PAGE_SIZE.
needed by dtrace.
2017-06-08 04:00:01 +00:00
chs
ec5ea71a90 move some buffer cache internals declarations from buf.h to vfs_bio.c.
this is needed to avoid name conflicts with ZFS and also
makes it clearer that other code shouldn't be messing with these.
remove the LFS debug code that poked around in bufqueues and
remove the BQ_EMPTY bufqueue since nothing uses it anymore.
provide a function to let LFS and wapbl read the value of nbuf for now.
2017-06-08 01:23:01 +00:00
chs
67c81802f1 allow cv_signal() immediately followed by cv_destroy().
this sequence is used by ZFS in a couple places and by supporting it
natively we can undo our local ZFS changes that avoided it.
note that this is only legal when all of the waiters use cv_wait()
and not any of the other variations, and lockdebug will catch
any violations of this rule.
2017-06-08 01:09:52 +00:00
hannken
287643b0da Operations fstrans_start() and fstrans_start_nowait() now always
use FSTRANS_SHARED as lock type so remove the lock type argument.

File system state FSTRANS_SUSPENDING is now unused so remove it.

Regen vnode_if files.

Ride 8.99.1 less than a hour ago.
2017-06-04 08:05:41 +00:00
hannken
775d23a76b Operations fstrans_start() and fstrans_start_nowait() now always
use FSTRANS_SHARED as lock type so remove the lock type argument.
2017-06-04 08:03:26 +00:00
hannken
f5647f853e Locking a layer vnode using the regular bypass routine is no longer
racy.  Undo the change from 2017-03-30 11:16:52, commitid eurqbzuGxGRlryLz
and make vi_lock a krwlock_t again.
2017-06-04 08:02:26 +00:00
hannken
48c67e7912 Regen. 2017-06-04 08:00:27 +00:00
hannken
dfcc54aa9c Add "FSTRANS=LOCK" and "FSTRANS=UNLOCK" to vop_lock and vop_unlock.
Add two "static inline" functions to vnode_if.c to handle MPSAFE
and FSTRANS before and after the "VCALL()".

Take FSTRANS and handle error before "VCALL(...vop_lock...)" and
release it after "VCALL(...vop_unlock...)".
2017-06-04 07:59:17 +00:00
hannken
8e1cefd98c A vnode is usually called "active", if it has an associated file system
node and a usecount greater zero.  Therefore rename state "VS_ACTIVE"
to "VS_LOADED" and add a new synthetic state "VS_ACTIVE" for VSTATE_ASSERT()
to assert an active vnode.

Add VSTATE_ASSERT_UNLOCKED() to be used with v_interlock unheld and
move the state assertion macros to sys/vnode_impl.h.
2017-06-04 07:58:29 +00:00
chs
ffb3d80455 localcount_init() can't fail because percpu_alloc() can't fail.
remove the check and change the return type to void.
2017-06-02 00:32:12 +00:00
chs
fd34ea77eb remove checks for failure after memory allocation calls that cannot fail:
kmem_alloc() with KM_SLEEP
  kmem_zalloc() with KM_SLEEP
  percpu_alloc()
  pserialize_create()
  psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.
2017-06-01 02:45:05 +00:00
chs
1f0e167178 vmem_alloc() with VM_SLEEP cannot fail, so percpu_alloc() cannot fail either. 2017-05-31 23:54:17 +00:00
chs
c85613c074 assert that vmem_alloc() with VM_SLEEP does not fail. 2017-05-31 23:53:30 +00:00
hannken
e4e82d96c7 Restrict vgone() to suspended file systems only.
Welcome to 7.99.75, old file system modules would cause a diagnostic
assertion with new kernel.
2017-05-28 16:39:41 +00:00
hannken
a8045334ce Add a helper to propagate file system suspension for vrevoke().
Take care to retry suspension on interrupt as vrevoke must succeed.
2017-05-28 16:35:47 +00:00
bouyer
6e4cb2b9ab merge the bouyer-socketcan branch to HEAD.
CAN stands for Controller Area Network, a broadcast network used
in automation and automotive fields. For example, the NMEA2000 standard
developped for marine devices uses a CAN network as the link layer.

This is an implementation of the linux socketcan API:
https://www.kernel.org/doc/Documentation/networking/can.txt
you can also see can(4).

This adds a new socket family (AF_CAN) and protocol (PF_CAN),
as well as the canconfig(8) utility, used to set timing parameter of
CAN hardware. Also inclued is a driver for the CAN controller
found in the allwinner A20 SoC (I tested it with an Olimex lime2 board,
connected with PIC18-based CAN devices).

There is also the canloop(4) pseudo-device, which allows to use
the socketcan API without CAN hardware.

At this time the CANFD part of the linux socketcan API is not implemented.
Error frames are not implemented either. But I could get the cansend and
canreceive utilities from the canutils package to build and run with minimal
changes. tcpudmp(8) can also be used to record frames, which can be
decoded with etherreal.
2017-05-27 21:02:54 +00:00
riastradh
c921bd9b79 Check VOP_INACTIVE contract with a judicious assert. 2017-05-26 14:40:09 +00:00
riastradh
51e152b5ce Clarify comment. 2017-05-26 14:39:20 +00:00
riastradh
93562e3f53 Eliminate crusty debugging sludge.
We have a mostly sane vnode lifecycle now.  If this needs debugging,
it should be done once at the call site of VOP_RECLAIM.
2017-05-26 14:34:19 +00:00
riastradh
f4ad397b3e regen 2017-05-26 14:21:54 +00:00
riastradh
7f7aad09bd Make VOP_RECLAIM do the last unlock of the vnode.
VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.
2017-05-26 14:20:59 +00:00
christos
9aa2075330 switch to a switch 2017-05-25 20:42:36 +00:00
pgoyette
3b2df19edf When logging a history record for biowait(), include the return address
as a parameter, to identify to which of the many calls to biowait() the
record refers.
2017-05-25 02:28:07 +00:00
hannken
69174779b1 With dounmount() working on a suspended file system remove no longer
needed fields mnt_busynest and mnt_unmounting from struct mount.

Welcome to 7.99.73
2017-05-24 09:53:55 +00:00
hannken
c2c49e1ed2 Remove the syncer dance from dounmount(). The syncer skips
unmounting file systems as they are suspended.

Remove now unused syncer_mutex.
2017-05-24 09:52:59 +00:00
pgoyette
cb99404632 Fix a comment - in localcount_fini(), we don't care whether it was the
caller or some other code that drained the localcount;  all we care is
that it has been drained.
2017-05-19 02:20:24 +00:00
pgoyette
a372bceac2 Introduce new localcount(9) reference-count primitives. 2017-05-19 00:01:33 +00:00
hannken
9fc3ca45b3 Suspend file system while revoking a vnode. This way no operations run
on the mounted file system during revoke and all operations see
the state before or after the revoke.
2017-05-17 12:46:14 +00:00
hannken
677cf1d8b4 Suspend file system while unmounting. This way no operations run
on the mounted file system during unmount and all operations see
the state before or after the (possibly failed) unmount.
2017-05-17 12:45:03 +00:00
christos
f6b964d39b protect against NULL, from PaulG 2017-05-11 23:50:17 +00:00
nat
5e34165f16 Explicitly set the flags instead of masking set values in.
This fixes FNONBLOCK weirdness seen in audio.c

OK christos@ and martin@.
2017-05-11 22:38:56 +00:00
riastradh
9c32900485 regen 2017-05-10 06:19:47 +00:00
riastradh
913618cd04 Forward-declare struct lwp' so we can use struct lwp *' here. 2017-05-10 06:08:56 +00:00
christos
21e6c9452c fp == NULL in the DIAGNOSTIC, so use the real fp and also print the errno. 2017-05-09 21:18:51 +00:00
christos
1e7fb326f1 de-triplicate. 2017-05-07 22:54:54 +00:00
hannken
4f4cfe27b2 Enter fstrans from _vfs_busy() and leave from vfs_unbusy().
Adapt sched_sync() and do_sys_sync().
2017-05-07 08:26:58 +00:00
hannken
01d31ceb6d Return ENOENT if trying to suspend an unmounted file system. 2017-05-07 08:25:54 +00:00
hannken
c18a56f135 Move fstrans initialization to vfs_mountalloc(). 2017-05-07 08:24:20 +00:00
hannken
12ad3b05fd Handle the case where the mount is gone and its mnt_transinfo is NULL. 2017-05-07 08:23:28 +00:00
hannken
853d034c97 Remove now invalid comment. 2017-05-07 08:21:08 +00:00
joerg
4f77b889d0 Extend the mmap(2) interface to allow requesting protections for later
use with mprotect(2), but without enabling them immediately.

Extend the mremap(2) interface to allow duplicating mappings, i.e.
create a second range of virtual addresses references the same physical
pages. Duplicated mappings can have different effective protections.

Adjust PAX mprotect logic to disallow effective protections of W&X, but
allow one mapping W and another X protections. This obsoletes using
temporary files for purposes like JIT.

Adjust PAX logic for mmap(2) and mprotect(2) to fail if W&X is requested
and not silently drop the X protection.

Improve test cases to ensure correct operation of the changed
interfaces.
2017-05-06 21:34:51 +00:00
kamil
1627fdf3a4 Set clear comment about EI_OSABI and EI_ABIVERSION
/*
 * NetBSD sets generic SYSV OSABI and ABI version 0
 * Native ELF files are distinguishable with NetBSD specific notes
 */

No functional change.
2017-05-04 11:12:23 +00:00
kamil
ec80600208 Use consistently "bufq_private(bufq)" instead of "bufq->bq_private"
No functional change.
2017-05-04 11:03:27 +00:00
kamil
df97a42593 Correct typo in the comment
No functional change.
2017-05-04 11:01:16 +00:00
kamil
88e477a387 Fix kernel panic triggered with LLDB
PT_SETSTEP and PT_CLEARSTEP in the current design must unlock proc_lock and
t->p_lock. These functions use lwp_delref() for a tracee with more than one
LWP. This function internally lock (t->)p_lock and this is lock against
self.

There are coming new ATF test with PT_*STEP with multiple LWPs to catch
these bugs in future changes.

Sponsored by <The NetBSD Foundation>
2017-05-03 15:53:31 +00:00
pgoyette
48e395b1b8 Introduce mutex_ownable() to determine if it is possible for the current
process to acquire a mutex.
2017-05-01 21:35:25 +00:00
ryo
d9ee24f798 whitespace police 2017-05-01 10:00:43 +00:00
abhinav
39132b9e2d Rearrange the if conditions in order to get rid of unnecessary indentation.
No functional change intended. ok christos@
2017-04-27 16:52:22 +00:00
riastradh
8e5c8dbff1 regen 2017-04-26 03:04:24 +00:00
riastradh
6fa7b15833 Change VOP_REMOVE and VOP_RMDIR to preserve lock/ref on dvp.
No change to vp -- the plan is to replace the node by the
componentname in the vop parameters, and let all directory vops do
lookups internally.

Proposed on tech-kern with no objections:
https://mail-index.netbsd.org/tech-kern/2017/04/17/msg021825.html
2017-04-26 03:02:47 +00:00
pgoyette
ca22f64915 Add a check to ensure that a new sysctl node was attached in the tree
at the place we expected it to be attached!

As mentioned several times (on tech-kern@ mailing list) over the past
18 months or so, I've seen a few instances where this will trigger,
although I've been unable to reproduce them.  Hopefully some wider
exposure will reveal the under-lying cause of this rare phenomenon.

Commit was proposed on tech-kern list, and no objections raised.
2017-04-25 22:07:10 +00:00
pgoyette
ab5e69493e Use __func__ for routine name in printf() calls. NFC intended. 2017-04-25 08:46:38 +00:00
kamil
795febebbd Try to fix build of sys_lwp.c
lwp_create() has been acquired more arguments, there was missing the latest
one. Per analogiam with changes in the same commit to other source files,
go for &SS_INIT.
2017-04-21 19:38:35 +00:00
christos
d7746f2ee3 - Propagate the signal mask from the ucontext_t to the newly created thread
as specified by _lwp_create(2)
- Reset the signal stack for threads created with _lwp_create(2)
2017-04-21 15:10:34 +00:00
kamil
34e270cb64 Enhance verbosity of debug message for ELF magic mismatch
Print e_ident[EI_MAG3] (it was missed)
Print e_ident[EI_CLASS] as it is used do determine correct ELF magic.

No functional change for non-debug (without option DEBUG_ELF) build.
2017-04-21 13:17:42 +00:00
christos
5d75b0065e simplify. 2017-04-19 15:54:45 +00:00
pgoyette
05aa8c5f12 Be consistent about checking for text section address being 0, and
don't ignore errors by falling through to the next section(s).

As discussed on tech-kern@
2017-04-19 06:19:02 +00:00
christos
6ef342f61a PR/52174: Remove root test, it is too verbose. XXX: need to come up with
something better.
2017-04-18 18:07:29 +00:00
hannken
bd152b56b5 Add vfs_trybusy() and mountlist_iterator_trynext() and use it for the syncer. 2017-04-17 08:34:27 +00:00
hannken
eb8533a8b6 No need to keep a not yet visible mount busy. Move vfs_busy()
from vfs_mountalloc() to vfs_rootmountalloc().

XXX: Do we really need to vfs_busy() for vfs_mountroot?
2017-04-17 08:32:55 +00:00
hannken
20bb034f5b Remove unused argument "nextp" from vfs_busy() and vfs_unbusy().
Remove argument "keepref" from vfs_unbusy() and add vfs_ref() where needed.
2017-04-17 08:32:00 +00:00
hannken
ebb8f73b4b Add vfs_ref(mp) and vfs_rele(mp) to add or remove a reference to
struct mount.  Rename vfs_destroy(mp) to vfs_rele(mp) and replace
incrementing mp->mnt_refcnt with vfs_ref(mp).
2017-04-17 08:31:01 +00:00
hannken
256581e1f9 Cleanup after mountlist iterator:
- remove now unused field mnt_list.
- rename mount_list to mountlist and make it local to vfs_mount.c.
- make mountlist_lock local to vfs_mount.c.

Change pstat.c to retrieve vnodes by lru lists.
2017-04-17 08:29:58 +00:00
riastradh
629022bd8f regen to confirm no functional change 2017-04-16 17:18:54 +00:00
riastradh
f2ed57297a Count vnode arguments correctly.
Don't count arguments that have WILLRELE/WILLPUT; count arguments
that are struct vnode *.

No functional change currently because it happens that every released
or put vnode argument comes first or after other ones.
2017-04-16 17:18:28 +00:00
riastradh
d08e9ec7c8 regen 2017-04-16 16:49:25 +00:00