Commit Graph

132 Commits

Author SHA1 Message Date
ad 6d70f903e6 Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
  be sent from a hardware interrupt handler. Signal activity must be
  deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
  and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.
2008-04-24 15:35:27 +00:00
yamt 3426b80b5e - l_wmesg is not always valid. check l_wchan when using l_wmesg.
should fix a crash reported by Juan RP on current-users@.
- ttyinfo: lock lwp when accessing l_wmesg.
- fill_lwp: add an assertion.
2008-04-05 14:03:16 +00:00
cegger 224670ae98 use device_xname() where appropriate
OK martin
2008-04-04 20:13:18 +00:00
xtraeme 247cd610f6 Revert rev 1.126-1.128. The original code was correct and rmind and I
didn't look correctly at them.
2008-04-02 10:53:23 +00:00
xtraeme dcf3ee7d3b When copying l_name and l_wmesg use KI_LNAMELEN and KI_WMESGLEN
respectively, so that we don't care if l_name/wmesg is longer
than kl_name/wmesg and the KASSERTs added in previous can go away.
2008-04-01 21:05:37 +00:00
xtraeme 3189c49560 Fix previous: use the length of l->l_foo not kl->l_foo and add
two KASSERTs to check for max lenght limits before copying.

As suggested by rmind@.
2008-04-01 18:06:06 +00:00
xtraeme 03c6a6aa65 fill_lwp: when copying l_wmesg and l_name, use the size of the string
not of the variable.

Found and ok by rmind@.
2008-04-01 17:39:58 +00:00
ad be04ac4896 Make rusage collection per-LWP and collate in the appropriate places.
cloned threads need a little bit more work but the locking needs to
be fixed first.
2008-03-27 19:06:51 +00:00
ad a9ca7a3734 Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.
2008-03-21 21:54:58 +00:00
matt 6d6aefbf45 Convert to ansi definitions from old-style definitons. 2008-02-27 19:57:18 +00:00
ad ec93662039 Another locking botch. 2008-01-30 00:43:47 +00:00
ad eb97d34997 More file/proc locking fixes. 2008-01-28 20:05:21 +00:00
elad c27d5f30b6 Tons of process scope changes.
- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
    requests, and add specific requests for set/get scheduler policy and
    set/get scheduler parameters.

  - Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
    requests.

  - Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

  - Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
    process information is being looked at (entry itself, args, env,
    open files).

  - Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

  - Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

  - Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

  - Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.
2008-01-23 15:04:38 +00:00
ad 2e85c8c3b2 sysctl_kern_proc_args: avoid zero length allocation. 2008-01-12 19:25:25 +00:00
ad 77e0b2120f Patch up sysctl locking:
- Lock processes, credentials, filehead etc correctly.
- Acquire a read hold on sysctl_treelock if only doing a query.
- Don't wire down the output buffer. It doesn't work correctly and the code
  regularly does long term sleeps with it held - it's not worth it.
- Don't hold locks other than sysctl_lock while doing copyout().
- Drop sysctl_lock while doing copyout / allocating memory in a few places.
- Don't take kernel_lock for sysctl.
- Fix a number of bugs spotted along the way
2008-01-07 16:12:52 +00:00
ad 2ecdf58c2c Remove systrace. Ok core@. 2007-12-31 15:31:24 +00:00
christos 65c680cad7 Add PaX ASLR (Address Space Layout Randomization) [from elad and myself]
For regular (non PIE) executables randomization is enabled for:
    1. The data segment
    2. The stack

For PIE executables(*) randomization is enabled for:
    1. The program itself
    2. All shared libraries
    3. The data segment
    4. The stack

(*) To generate a PIE executable:
    - compile everything with -fPIC
    - link with -shared-libgcc -Wl,-pie

This feature is experimental, and might change. To use selectively add
    options PAX_ASLR=0
in your kernel.

Currently we are using 12 bits for the stack, program, and data segment and
16 or 24 bits for mmap, depending on __LP64__.
2007-12-26 22:11:47 +00:00
yamt 949e16d902 use binuptime for l_stime/l_rtime. 2007-12-22 01:14:53 +00:00
elad 9725bcfd97 - Use KAUTH_ARG() instead of casts,
- Don't ignore return value of settime() in sysctl_kern_rtc_offset(), as
  suggested by yamt@.

