Commit Graph

441 Commits

Author SHA1 Message Date
christos
4705defbf3 es_arglen is already in bytes... 2017-01-25 17:57:14 +00:00
kamil
e6f79d077f Cleanup dead code after revert of racy vfork(2) commit
This removes dead code introduced with the following commit:

date: 2012-07-27 22:52:49 +0200;  author: christos;  state: Exp;  lines: +8 -2;
revert racy vfork() parent-blocking-before-child-execs-or-exits code.
ok rmind
2017-01-09 00:31:30 +00:00
kamil
239e90be56 Introduce new SIGTRAP code: TRAP_EXEC
On exec() events under a debugger generate the SIGTRAP signal with
TRAP_EXEC property. This allows tracer to distinguish exec() events easily.

Sponsored by <The NetBSD Foundation>
2017-01-06 22:42:58 +00:00
kamil
f26cf4cb48 Prefer modern simple past tense and past participle of catch
The "catched" form is obsolete and nonstandard, prefer "caught".
2016-11-03 22:08:30 +00:00
christos
4fddba2c93 m68k binaries load @ pagesize. unbreak. 2016-09-15 17:44:16 +00:00
maxv
e727235220 The way the kernel tries to prevent a userland process from allocating page
zero is hugely flawed. It is easy to demonstrate that one can trick UVM
into chosing a NULL hint after the user_va0_disable check from uvm_map.
Such a bypass allows kernel NULL pointer dereferences to be exploitable on
architectures with a shared userland<->kernel VA, like amd64.

Fix this by increasing the limit of the vm space made available for
userland processes. This way, UVM will never chose a NULL hint, since it
would be outside of the vm space.

The user_va0_disable sysctl still controls this feature.
2016-08-06 15:13:13 +00:00
msaitoh
8bc54e5be6 KNF. Remove extra spaces. No functional change. 2016-07-07 06:55:38 +00:00
christos
f4c1c0d146 put back commented out name resolution code that was gc'ed after previous
refactoring.
2016-06-20 19:14:35 +00:00
christos
b035b9b913 fix variable name 2016-06-09 00:17:45 +00:00
christos
3aa7fc217c ignore EACCES 2016-06-08 23:55:24 +00:00
christos
5763e378f2 Give 0,1,2 for security.pax.mprotect.ptrace and make it default to 1
as documented in sysctl(7):
0 - ptrace does not affect mprotect
1 - (default) mprotect is disabled for processes that start executing from
    the debugger (being traced)
2 - mprotect restrictions are relaxed for traced processes
2016-05-25 20:07:54 +00:00
christos
b039ee7763 reduce #ifdef mess caused by PaX 2016-05-22 14:26:09 +00:00
ozaki-r
472a3b6444 Fix builds of ALL kernels that define DEBUG_EXEC 2016-05-11 02:18:27 +00:00
christos
f50af3d36b Enable DEBUG_EXEC, if we have DEBUG (since it only fires on errors) and
disable the super verbose printing by protecting it against TRACE_EXEC.
2016-05-08 20:00:21 +00:00
christos
6b2e8a5337 Move all the randomization inside kern_pax.c so we can control it directly.
Add debugging flags to be able to set the random number externally.
2016-05-08 01:28:09 +00:00
christos
5c35dbcd66 no need to pass the coredump flag to exit1() since it is set and known
in one place.
2016-04-04 23:07:06 +00:00
christos
4fbdf206cb Split p_xstat (composite wait(2) status code, or signal number depending
on context) into:
1. p_xexit:		exit code
2. p_xsig:		signal number
3. p_sflag & WCOREFLAG	bit to indicated that the process core-dumped.

Fix the documentation of the flag bits in <sys/proc.h>
2016-04-04 20:47:57 +00:00
khorben
88481e0aaa Let PaX ASLR know about the current emulation
This effectively fixes PaX ASLR with 32-bits emulation on 64-bits
platforms. Without this knowledge, the offset applied for 32-bits
programs was really meant for a 64-bits address space - thus
shifting the address up to 12 bits, with a success rate of about
1/4096. This offset is calculated once in the lifetime of the
process, which therefore behaved normally when able to start.

