summaryrefslogtreecommitdiffstats
path: root/sys/kern/imgact_elf.c
Commit message (Collapse)AuthorAgeFilesLines
* Use the same expression to report stack protection mode for AT_STACKEXECkib2011-01-081-2/+3
| | | | as the expression used by exec_new_vmspace().
* In elf image activator, read and apply the stack protection mode fromkib2011-01-081-5/+17
| | | | | | | | | | | | | PT_GNU_STACK program header, if present and enabled. Two new sysctls are provided, kern.elf32.nxstack and kern.elf64.nxstack, that allow to enable PT_GNU_STACK for ABIs of specified bitsize, if ABI decided to support shared page. Inform rtld about access mode of the stack initial mapping by AT_STACKPROT aux vector. At the moment, the default is disabled, waiting for the usermode support bits.
* Collect code to translate between vm_prot_t and p_flags into helperkib2011-01-081-22/+35
| | | | | | functions. MFC after: 1 week
* Add the ability for GDB to printout the thread name along with otherattilio2010-11-221-0/+10
| | | | | | | | | | | | | | | | | | | | thread specific informations. In order to do that, and in order to avoid KBI breakage with existing infrastructure the following semantic is implemented: - For live programs, a new member to the PT_LWPINFO is added (pl_tdname) - For cores, a new ELF note is added (NT_THRMISC) that can be used for storing thread specific, miscellaneous, informations. Right now it is just popluated with a thread name. GDB, then, retrieves the correct informations from the corefile via the BFD interface, as it groks the ELF notes and create appropriate pseudo-sections. Sponsored by: Sandvine Incorporated Tested by: gianni Discussed with: dim, kan, kib MFC after: 2 weeks
* Supply some useful information to the started image using ELF aux vectors.kib2010-08-171-0/+11
| | | | | | | | In particular, provide pagesize and pagesizes array, the canary value for SSP use, number of host CPUs and osreldate. Tested by: marius (sparc64) MFC after: 1 month
* Don't leak core_buf or gzfile if doing a compressed core file and wealfred2010-04-301-4/+7
| | | | | | hit an error condition. Obtained from: Juniper Networks
* Add the ELF relocation base to struct image_params. This will benwhitehorn2010-03-251-0/+1
| | | | | required to correctly relocate the executable entry point's function descriptor on powerpc64.
* Change the way text_addr and data_addr are computed to use thenwhitehorn2010-03-251-11/+6
| | | | | | | | | | | executable status of segments instead of detecting the main text segment by which segment contains the program entry point. This affects obreak() and is required for correct operation of that function on 64-bit PowerPC systems. The previous behavior was apparently required only for the Alpha, which is no longer supported. Reviewed by: jhb Tested on: amd64, sparc64, powerpc
* Provide groundwork for 32-bit binary compatibility on non-x86 platforms,nwhitehorn2010-03-111-9/+6
| | | | | | | | | for upcoming 64-bit PowerPC and MIPS support. This renames the COMPAT_IA32 option to COMPAT_FREEBSD32, removes some IA32-specific code from MI parts of the kernel and enhances the freebsd32 compatibility code to support big-endian platforms. Reviewed by: kib, jhb
* put calls to gzclose() under ifdef COMPRESS_USER_CORES to preventalfred2010-03-041-1/+1
| | | | | | undefined symbols on kernels without this option. Reported by: Alexander Best
* Merge projects/enhanced_coredumps (r204346) into HEAD:alfred2010-03-021-16/+156
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Enhanced process coredump routines. This brings in the following features: 1) Limit number of cores per process via the %I coredump formatter. Example: if corefilename is set to %N.%I.core AND num_cores = 3, then if a process "rpd" cores, then the corefile will be named "rpd.0.core", however if it cores again, then the kernel will generate "rpd.1.core" until we hit the limit of "num_cores". this is useful to get several corefiles, but also prevent filling the machine with corefiles. 2) Encode machine hostname in core dump name via %H. 3) Compress coredumps, useful for embedded platforms with limited space. A sysctl kern.compress_user_cores is made available if turned on. To enable compressed coredumps, the following config options need to be set: options COMPRESS_USER_CORES device zlib # brings in the zlib requirements. device gzio # brings in the kernel vnode gzip output module. 4) Eventhandlers are fired to indicate coredumps in progress. 5) The imgact sv_coredump routine has grown a flag to pass in more state, currently this is used only for passing a flag down to compress the coredump or not. Note that the gzio facility can be used for generic output of gzip'd streams via vnodes. Obtained from: Juniper Networks Reviewed by: kan
* If ET_DYN binary has non-zero base address for some reason, honour itkib2009-10-181-5/+20
| | | | | | | | | | | | | | | | | and do not relocate the binary to ET_DYN_LOAD_ADDR. This allows for the binary author to influence address map of the process. In particular, when the binary is actually an interpeter, this allows to have almost usual process address map. Communicate the relocation bias of the mapping for interpeter-less ET_DYN binary, that is interperter itself, in AT_BASE aux entry. This way, rtld is able to find its dynamic structure and relocate itself. Note that mapbase in the rtld is still wrong and requires further fixing. Reported and tested by: rwatson Discussed with: kan MFC after: 3 days
* Map PIE binaries at non-zero base address.kib2009-10-101-10/+14
| | | | | | | Discussed with: bz Reviewed by: kan Tested by: bz (i386, amd64), bsam (linux) MFC after: some time
* Do not map segments of zero length.kib2009-10-101-1/+4
| | | | | | | Discussed with: bz Reviewed by: kan Tested by: bz (i386, amd64), bsam (linux) MFC after: some time
* Print a warning in case we cannot add more brandinfo becausebz2009-10-031-1/+4
| | | | | | | we would overflow the MAX_BRANDS sized array. Reviewed by: kib MFC After: 1 month
* Make sure FreeBSD binaries without .note.ABI-tag section workbz2009-08-301-5/+13
| | | | | | | | | | | | | | | | | | | | | correctly and do not match a colliding Debian GNU/kFreeBSD brandinfo statements. For this mark the Debian GNU/kFreeBSD brandinfo that it must have an .note.ABI-tag section and ignore the old EI_OSABI brandinfo when comparing a possibly colliding set of options. Due to SYSINIT we add the brandinfo in a non-deterministic order, so native FreeBSD is not always first. We may want to consider to force native FreeBSD to come first as well. The only way a problem could currently be noticed is when running an i386 binary without the .note.ABI-tag on amd64 and the Debian GNU/kFreeBSD brandinfo was matched first, as the fallback to ld-elf32.so.1 does not exist in that case. Reported and tested by: ticso In collaboration with: kib MFC after: 3 days
* Fix handling of .note.ABI-tag section for GNU systems [1].bz2009-08-241-6/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Handle GNU/Linux according to LSB Core Specification 4.0, Chapter 11. Object Format, 11.8. ABI note tag. Also check the first word of desc, not only name, according to glibc abi-tags specification to distinguish between Linux and kFreeBSD. Add explicit handling for Debian GNU/kFreeBSD, which runs on our kernels as well [2]. In {amd64,i386}/trap.c, when checking osrel of the current process, also check the ABI to not change the signal behaviour for Linux binary processes, now that we save an osrel version for all three from the lists above in struct proc [2]. These changes make it possible to run FreeBSD, Debian GNU/kFreeBSD and Linux binaries on the same machine again for at least i386 and amd64, and no longer break kFreeBSD which was detected as GNU(/Linux). PR: kern/135468 Submitted by: dchagin [1] (initial patch) Suggested by: kib [2] Tested by: Petr Salinger (Petr.Salinger seznam.cz) for kFreeBSD Reviewed by: kib MFC after: 3 days
* Fix KBI breakage by r190520 which affects older linux.ko binaries:dchagin2009-04-051-1/+1
| | | | | | | | | | | | | | 1) Move the new field (brand_note) to the end of the Brandinfo structure. 2) Add a new flag BI_BRAND_NOTE that indicates that the brand_note pointer is valid. 3) Use the brand_note field if the flag BI_BRAND_NOTE is set and as old modules won't have the flag set, so the new field brand_note would be ignored. Suggested by: jhb Reviewed by: jhb Approved by: kib (mentor) MFC after: 6 days
* Fix several issues with parsing the notes for ELF objects.kib2009-03-221-5/+5
| | | | | | | | | | | | | | | | | | | Badly formed ELF note may cause the caclulated pointer to the next note to point both after the note region, that was checked in the code, but also to point before the region, that was not checked [1]. Remember the first note location in note0 and leap out if the note is not between note0 and note_end. In the similar way, badly formed note may cause infinite loop by pointing next note into the same or previous note. Guard against this by limiting amount of loop iterations by arbitrary choosen big number. For clarity, check the calculated note alignment in each iteration. Reported by: Chris Palmer <chris noncombatant org> [1] PR: kern/132886 Reviewed and tested by: dchagin MFC after: 3 days
* Supply AT_EXECPATH auxinfo entry to the interpreter, both for native andkib2009-03-171-0/+2
| | | | | | | compat32 binaries. Tested by: pho Reviewed by: kan
* Use the properly sized types for ELF object header and program headers.kib2009-03-171-4/+4
| | | | | | | | | This fixes osrel fetching from the FreeBSD branding note for the 64bit platforms. Reported by: swell.k gmail com Reviewed by: dchagin Tested by: dchagin, swell.k gmail com
* Implement new way of branding ELF binaries by looking to adchagin2009-03-131-51/+101
| | | | | | | | | | | | ".note.ABI-tag" section. The search order of a brand is changed, now first of all the ".note.ABI-tag" is looked through. Move code which fetch osreldate for ELF binary to check_note() handler. PR: 118473 Approved by: kib (mentor)
* When a statically linked binary is executed (or at least, one withoutrwatson2009-01-251-1/+2
| | | | | | | | | | | | | | | | | | | | | an interpreter definition in its program header), set the auxiliary ELF argument AT_BASE to 0 rather than to the address that we would have mapped the interpreter at if there had been one. The ELF ABI specifications appear to be ambiguous as to the desired behavior in this situation, as they define AT_BASE as the base address of the interpreter, but do not mention what to do if there is none. On Solaris, AT_BASE will be set to the base address of the static binary if there is no interpreter, and on Linux, AT_BASE is set to 0. We go with the Linux semantics as they are of more immediate utility and allow the early runtime environment to know that the kernel has not mapped an interpreter, but because AT_PHDR points at the ELF header for the running binary, it is still possible to retrieve all required mapping information when the process starts should it be required. Either approach would be preferable to our current behavior of passing a pointer to an unmapped region of user memory as AT_BASE. MFC after: 3 weeks
* Remove sysctl debug.elf_trace and the trace field in auxargs. They gopeter2008-12-171-4/+0
| | | | | nowhere. It used to be the equivalent of $LD_DEBUG in rtld-elf. Elf_Auxargs is an internal structure.
* Minor style(9) nit.imp2008-12-171-2/+1
|
* Remove two remnant uses of AT_DEBUG.kib2008-12-171-3/+0
|
* If the ABI-overriden interpreter was not loaded, do not setkib2008-10-081-1/+2
| | | | | | | | | have_interp to TRUE. This allows the code in image activator to try /libexec/ld-elf.so.1 as interpreter when newinterp is not found to execute. Reviewed by: peter MFC after: 2 weeks (together with r175105)
* Go back to using the process command name (p_comm) for the file name andjhb2008-05-151-2/+2
| | | | | | | command line arguments stored in the note at the beginning of a core dump instead of the current thread name. Reviewed by: julian
* Remove kernel support for M:N threading.jeff2008-03-121-6/+2
| | | | | | | | While the KSE project was quite successful in bringing threading to FreeBSD, the M:N approach taken by the kse library was never developed to its full potential. Backwards compatibility will be provided via libmap.conf for dynamically linked binaries and static binaries will be broken.
* VOP_LOCK1() (and so VOP_LOCK()) and VOP_UNLOCK() are only used inattilio2008-01-131-3/+2
| | | | | | | | | | | conjuction with 'thread' argument passing which is always curthread. Remove the unuseful extra-argument and pass explicitly curthread to lower layer functions, when necessary. KPI results broken by this change, which should affect several ports, so version bumping and manpage update will be further committed. Tested by: kris, pho, Diego Sardina <siarodx at gmail dot com>
* vn_lock() is currently only used with the 'curthread' passed as argument.attilio2008-01-101-2/+2
| | | | | | | | | | | | | | | | Remove this argument and pass curthread directly to underlying VOP_LOCK1() VFS method. This modify makes the code cleaner and in particular remove an annoying dependence helping next lockmgr() cleanup. KPI results, obviously, changed. Manpage and FreeBSD_version will be updated through further commits. As a side note, would be valuable to say that next commits will address a similar cleanup about VFS methods, in particular vop_lock1 and vop_unlock. Tested by: Diego Sardina <siarodx at gmail dot com>, Andrea Di Pasquale <whyx dot it at gmail dot com>
* Fall back to the binary-specified interpreter (ld-elf.so.1) if thepeter2008-01-051-4/+10
| | | | | | ABI override binary isn't found. This could probably be smoother, but it is what I did in p4 change #126891 on 2007/09/27. It should solve the "ld-elf32.so.1"-in-chroot problem.
* Implement fetching of the __FreeBSD_version from the ELF ABI-tag note.kib2007-12-041-3/+43
| | | | | | | The value is read into the p_osrel member of the struct proc. p_osrel is set to 0 for the binaries without the note. MFC after: 3 days
* Check for the program headers alignment of the ELF images beforekib2007-12-041-3/+10
| | | | | | | | dereferencing. Unaligned access could cause panic on strict alignment architectures. Reviewed by: marcel, marius (also tested on sparc64, thanks !) MFC after: 3 days
* A bunch more files that should probably print out a thread namejulian2007-11-141-2/+2
| | | | instead of a process name.
* Fix for the panic("vm_thread_new: kstack allocation failed") andkib2007-11-051-1/+3
| | | | | | | | | | | | | | | | | | | | silent NULL pointer dereference in the i386 and sparc64 pmap_pinit() when the kmem_alloc_nofault() failed to allocate address space. Both functions now return error instead of panicing or dereferencing NULL. As consequence, vmspace_exec() and vmspace_unshare() returns the errno int. struct vmspace arg was added to vm_forkproc() to avoid dealing with failed allocation when most of the fork1() job is already done. The kernel stack for the thread is now set up in the thread_alloc(), that itself may return NULL. Also, allocation of the first process thread is performed in the fork1() to properly deal with stack allocation failure. proc_linkup() is separated into proc_linkup() called from fork1(), and proc_linkup0(), that is used to set up the kernel process (was known as swapper). In collaboration with: Peter Holm Reviewed by: jhb
* Rework the support for ABIs to override resource limits (used by 32-bitjhb2007-05-141-1/+1
| | | | | | | | | | | | | | | | | | | processes under 64-bit kernels). Previously, each 32-bit process overwrote its resource limits at exec() time. The problem with this approach is that the new limits affect all child processes of the 32-bit process, including if the child process forks and execs a 64-bit process. To fix this, don't ovewrite the resource limits during exec(). Instead, sv_fixlimits() is now replaced with a different function sv_fixlimit() which asks the ABI to sanitize a single resource limit. We then use this when querying and setting resource limits. Thus, if a 32-bit process sets a limit, then that new limit will be inherited by future children. However, if the 32-bit process doesn't change a limit, then a future 64-bit child will see the "full" 64-bit limit rather than the 32-bit limit. MFC is tentative since it will break the ABI of old linux.ko modules (no other modules are affected). MFC after: 1 week
* Use FOREACH_PROC_IN_SYSTEM instead of using its unrolled form.delphij2007-01-171-1/+1
|
* Add vm map and object locking to each_writable_segment().alc2006-11-191-10/+15
| | | | | Noticed by: jhb@ MFC after: 3 weeks
* Avoid a vm object reference leak in a rarely used code path.alc2006-01-211-10/+7
| | | | | | | | | | An executable contains at most one PT_INTERP program header. Therefore, the loop that searches for it can terminate after it is found rather than iterating over the entire set of program headers. Eliminate an unneeded initialization. Reviewed by: tegge
* Fix breakage introduced in the previous commit.sobomax2005-12-261-4/+2
|
* Remove kern.elf32.can_exec_dyn sysctl. Instead extend Brandinfo structuresobomax2005-12-261-7/+10
| | | | | | | | | | with flags bitfield and set BI_CAN_EXEC_DYN flag for all brands that usually allow executing elf dynamic binaries (aka shared libraries). When it is requested to execute ET_DYN elf image check if this flag is on after we know the elf brand allowing execution if so. PR: kern/87615 Submitted by: Marcin Koziej <creep@desk.pl>
* Maintain the lock on the vnode for most of exec_elfN_imgact().alc2005-12-241-32/+35
| | | | | | | | | | | | | Specifically, it is required for the I/O that may be performed by elfN_load_section(). Avoid an obscure deadlock in the a.out, elf, and gzip image activators. Add a comment describing why the deadlock does not occur in the common case and how it might occur in less usual circumstances. Eliminate an unused variable from exec_aout_imgact(). In collaboration with: tegge
* Maintain the vnode lock throughout elfN_load_file() rather than releasingalc2005-12-211-21/+13
| | | | | | | | it and reacquiring it in vrele(). Consequently, there is no reason to increase the reference count on the vm object caching the file's pages. Reviewed by: tegge Eliminate unused parameters to elfN_load_file().
* Eliminate an unneeded (vm_prot_t) parameter from two functions. Eliminatealc2005-12-201-15/+10
| | | | | | unnecessary uses of a local variable. Reviewed by: tegge
* Correct a long-standing problem in elfN_map_insert(): In order to copy aalc2005-12-171-1/+1
| | | | | | | page to user space, the user space mapping must allow write access. In collaboration with: tegge@ MFC after: 3 weeks
* Style: The second argument to vm_map_find() should be NULL instead of 0.alc2005-12-161-1/+1
|
* Use sf_buf_alloc() instead of vm_map_find() on exec_map to create thealc2005-12-161-61/+29
| | | | | | | | | | | | | | | | | ephemeral mappings that are used as the source for three copy operations from kernel space to user space. There are two reasons for making this change: (1) Under heavy load exec_map can fill up causing vm_map_find() to fail. When it fails, the nascent process is aborted (SIGABRT). Whereas, this reimplementation using sf_buf_alloc() sleeps. (2) Although it is possible to sleep on vm_map_find()'s failure until address space becomes available (see kmem_alloc_wait()), using sf_buf_alloc() is faster. Furthermore, the reimplementation uses a CPU private mapping, avoiding a TLB shootdown on multiprocessors. Problem uncovered by: kris@ Reviewed by: tegge@ MFC after: 3 weeks
* Add a new sysctl, kern.elf[32|64].can_exec_dyn. When set to 1, one cancognet2005-11-141-1/+7
| | | | | | | | | execute a ET_DYN binary (shared object). This does not make much sense, but some linux scripts expect to be able to execute /lib/ld-linux.so.2 (ldd comes to mind). The sysctl defaults to 0. MFC after: 3 days
* Back out alpha/alpha/trap.c:1.124, osf1_ioctl.c:1.14, osf1_misc.c:1.57,rwatson2005-09-281-6/+0
| | | | | | | | | | | | | | | | | | | | osf1_signal.c:1.41, amd64/amd64/trap.c:1.291, linux_socket.c:1.60, svr4_fcntl.c:1.36, svr4_ioctl.c:1.23, svr4_ipc.c:1.18, svr4_misc.c:1.81, svr4_signal.c:1.34, svr4_stat.c:1.21, svr4_stream.c:1.55, svr4_termios.c:1.13, svr4_ttold.c:1.15, svr4_util.h:1.10, ext2_alloc.c:1.43, i386/i386/trap.c:1.279, vm86.c:1.58, unaligned.c:1.12, imgact_elf.c:1.164, ffs_alloc.c:1.133: Now that Giant is acquired in uprintf() and tprintf(), the caller no longer leads to acquire Giant unless it also holds another mutex that would generate a lock order reversal when calling into these functions. Specifically not backed out is the acquisition of Giant in nfs_socket.c and rpcclnt.c, where local mutexes are held and would otherwise violate the lock order with Giant. This aligns this code more with the eventual locking of ttys. Suggested by: bde
OpenPOWER on IntegriCloud