Note: the kauth(9) call in sysctl_kern_rtc_offset() is bogus, but this will
be addressed separately.
2007-12-10 18:58:02 +00:00
ad d831186d55 Merge scheduler changes from the vmlocking branch. All discussed on
tech-kern:

- Invert priority space so that zero is the lowest priority. Rearrange
  number and type of priority levels into bands. Add new bands like
  'kernel real time'.
- Ignore the priority level passed to tsleep. Compute priority for
  sleep dynamically.
- For SCHED_4BSD, make priority adjustment per-LWP, not per-process.
2007-11-06 00:42:39 +00:00
ad a2a3828545 machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h 2007-10-19 11:59:34 +00:00
christos a9a5cf56c3 Don't fail to produce the argument vector if the program has modified it
by deleting arguments. This is a popular practice, and failing means that
ps(1) prints (programname). For example this is what XtOpenDisplay() with
-geometry. This used to work before 2.0H, and the behavior is allowed and
hinted by POSIX. Found out by Anon Ymous.
2007-10-16 16:10:59 +00:00
christos e221af6ac2 - fix comment sentence capitalization.
- whitespace cleanup.
No functional changes.
2007-10-16 16:05:50 +00:00
ad 9c3109d6c5 Add _SC_NPROCESSORS_ONLN and _SC_NPROCESSORS_CONF for sysconf(). These
are extensions but are provided by many Unix systems.
2007-10-15 14:12:54 +00:00
rmind aa9301c8f4 sysctl_kern_lwp: Use a correct variable when rechecking if LWP still
exists after relocking.  Found via CID: 4689.  OK by <dsl>.
2007-10-13 10:04:08 +00:00
ad 16598eeedf Merge from vmlocking: don't hold scheduler locks across copyout(). 2007-10-08 18:09:37 +00:00
joerg 9e4ace25c5 Add kern.no_sa_support to easily detect whether a kernel supports
Scheduler Activation or not. This is a negative name as ld.so.conf
conditionals threat undefined sysctls like 0.
2007-09-28 21:25:21 +00:00
ad 63c4506184 Changes to make ktrace LKM friendly and reduce ifdef KTRACE. Proposed
on tech-kern.
2007-08-15 12:07:23 +00:00
yamt 261e7c1e79 remove a homegrown definition of CPU_INFO_FOREACH. 2007-08-06 11:51:46 +00:00
ad 88ab7da936 Merge some of the less invasive changes from the vmlocking branch:
- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
2007-07-09 20:51:58 +00:00
dsl 04c196a642 Add a flags parameter to kauth_cred_get/setgroups() so that sys_set/setgroups
can copy directly to/from userspace.
Avoids exposing the implementation of the group list as an array to code
outside kern_auth.c.
compat code and man page need updating.
2007-06-30 13:32:14 +00:00
yamt f03010953f merge yamt-idlelwp branch. asked by core@. some ports still needs work.
from doc/BRANCHES:

	idle lwp, and some changes depending on it.

	1. separate context switching and thread scheduling.
	   (cf. gmcgarry_ctxsw)
	2. implement idle lwp.
	3. clean up related MD/MI interfaces.
	4. make scheduler(s) modular.
2007-05-17 14:51:11 +00:00
dsl e6918d8f47 Remove proc->p_ru and the 'rusage' pool.
I think it existed to cache the numbers in kernel memory of a zombie when
proc->p_stats was part of the 'u' area - so got freed earlier and wouldn't
(easily) be accessible from a separate process.  However since both the
p_ru and p_stats fields are freed at the same time it is no longer needed.
Ride the recent 4.99.19 version change.
2007-04-30 20:11:41 +00:00
ad f96f2e2a7f Add the LWP's runtime to kinfo_lwp. 2007-03-11 21:38:38 +00:00
ad c147748d84 - Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.
2007-03-09 14:11:22 +00:00
pavel 934634a18c Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.
2007-02-17 22:31:36 +00:00
ad 087fdb9080 Count the number of CPUs at boot and stash in 'ncpu'. Eventually should
have each CPU register at attach, so we can figure out the topology for
the scheduler.
2007-02-15 20:32:47 +00:00
ad b07ec3fc38 Merge newlock2 to head. 2007-02-09 21:55:00 +00:00
elad 317687e988 Don't rely on KAUTH_PROCESS_CANSEE for environment just yet,
otherwise we're allowing anyone to read the environment unless
curtain is enabled.