Fixes kern/50469, probably also kern/50986

Tested on NetBSD/amd64 (emul_netbsd32)
2016-03-20 14:58:10 +00:00
pgoyette
0513b92c02 Make the list of syscalls which can trigger a module autoload an
attribute of each emulation, rather than having a single global
list which applies only to the default emulation.

This changes 'struct emul' so

        Welcome to 7.99.23 !
2015-11-30 22:47:19 +00:00
martin
76713fa86f We never exec(2) with a kernel vmspace, so do not test for that, but instead
KASSERT() that we don't.
When calculating the load address for the interpreter (e.g. ld.elf_so),
we need to take into account wether the exec'd process will run with
topdown memory or bottom up. We can not use the current vmspace's flags
to test for that, as this happens too early. Luckily the execpack already
knows what the new state will be later, so instead of testing the current
vmspace, pass the info as additional argument to struct emul
e_vm_default_addr.
Fix all such functions and adopt all callers.
2015-11-26 13:15:34 +00:00
maxv
6d1bcdcc10 Reset the PaX flags, make sure ep_emul_arg is NULL, and add a comment. 2015-10-22 11:48:02 +00:00
pgoyette
90bf221e1f In spawn_return() we temporarily move the process state to SSTOP, but
without updating its p_waited value or its parent's p_nstopchild
counter.  Later, we restore the original state, again without any
adjustment of the related values.  This leaves a relatively short
window when the values are inconsistent and could interfere with the
proper operation of sys_wait() for the parent (if it manages to be
scheduled;  it's not totally clear what, if anything, prevents
scheduling/execution of the parent).

If during this window, any of the checks being made result in an
error, we call exit1() which will eventually migrate the process's
state to SDEAD (with an intermediate transition to SDYING).  At
this point the other variables get updated, and we finally restore
a consistent state.

This change updates the p_waited and parent's p_nstopchild at each
step to eliminate any windows during which the values could lead to
incorrect decisions.

Fixes PR kern/50330

Pullups will be requested for NetBSD-7, -6, -6-0, and -6-1
2015-10-13 00:29:34 +00:00
pgoyette
4937211e28 In execve_runproc(), update the p_waited entry for the process being
moved to SSTOP state, not for its parent.  (It is correct to update
the parent's p_nstopchild count.)  If the value is not already zero,
it could prevent its parent from waiting for the process.

Fixes PR kern/50298

Pullups will be requested for:

       NetBSD-7, -6, -6-0, -6-1, -5, -5-0, -5-1, and -5-2
2015-10-13 00:24:35 +00:00
christos
db70f1818e Change SDT (Statically Defined Tracing) probes to use link sets so that it
is easier to add probes. (From FreeBSD)
2015-10-02 16:54:15 +00:00
maxv
9ed595918a Revamp the way processes are PaX'ed in the kernel. Sent on tech-kern@ two
months ago, but no one reviewed it - probably because it's not a trivial
change.

This change fixes the following bug: when loading a PaX'ed binary, the
kernel updates the PaX flag of the calling process before it makes sure
the new process is actually launched. If the kernel fails to launch the
new process, it does not restore the PaX flag of the calling process,
leaving it in an inconsistent state.

Actually, simply restoring it would be horrible as well, since in the
meantime another thread may have used the flag.

The solution is therefore: modify all the functions used by PaX so that
they take as argument the exec package instead of the lwp, and set the PaX
flag in the process *right before* launching the new process - it cannot
fail in the meantime.
2015-09-26 16:12:24 +00:00
christos
32627ea0ec gcc does not detect initialization correctly on all platforms (hpcsh) 2015-09-12 18:30:46 +00:00
christos
e56eaf6411 - preserve the error number returned from copyin.
- preserve the original pathname in ep_kname, because this is what gets passed
  to userland in exec_script.c
2015-09-12 17:04:57 +00:00
christos
c8bd35c1f3 On non absolute exec pathnames, prepend the working directory if
possible so that we can provide in most situations the absolute
pathname in the AUX vector so that $ORIGIN works. The following
are implementation issues:
    1. deep path execs still don't work (can't provide path to the AUX vector)
    2. the returned path is not normalized (cosmetic)
