Commit Graph

96 Commits

Author SHA1 Message Date
christos
00cf4274d3 stsrt with an alignment of 1 (which means no alignment). From alnsn 2018-03-18 13:18:39 +00:00
christos
109cfb3271 Turn KASSERTS that check alignment which are user triggerable into errors.
From alnsn
2018-03-18 02:16:21 +00:00
christos
374568837c CID/1427732: Don't dereference NULL execname if there is no emul_arg.
(there always is one in our emulations) from alnsn@
2018-03-17 00:30:50 +00:00
christos
0011aa658c Store full executable path in p->p_path as discussed in tech-kern.
This means that the full executable path is always available.

- exec_elf.c: use p->path to set AT_SUN_EXECNAME, and since this is
  always set, do so unconditionally.
- kern_exec.c: simplify pathexec, use kmem_strfree where appropriate
  and set p->p_path
- kern_exit.c: free p->p_path
- kern_fork.c: set p->p_path for the child.
- kern_proc.c: use p->p_path to return the executable pathname; the
  NULL check for p->p_path, should be a KASSERT?
- exec.h: gc ep_path, it is not used anymore
- param.h: bump version, 'struct proc' size change

TODO:
1. reference count the path string, to save copy at fork and free
   just before exec?
2. canonicalize the pathname by changing namei() to LOCKPARENT
   vnode and then using getcwd() on the parent directory?
2017-11-07 19:44:04 +00:00
christos
bb321f6151 Setting AT_BASE on static binaries breaks TLS because they assume that
it is 0, will fix it differently.
2017-10-16 01:50:55 +00:00
christos
3df3b581f3 For static PIE set the interpreter address to be the entry offset so we
don't lose it.
2017-10-08 15:00:40 +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
chs
006dc29ca6 obey the executable's ELF alignment constraints for PIE.
this fixes gdb of PIE binaries on mac68k (and other platforms
which use an ELF alignment that is larger than PAGE_SIZE).
2017-02-18 01:29:09 +00:00
uwe
1159401280 netbsd_elf_signature - look at note segments (phdrs) not note
sections.  They point to the same data in the file, but sections are
for linkers and are not necessarily present in an executable.

The original switch from phdrs to shdrs seems to be just a cop-out to
avoid parsing multiple notes per segment, which doesn't really avoid
the problem b/c sections also can contain multiple notes.
2017-02-12 21:52:46 +00:00
christos
cbcfdd13ce oops removed too much 2016-09-15 18:40:34 +00:00
christos
406ea0ab88 Add debugging. 2016-09-15 17:45:44 +00:00
christos
cd1c56e89e randomize the location of the rtld. 2016-05-25 17:25:32 +00:00
christos
b039ee7763 reduce #ifdef mess caused by PaX 2016-05-22 14:26:09 +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
b1ba608e8b Allow enabling and disabling PaX ASLR debug 2016-03-19 18:56:37 +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
christos
41dca8aba0 Ignore the ancient 01.01 tag that gnuc used to put in old NetBSD binaries. 2015-11-01 17:44:41 +00:00
christos
f5789f4f44 Add buildid Go note 2015-11-01 15:21:42 +00:00
maxv
856f192f05 Check the error code from es_setup_stack, and correctly free ep_emul_arg if
it fails.

That bug is harmless, since ep_setup_stack never fails.
2015-10-22 11:38:51 +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
maxv
6a1d6f071c revert; but still fix the comment 2015-08-08 06:24:40 +00:00
maxv
22674dbcd0 stupid comment, and make sure we are not executing a lib 2015-08-05 15:58:01 +00:00
maxv
b36a7fd23d Some changes, to reduce a bit my tech-kern@ patch:
- move the P_PAX_ flags out of #ifdef PAX_ASLR in pax.h
 - add a generic pax_flags_active() function
 - fix a comment in exec_elf.c; interp is not static
 - KNF for return
 - rename pax_aslr() to pax_aslr_mmap()
 - rename pax_segvguard_cb() to pax_segvguard_cleanup_cb()
2015-08-04 18:28:09 +00:00
maxv
c0b150f033 Revamp PaX:
- don't confuse between ELF flags and proc flags. Introduce the proc-
   specific P_PAX_ASLR, P_PAX_MPROTECT and P_PAX_GUARD flags.
 - introduce pax_setup_elf_flags(), which takes as argument the PaX flag
   of the ELF PaX note section, and which sets the proc flag as
   appropriate. Also introduce a couple of other functions used for that
   purpose.
 - modify pax_aslr_active(), and all the other similar pieces of code, so
   that it checks the proc flag directly, without extra ELF computation

In addition to making PaX clearer, the combination of these changes fixes
the following bug: if a non-PaX'ed process is launched, and then someone
sets security.pax.{aslr,mprotect,segvguard}.global=1, the process becomes
PaX'ed while its address space hasn't been randomized, which is not likely
to be a good idea.

Now, only the proc flag is checked at runtime, which means the process's
PaX status won't be altered during the execution.