From yamt@.
2007-01-22 15:11:52 +00:00
elad e0d8be4efc Move Veriexec's sysctl(9) setup routine and helper to kern_verifiedexec.c. 2006-11-27 17:45:36 +00:00
christos df031f1edc PR/34837: Mindaguas: Add SysV SHM dynamic reallocation and locking to the
physical memory
2006-11-25 21:40:04 +00:00
christos 3f78162b5c implement kern.arandom properly, instead of lying about it and only filling
the first 4 bytes of the array with random data.
2006-11-01 22:27:43 +00:00
christos ce42f55037 add the emulation in kinfo_proc2 2006-10-29 22:34:07 +00:00
elad 5cb38e5a6c Back out previous (p_flag2).
In 30 minutes from now Jason Thorpe will come up with an implementation
of a proplib dictionary in struct proc, so adding an int doesn't really
make any sense.
2006-10-03 16:07:12 +00:00
elad f346fbdce9 Until we figure out the Perfect Way of adding flags to processes, add
a p_flag2. No objections on tech-kern@.

Input from simonb@, thanks!
2006-10-03 11:23:32 +00:00
dogcow 78b90930eb correct dcopyout #define for !KTRACE case. 2006-09-24 05:46:14 +00:00
manu 8a1037a46b Add a -t+S flag to ktrace for tracing activity related to sysctl. MIB
names will be displayed, with data readen and written as well.
2006-09-23 22:01:04 +00:00
elad bada0c776a Don't use KAUTH_RESULT_* where it's not applicable.
Prompted by yamt@.
2006-09-13 10:07:42 +00:00
manu bdfbd98ac1 When getting the program argument or environement string, we previously
assumed that all the strings were stored in a row, separated by NUL chars,
 at the address pointed bu argv[0] (or envp[0]).

This was wrong: if the program changed argvs[0], we still read the
first string correctly, but the next strings did contain unexpected data.

The fix: read the whole argv (or envp) array, then copy the string one by
one, using their addresses in argv (or agrp)
2006-09-10 05:46:02 +00:00
elad 5f7169ccb1 First take at security model abstraction.
- Add a few scopes to the kernel: system, network, and machdep.

- Add a few more actions/sub-actions (requests), and start using them as
  opposed to the KAUTH_GENERIC_ISSUSER place-holders.

- Introduce a basic set of listeners that implement our "traditional"
  security model, called "bsd44". This is the default (and only) model we
  have at the moment.

- Update all relevant documentation.

- Add some code and docs to help folks who want to actually use this stuff:

  * There's a sample overlay model, sitting on-top of "bsd44", for
    fast experimenting with tweaking just a subset of an existing model.

    This is pretty cool because it's *really* straightforward to do stuff
    you had to use ugly hacks for until now...

  * And of course, documentation describing how to do the above for quick
    reference, including code samples.

All of these changes were tested for regressions using a Python-based
testsuite that will be (I hope) available soon via pkgsrc. Information
about the tests, and how to write new ones, can be found on:

	http://kauth.linbsd.org/kauthwiki

NOTE FOR DEVELOPERS: *PLEASE* don't add any code that does any of the
following:

  - Uses a KAUTH_GENERIC_ISSUSER kauth(9) request,
  - Checks 'securelevel' directly,
  - Checks a uid/gid directly.

(or if you feel you have to, contact me first)

This is still work in progress; It's far from being done, but now it'll
be a lot easier.

Relevant mailing list threads:

http://mail-index.netbsd.org/tech-security/2006/01/25/0011.html
http://mail-index.netbsd.org/tech-security/2006/03/24/0001.html
http://mail-index.netbsd.org/tech-security/2006/04/18/0000.html
http://mail-index.netbsd.org/tech-security/2006/05/15/0000.html
http://mail-index.netbsd.org/tech-security/2006/08/01/0000.html
http://mail-index.netbsd.org/tech-security/2006/08/25/0000.html

Many thanks to YAMAMOTO Takashi, Matt Thomas, and Christos Zoulas for help
stablizing kauth(9).

Full credit for the regression tests, making sure these changes didn't break
anything, goes to Matt Fleming and Jaime Fournier.

Happy birthday Randi! :)
2006-09-08 20:58:56 +00:00