2015-09-11 01:23:37 +00:00
maxv
cbb6f393d8 Small changes:
- rename pax_aslr_init() to pax_aslr_init_vm()
 - remove the PAX_ flags (unused)
 - fix a comment in pax.h
2015-07-31 07:37:17 +00:00
chs
669ef94683 remove ep_name, change the last reference to use ep_kname instead. 2014-12-14 23:49:28 +00:00
christos
a24ecb0e5b PR/49287: Masao Uebayashi: Handle exec_script argument vector from the 32 ->
64 bit case. When execing a 64 bit shell from a 32 bit binary the argument
vector was still incorrect.

XXX: Pullup 7
2014-12-14 21:35:24 +00:00
maxv
eda7c7bbe4 Do not uselessly include <sys/malloc.h>. 2014-11-09 17:48:07 +00:00
christos
f9128b659c PR/49287: David Holland: Skip the right number of bytes to go over the first
argument in the argv vector. Fixes netbsd32 script execution, where you lost
the first argument because it skipped 8 bytes instead of 4.
2014-10-24 21:13:30 +00:00
maxv
f1911357ef A KASSERT() is better. 2014-06-22 17:23:34 +00:00
riastradh
2191ea5a51 Correct type of i in execve_dovmcmds. Fixes DEBUG_EXEC build. 2014-04-25 18:04:45 +00:00
uebayasi
82d46164cd execve_runproc: Isolate emul specific code into a function. 2014-04-20 00:20:01 +00:00
uebayasi
f207cc4217 copyinargs: Shorten a local var name. 2014-04-19 23:00:27 +00:00
uebayasi
ea85945d7a copyinargs: Plug theoretical memory leak when fakearg is too long.
Pointed out & reviewed by Maxime Villard.
2014-04-19 22:59:08 +00:00
maxv
dc8c3423b2 'error' is not set on failure. This is a true bug: everything is freed
and unlocked while zero is returned. Since there's no error, execve_runproc()
will get called and will try to use those freed things.

PS: This bug was here before uebayasi@'s changes
2014-04-18 11:44:31 +00:00
uebayasi
a969a4cf8a calcargs: Correct the size of "argc" in the stack size calculation.
(The old code has worked because it is compensated by wrong size calculation
of "auxinfo" (multiplied by sizeof(void *)).)
2014-04-18 06:59:32 +00:00
uebayasi
c3b49b4f57 execve_runproc: Isolate vmcmd execution code into a function. 2014-04-16 02:22:38 +00:00
uebayasi
acaa1e700b execve_runproc: Isolate path / commandname (proc:p_comm) related code into a function. 2014-04-16 01:30:33 +00:00
uebayasi
532bc286ec execve_runproc: Isolate new stack arg filling code into a function. 2014-04-15 17:06:21 +00:00
uebayasi
e4f9e005a5 execve_runproc: Isolate ps_strings filling code into a function. 2014-04-15 16:44:57 +00:00
uebayasi
0244fbfc39 execve_runproc: Simplify &argc address calc. The set of (argc, argv, ...)
is located just "behind" the initial SP.  SHRINK, then ALLOC, and you get
&argc.
2014-04-15 16:13:04 +00:00
uebayasi
9605f3cc61 exec_loadvm: Isolate stack size calc logic into separate functions. 2014-04-15 15:50:16 +00:00
uebayasi
3d725db397 copyinargs: Redo previous; if given fakearg is longer than arg buf (which is
very unlikely to happen), there's no point to continue with truncated arg.
Just give up and return E2BIG.
2014-04-14 13:14:38 +00:00
uebayasi
dd3e806542 copyinargs: Replace a hand-written string copy loop with strlcpy(3). Carefully
reuse return value of strlcpy(3) to iterate.
2014-04-14 05:39:19 +00:00
uebayasi
4adfcd2c94 Revert braces. 2014-04-13 12:11:01 +00:00
uebayasi
eecddf1604 copyinargs: Refactor. Share code. 2014-04-13 09:19:42 +00:00