Commit Graph

66 Commits

Author SHA1 Message Date
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
martin 03ee7892c9 Fix a comment and a few minor optimizations:
* elf_check_header() already ensures eh.e_phnum > MAXPHNUM, so do not
   test it again at the call site
 * is_dyn == true implies a successfull call to elf_check_header(eh, ET_DYN),
   so no need to call elf_check_header(eh, ET_EXEC)

From Maxime Villard.
2013-08-26 12:24:10 +00:00
skrll 38fd17d91a Fix PAX build. 2013-04-09 07:39:01 +00:00
skrll 94a59cc1db Remove some set but unused variables 2013-04-08 21:12:33 +00:00
matt 3e95365cba back out elf note changes and use EF_ARM_ABIVERS to determine EABI usage. 2012-08-05 01:43:58 +00:00
matt 2051fb7586 Add a elf note to describe the ARM ABI in use. If encounters on arm,
set EXEC_ARM_AAPCS bit in exec_package's ep_flags.
XXX kind of gross but it there's isn't a MD hook for notes so ...
2012-08-03 07:54:14 +00:00
christos 632a99a18c put back missing break; 2012-06-02 18:32:27 +00:00
christos cf50f3a20b the gnu tag name is valid for both type 1 (abi) and type 3 (build id) 2012-06-02 16:48:13 +00:00
christos 95a363c914 - Recognize the SuSE ABI note.
- Restructure the code to do the checking in the appropriate note type,
and harmonize all the checks to be positive.
- Print only the tag data being careful not to overrun the allocated buffer.
2012-05-22 02:40:05 +00:00
martin 94b761b6aa Rework posix_spawn locking and memory management:
- always provide a vmspace for the new proc, initially borrowing from proc0
   (this part fixes PR 46286)
 - increase parallelism between parent and child if arguments allow this,
   avoiding a potential deadlock on exec_lock
 - add a new flag for userland to request old (lockstepped) behaviour for
   better error reporting
 - adapt test cases to the previous two and add a new variant to test the
   diagnostics flag
 - fix a few memory (and lock) leaks
 - provide netbsd32 compat