Also:
 - declare PAX_DPRINTF, makes it more readable
 - fix a typo in exec_elf.h
2015-07-30 15:28:18 +00:00
maxv
1a624e5aac Remove #ifdef notyet. 2015-04-27 09:19:58 +00:00
maxv
06b89b30f2 Zero-fill the ELF auxiliary vectors. Otherwise, on 64bit systems, the
padding between a_v and a_type contains kernel garbage, therefore
exposed to userland.

Original report by uebayasi@
2015-03-20 20:36:27 +00:00
chs
99a9d84aad eliminate COMPAT_OLDNOTE and just always recognize the old notes. 2014-08-17 23:03:58 +00:00
maxv
8754c3d9cf Define ELF_MAXNOTESIZE, ELF_MAXSHNUM and ELF_MAXPHNUM in <sys/exec_elf.h>, so
that it can be used externally.
2014-07-08 17:16:25 +00:00
maxv
477e684b2e Check .evs_used==0 instead of .evs_cmds==NULL. evs_cmds would not be NULL if
another _makecmds() had allocated and deallocated VMCMDs (not the case
currently).
2014-07-06 07:41:41 +00:00
christos
32d87f41a7 Provide a compatibility define for binaries generated before NetBSD 1.5.
These binaries contain multiple notes per section and their NetBSD version
value is 199905. This is enabled via COMPAT_OLDNOTE (default off).
2014-06-25 17:10:39 +00:00
christos
7360fa8391 be a bit more verbose about why we think a note is bad. 2014-05-15 19:37:22 +00:00
maxv
d8a274dfb9 Small changes:
- rename elf_load_file() to elf_load_interp()
 - use the correct type for 'nused'
 - remove useless cases
 - reorder a kmem_alloc

ok christos@
2014-03-22 07:27:21 +00:00
maxv
7c09916210 Remove the 'prot' argument from elf_load_psection(). It is not used
outside, and can be declared locally. Clearer.

ok christos@
2014-03-16 07:57:25 +00:00
matt
ab77483fb9 add ep_entryoffset to exec_package so one can calculate the relocabase
of an ET_DYN image.
2014-03-06 09:30:37 +00:00
maxv
ff3f3d5c44 We have to ensure the string is NUL-terminated and of the expected
length to avoid copying uninitialized data.

ok christos@
2014-02-27 09:58:05 +00:00
maxv
33cfa4fef0 Simplify error path.
ok christos@
2014-02-22 07:53:16 +00:00
maxv
c14dea48b0 Properly check the section size to avoid out-of-bound reads. The
computed size must be the exact same size that is indicated in
sh_size.

ok agc@ christos@
2014-02-21 07:47:02 +00:00
maxv
c22b5e2a12 We need VMCMDs for a binary and its interpreter, so make sure we have
at least one VMCMD. This also prevents the kernel from using an
uninitialized pointer as entry point for the execution.

From me and Christos

ok christos@
2014-02-19 15:23:20 +00:00
maxv
03cdabd0dd Small cleanup:
- make elf_load_file() and elf_load_psection() static
 - make loops consistent
 - 'nload' is not used - see rev1.24
 - 'ap' is not used in elf_load_file()

ok agc@ christos@
2014-02-16 17:46:36 +00:00
christos
6f9879ba7d initialize offset to 0 (Maxime Villard) 2014-02-15 17:39:03 +00:00
maxv
c11747d060 Remove the last argument of elf_check_header(). It is easier - and faster - to
check the e_type field in the calling function. Other BSD's already do this.

ok christos@
2014-02-15 16:17:01 +00:00
maxv
1a33eb9d1c Fix memory leak.
ok christos@ agc@
2014-02-14 07:30:07 +00:00
christos
840bc63029 __USING_TOPDOWN_VM is no more, __USE_TOPDOWN_VM... 2014-01-25 19:44:11 +00:00
skrll
04e9e004ed Check interp after reading it. Checking newly allocated memory doesn't
work.

Hi Christos.
2013-12-21 17:44:33 +00:00
christos
39826d358b Consistency checks for the length of the interpreter (the length includes
the trailing NUL): make sure it is not empty and has the proper length.
From Maxime Villard
2013-12-21 14:41:02 +00:00
martin
41de4c61e8 As discussed on tech-kern: make TOPDOWN-VM runtime selectable per process
(offer MD code or emulations to override it).
2013-11-14 12:07:11 +00:00
martin
2fae30a160 Remove dead code 2013-11-11 15:22:11 +00:00
martin
c04325564a Define a new NetBSD specific note to encode the code model used for a binary.
Allow MD code to check these notes in the exec path.
2013-11-05 14:26:19 +00:00
joerg
1e90a44d68 Preserve NetBSD version from the ABI tag for compat use. 2013-10-30 23:32:30 +00:00
matt
50bfeb714d Support an optional MARCH ELF tag.
Store the MACHINE_ARCH of the executable in mdproc and override sysctl
so that value returned.
2013-09-10 21:30:21 +00:00