2012-04-08 11:27:44 +00:00
martin f8c7c04bbe Add a posix_spawn syscall, as discussed on tech-kern.
Based on the summer of code project by Charles Zhang, heavily reworked
later by me - all bugs are likely mine.
Ok: core, releng.
2012-02-11 23:16:15 +00:00
joerg 307c7101da Add AuxInfo record with the base address of the main thread. 2012-02-04 18:12:02 +00:00
matt 2210079e9b Add a hook for freeing an ep_emul_arg. Add a wrapper routine
(exec_free_emul_arg) to call the hook and then clear the ep_emul_arg
and ep_emul_arg_free members in the exec_package.
Change users/accessors to use these routines.
Approved by releng.
2012-02-03 20:11:53 +00:00
matt 993d752c0e Use kmem instead of malloc. 2012-02-01 21:49:52 +00:00
tls 3afd44cf08 First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>.  This change includes
the following:

	An initial cleanup and minor reorganization of the entropy pool
	code in sys/dev/rnd.c and sys/dev/rndpool.c.  Several bugs are
	fixed.  Some effort is made to accumulate entropy more quickly at
	boot time.

	A generic interface, "rndsink", is added, for stream generators to
	request that they be re-keyed with good quality entropy from the pool
	as soon as it is available.

	The arc4random()/arc4randbytes() implementation in libkern is
	adjusted to use the rndsink interface for rekeying, which helps
	address the problem of low-quality keys at boot time.

	An implementation of the FIPS 140-2 statistical tests for random
	number generator quality is provided (libkern/rngtest.c).  This
	is based on Greg Rose's implementation from Qualcomm.

	A new random stream generator, nist_ctr_drbg, is provided.  It is
	based on an implementation of the NIST SP800-90 CTR_DRBG by
	Henric Jungheim.  This generator users AES in a modified counter
	mode to generate a backtracking-resistant random stream.

	An abstraction layer, "cprng", is provided for in-kernel consumers
	of randomness.  The arc4random/arc4randbytes API is deprecated for
	in-kernel use.  It is replaced by "cprng_strong".  The current
	cprng_fast implementation wraps the existing arc4random
	implementation.  The current cprng_strong implementation wraps the
	new CTR_DRBG implementation.  Both interfaces are rekeyed from
	the entropy pool automatically at intervals justifiable from best
	current cryptographic practice.

	In some quick tests, cprng_fast() is about the same speed as
	the old arc4randbytes(), and cprng_strong() is about 20% faster
	than rnd_extract_data().  Performance is expected to improve.

	The AES code in src/crypto/rijndael is no longer an optional
	kernel component, as it is required by cprng_strong, which is
	not an optional kernel component.

	The entropy pool output is subjected to the rngtest tests at
	startup time; if it fails, the system will reboot.  There is
	approximately a 3/10000 chance of a false positive from these
	tests.  Entropy pool _input_ from hardware random numbers is
	subjected to the rngtest tests at attach time, as well as the
	FIPS continuous-output test, to detect bad or stuck hardware
	RNGs; if any are detected, they are detached, but the system
	continues to run.

	A problem with rndctl(8) is fixed -- datastructures with
	pointers in arrays are no longer passed to userspace (this
	was not a security problem, but rather a major issue for
	compat32).  A new kernel will require a new rndctl.

	The sysctl kern.arandom() and kern.urandom() nodes are hooked
	up to the new generators, but the /dev/*random pseudodevices
	are not, yet.

	Manual pages for the new kernel interfaces are forthcoming.
2011-11-19 22:51:18 +00:00
reinoud f64aeb0d94 In execve1(), don't assume VM_MIN_ADDRESS is 0 for PIE executables. 2011-08-27 17:53:21 +00:00
christos 3bcfc66d27 Add SuSE note 2011-08-02 16:44:01 +00:00
christos 442d0c330c don't produce diagnostics for GNU tags 2011-07-19 19:45:36 +00:00
joerg 5c3ccd6eba Pass down ELF Auxillary Vectors for static NetBSD binaries too.
Rename __libc_init to _libc_init and call it explicitly from CSU code.
This enforces the constructor run order for newly linked programs.
Keep it as constructor with run-once semantic for binary compatibility.
Implement dl_iterate_phdr for statically linked programs.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.
2011-03-07 05:09:09 +00:00
pooka 5aace62bf3 augment comment 2011-02-15 11:43:53 +00:00
chs 79f3dfff82 when we use a fake data section, make sure that the start is page-aligned. 2010-10-07 02:14:02 +00:00
chs 590b90699b always supply an auxiliary vector for linux ELF processes.
static executables (such as newer versions of /sbin/ldconfig)
require this to work properly.  since static executables
also don't have a PT_PHDR entry, use the same heuristic as
linux does to provide a value for AT_PHDR in this case.
2010-09-11 20:49:28 +00:00
joerg b5e51c26bb Remember the end of the last text segment and set up a fake data segment
if size 0 and starting after the text segments, if no data segment was
found. Unbreaks sbrk on platforms where all loaded segments are
executable (PR 43817). The cast of executable segments after data
segments is left out for now.
2010-09-07 21:32:03 +00:00
joerg e84862bd9b Allow ELF objects with more than two PT_LOAD sections. Go creates such
binaries by default with separate sections for executable, writeable
data and constants. Use the same heuristic as FreeBSD to match up the
text and data segment assumptions.
2010-08-20 14:59:53 +00:00
hannken 1423e65b26 Clean up vnode lock operations pass 2:
VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.
2010-06-24 12:58:48 +00:00
dholland c2fc97579a Improve previous: there were two printfs and I'd only noticed and fixed
one of them. PR 43217.
2010-06-06 06:20:16 +00:00
dholland 30c9deb259 Don't printf a userspace pointer; print the copied-in kernel version
instead, now that it's readily available. Fixes PR 43217.
2010-05-02 06:35:21 +00:00
christos 8c20e0e884 fix debugging printf. 2010-04-02 14:11:18 +00:00
drochner 713b10dc38 When choosing the start address of a dynamic (ie relocatable) executable,
respect the alignment in the ELF phdr.
Also, for correctness, use the maximum alignment of the PT_LOAD
sections rather than just the first one found.
Also, use more meaningful types.
2010-03-22 22:10:10 +00:00
christos b691db097d more debugging compilation fixes. 2010-03-20 01:52:16 +00:00
christos 7fa75c35d6 fix debugging code. 2010-03-20 01:47:12 +00:00