summaryrefslogtreecommitdiffstats
path: root/sys/kern/imgact_elf.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC r315518alc2017-06-281-4/+6
| | | | | | | | | | | | | | Avoid unnecessary calls to vm_map_protect() in elf_load_section(). Typically, when elf_load_section() unconditionally passed VM_PROT_ALL to elf_map_insert(), it was needlessly enabling execute access on the mapping, and it would later have to call vm_map_protect() to correct the mapping's access rights. Now, instead, elf_load_section() always passes its parameter "prot" to elf_map_insert(). So, elf_load_section() must only call vm_map_protect() if it needs to remove the write access that was temporarily granted to perform a copyout(). Approved by: re (kib)
* MFC 313407,313449: Copy ELF machine/flags from binaries to core dumps.jhb2017-05-111-6/+4
| | | | | | | | | | | | | | | | | 313407: Copy the e_machine and e_flags fields from the binary into an ELF core dump. In the kernel, cache the machine and flags fields from ELF header to use in the ELF header of a core dump. For gcore, the copy these fields over from the ELF header in the binary. This matters for platforms which encode ABI information in the flags field (such as o32 vs n32 on MIPS). 313449: Trim trailing whitespace (mostly introduced in r313407). Sponsored by: DARPA / AFRL
* Improvements for the brand detection and prioritization.kib2017-04-061-7/+20
| | | | | | | | | | | | | | | | | | | MFC r315701 (by ed): Set the interpreter path to /nonexistent. MFC r315749: Adjust r314851 to not require every brand to specify interpreter path. MFC r315753: Add a flag BI_BRAND_ONLY_STATIC to specify that the brand only matches static binaries. MFC r315754: Update r315753 with the proper flag name. MFC r316211: A followup to r315749, two more places where brand->interp_path was accessed unconditionally.
* MFC r315860:ed2017-04-061-1/+2
| | | | | | | | | Don't require the presence of the compat_3_brand. The existing ELF image activator requires the brandinfo to provide such a string unconditionally, even if the executable format in question doesn't use this type of branding. Skip matching when it's a null pointer.
* MFC r315157:kib2017-03-191-3/+7
| | | | Accept linkers representation for ELF segments with zero on-disk length.
* MFC r315156:kib2017-03-191-10/+4
| | | | Style.
* MFC r314717,315085alc2017-03-181-45/+42
| | | | | | Style and punctuation fixes. Simplify the control flow and tidy up a comment in map_insert.
* MFC r314851:kib2017-03-141-2/+15
| | | | | When selecting brand based on old Elf branding, prefer the brand which interpreter exactly matches the one requested by the activated image.
* MFC r314850:kib2017-03-141-2/+2
| | | | Require whole brand string matching for old Elf branding.
* MFC r314849:kib2017-03-141-3/+3
| | | | | Consistently use vm_ooffset_t type for the vm object offset in elf_load_section.
* Switch from the usage of vm_map_find()/vm_map_insert() to vm_map_fixed().kib2017-03-131-11/+7
| | | | | | | | MFC r314487: Use vm_map_insert() instead of vm_map_find() in elf_map_insert(). MFC r314773: Instead of direct use of vm_map_insert(), call vm_map_fixed(MAP_CHECK_EXCL).
* MFC r314486:kib2017-03-131-7/+12
| | | | | | When deallocating the vm object in elf_map_insert() due to vm_map_insert() failure, drop the vnode lock around the call to vm_object_deallocate().
* MFC r314562:kib2017-03-051-2/+1
| | | | Style.
* MFC r312532: don't abort writing of a core dump after EFAULTavg2017-01-261-7/+34
|
* MFC 303002: Include process IDs in core dumps.jhb2016-10-281-0/+1
| | | | | | | | | When threads were added to the kernel, the pr_pid member of the NT_PRSTATUS note was repurposed to store LWP IDs instead of process IDs. However, the process ID was no longer recorded in core dumps. This change adds a pr_pid field to prpsinfo (NT_PRSINFO). Rather than bumping the prpsinfo version number, note parsers can use the note's payload size to determine if pr_pid is present.
* MFC r306674:kib2016-10-071-3/+2
| | | | Style.
* MFC 302859: Include command line arguments in core dump process info.jhb2016-10-061-7/+41
| | | | | Fill in pr_psargs in the NT_PRSINFO ELF core dump note with command line arguments.
* add description for debug.elf{32,64}_legacy_coredump sysctlemaste2016-07-051-1/+2
| | | | | | Approved by: re (kib) MFC after: 1 week Sponsored by: The FreeBSD Foundation
* Include machine/acle-compat.h in cdefs.h on arm if the compiler doesn'tian2016-05-251-3/+0
| | | | | | | | | | | | | | | | | | | | | | have ACLE support built in. The ACLE (ARM C Language Extensions) defines a set of standardized symbols which indicate the architecture version and features available. ACLE support is built in to modern compilers (both clang and gcc), but absent from gcc prior to 4.4. ARM (the company) provides the acle-compat.h header file to define the right symbols for older versions of gcc. Basically, acle-compat.h does for arm about the same thing cdefs.h does for freebsd: defines standardized macros that work no matter which compiler you use. If ARM hadn't provided this file we would have ended up with a big #ifdef __arm__ section in cdefs.h with our own compatibility shims. Remove #include <machine/acle-compat.h> from the zillion other places (an ever-growing list) that it appears. Since style(9) requires sys/types.h or sys/param.h early in the include list, and both of those lead to including cdefs.h, only a couple special cases still need to include acle-compat.h directly. Loves it: imp
* sys: use our roundup2/rounddown2() macros when param.h is available.pfg2016-04-211-2/+2
| | | | | | | | | | rounddown2 tends to produce longer lines than the original code and when the code has a high indentation level it was not really advantageous to do the replacement. This tries to strike a balance between readability using the macros and flexibility of having the expressions, so not everything is converted.
* Remove some NULL checks for M_WAITOK allocations.trasz2016-03-291-4/+0
| | | | | MFC after: 1 month Sponsored by: The FreeBSD Foundation
* When matching brand to the ELF binary by notes, try to find a brandkib2016-02-041-1/+20
| | | | | | | | | | | | | | | | | | | | | with interpreter name exactly matching one wanted by the binary. If no such brand exists, return first brand which accepted the binary by note. The change fixes a regression after r292749, where e.g. our two ia32 compat brands, ia32_brand_info and ia32_brand_oinfo, only differ by the interpeter path and binary matches to a brand by linkage order. Then old binaries which require /usr/libexec/ld-elf.so.1 but matched against ia32_brand_info with interp_path /libexec/ld-elf.so.1, were considered requiring non-standard interpreter name, and magic to force ld-elf32.so.1 did not happen. Note that it might make sense to apply the same selection of brands for other matching criteria, SCO EI_OSABI and 3.x string. Reported and tested by: dwmalone Sponsored by: The FreeBSD Foundation MFC after: 3 days
* Do not substitute interpeter if the brand interpreter path iskib2015-12-261-1/+3
| | | | | | | | | | | different from the interpreter path requested by the binary. Before this change, it is impossible to activate non-default interpreter for 32bit image on amd64, when /libexec/ld-elf32.so.1 file exists. Sponsored by: The FreeBSD Foundation MFC after: 2 weeks
* Only allow one PT_INTERP ELF program header. This also fixes a potentialjtl2015-12-241-0/+5
| | | | | | | | | memory leak for interp_buf. Differential Revision: https://reviews.freebsd.org/D4692 Reviewed by: kib MFC after: 2 weeks Sponsored by: Juniper Networks
* If we annoy user with the terminal output due to failed load ofkib2015-12-221-1/+2
| | | | | | | | interpreter, also show the actual error code instead of some interpretation. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* Replace magic value ELF note type with NT_FREEBSD_ABI_TAGemaste2015-12-071-1/+1
| | | | | | | As of r291909 elf_common.h provides a definition. Suggested by: kib Sponsored by: The FreeBSD Foundation
* Add support for usermode (vdso-like) gettimeofday(2) andkib2015-12-071-1/+5
| | | | | | | | | | | | | | | | | | clock_gettime(2) on ARMv7 and ARMv8 systems which have architectural generic timer hardware. It is similar how the RDTSC timer is used in userspace on x86. Fix a permission problem where generic timer access from EL0 (or userspace on v7) was not properly initialized on APs. For ARMv7, mark the stack non-executable. The shared page is added for all arms (including ARMv8 64bit), and the signal trampoline code is moved to the page. Reviewed by: andrew Discussed with: emaste, mmel Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D4209
* Missed header_supported call from r291020: make really, really sure the brandnwhitehorn2015-12-011-0/+3
| | | | likes the executable.
* Extend r270123 to run the brand info's header_supported() routine fornwhitehorn2015-11-181-2/+5
| | | | | | | | | branded as well as unbranded binaries. This will be required to add support for the new ELFv2 ABI on powerpc64, which is distinguished from ELFv1 by the contents of the ELF header's flags field. Reviewed by: imp MFC after: 2 weeks
* Define `compress` in `__elfN(coredump)` when #ifdef GZIO is true to mutengie2015-11-021-0/+2
| | | | | | | an -Wunused-but-set-variable warning Reported by: FreeBSD_HEAD_amd64_gcc4.9 jenkins job Sponsored by: EMC / Isilon Storage Division
* Allow PT_INTERP and PT_NOTES segments to be located anywhere in thekib2015-10-141-40/+100
| | | | | | | | | | | | | executable image. Keep one page (arbitrary) limit on the max allowed size of the PT_NOTES. The ELF image activators still require that program headers of the executable are fully contained in the first page of the image file. Reviewed by: emaste, jhb Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D3871
* Fix core corruption caused by race in note_procstat_vmmapcem2015-10-061-4/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fix is spiritually similar to r287442 and was discovered thanks to the KASSERT added in that revision. NT_PROCSTAT_VMMAP output length, when packing kinfo structs, is tied to the length of filenames corresponding to vnodes in the process' vm map via vn_fullpath. As vnodes may move during coredump, this is racy. We do not remove the race, only prevent it from causing coredump corruption. - Add a sysctl, kern.coredump_pack_vmmapinfo, to allow users to disable kinfo packing for PROCSTAT_VMMAP notes. This avoids VMMAP corruption and truncation, even if names change, at the cost of up to PATH_MAX bytes per mapped object. The new sysctl is documented in core.5. - Fix note_procstat_vmmap to self-limit in the second pass. This addresses corruption, at the cost of sometimes producing a truncated result. - Fix PROCSTAT_VMMAP consumers libutil (and libprocstat, via copy-paste) to grok the new zero padding. Reported by: pho (https://people.freebsd.org/~pho/stress/log/datamove4-2.txt) Relnotes: yes Sponsored by: EMC / Isilon Storage Division Differential Revision: https://reviews.freebsd.org/D3824
* Follow-up to r287442: Move sysctl to compiled-once filecem2015-09-071-6/+1
| | | | | | | | | Avoid duplicate sysctl nodes. Found by: tijl Approved by: markj (mentor) Sponsored by: EMC / Isilon Storage Division Differential Revision: https://reviews.freebsd.org/D3586
* Detect badly behaved coredump note helperscem2015-09-031-7/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Coredump notes depend on being able to invoke dump routines twice; once in a dry-run mode to get the size of the note, and another to actually emit the note to the corefile. When a note helper emits a different length section the second time around than the length it requested the first time, the kernel produces a corrupt coredump. NT_PROCSTAT_FILES output length, when packing kinfo structs, is tied to the length of filenames corresponding to vnodes in the process' fd table via vn_fullpath. As vnodes may move around during dump, this is racy. So: - Detect badly behaved notes in putnote() and pad underfilled notes. - Add a fail point, debug.fail_point.fill_kinfo_vnode__random_path to exercise the NT_PROCSTAT_FILES corruption. It simply picks random lengths to expand or truncate paths to in fo_fill_kinfo_vnode(). - Add a sysctl, kern.coredump_pack_fileinfo, to allow users to disable kinfo packing for PROCSTAT_FILES notes. This should avoid both FILES note corruption and truncation, even if filenames change, at the cost of about 1 kiB in padding bloat per open fd. Document the new sysctl in core.5. - Fix note_procstat_files to self-limit in the 2nd pass. Since sometimes this will result in a short write, pad up to our advertised size. This addresses note corruption, at the risk of sometimes truncating the last several fd info entries. - Fix NT_PROCSTAT_FILES consumers libutil and libprocstat to grok the zero padding. With suggestions from: bjk, jhb, kib, wblock Approved by: markj (mentor) Relnotes: yes Sponsored by: EMC / Isilon Storage Division Differential Revision: https://reviews.freebsd.org/D3548
* Fix some error-handling bugs when core dump compression is enabled:markj2015-07-141-10/+11
| | | | | | | - Ensure that core dump parameters are initialized in the error path. - Don't call gzio_fini() on a NULL stream. Reported by: rpaulo
* Implement lockless resource limits.mjg2015-06-101-4/+4
| | | | | | | | | | Use the same scheme implemented to manage credentials. Code needing to look at process's credentials (as opposed to thred's) is provided with *_proc variants of relevant functions. Places which possibly had to take the proc lock anyway still use the proc pointer to access limits.
* Add user facing errors for exceeding process memory limitsemaste2015-06-081-10/+24
| | | | | | | | | | Previously the process terminating with SIGABRT at startup was the only notification. PR: 200617 Reviewed by: kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D2731
* Fix typo in symbol name. It helps to hit save in all your buffersimp2015-05-221-1/+1
| | | | before committing.
* Export the eflags field from the elf header. This allows betterimp2015-05-221-0/+4
| | | | | | | | | discrimination between different subarch binaries, at least for mips and arm. Arm is implemented, mips is still tbd, so not currently exported. aarch64 does not export this because aarch64 binaries use different tags and flags than arm. Differential Revision: https://reviews.freebsd.org/D2611
* Add kern.racct.enable tunable and RACCT_DISABLED config option.trasz2015-04-291-6/+8
| | | | | | | | | | | The point of this is to be able to add RACCT (with RACCT_DISABLED) to GENERIC, to avoid having to rebuild the kernel to use rctl(8). Differential Revision: https://reviews.freebsd.org/D2369 Reviewed by: kib@ MFC after: 1 month Relnotes: yes Sponsored by: The FreeBSD Foundation
* Implement support for binary to requesting specific stack size for thekib2015-04-151-0/+1
| | | | | | | | | | | | initial thread. It is read by the ELF image activator as the virtual size of the PT_GNU_STACK program header entry, and can be specified by the linker option -z stack-size in newer binutils. The soft RLIMIT_STACK is auto-increased if possible, to satisfy the binary' request. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* Reimplement support for userland core dump compression using a new interfacemarkj2015-03-091-152/+112
| | | | | | | | | | | | | | | | | | in kern_gzio.c. The old gzio interface was somewhat inflexible and has not worked properly since r272535: currently, the gzio functions are called with a range lock held on the output vnode, but kern_gzio.c does not pass the IO_RANGELOCKED flag to vn_rdwr() calls, resulting in deadlock when vn_rdwr() attempts to reacquire the range lock. Moreover, the new gzio interface can be used to implement kernel core compression. This change also modifies the kernel configuration options needed to enable userland core dump compression support: gzio is now an option rather than a device, and the COMPRESS_USER_CORES option is removed. Core dump compression is enabled using the kern.compress_user_cores sysctl/tunable. Differential Revision: https://reviews.freebsd.org/D1832 Reviewed by: rpaulo Discussed with: kib
* Allow the kern.osrelease and kern.osreldate sysctl values to be set in aian2015-02-271-1/+3
| | | | | | | | | | | | | | | | | | | | | jail's creation parameters. This allows the kernel version to be reliably spoofed within the jail whether examined directly with sysctl or indirectly with the uname -r and -K options. The values can only be set at jail creation time, to eliminate the need for any locking when accessing the values via sysctl. The overridden values are inherited by nested jails (unless the config for the nested jails also overrides the values). There is no sanity or range checking, other than disallowing an empty release string or a zero release date, by design. The system administrator is trusted to set sane values. Setting values that are newer than the actual running kernel will likely cause compatibility problems. Differential Revision: https://reviews.freebsd.org/D1948 Relnotes: yes
* Include OBJT_PHYS VM objects in ELF core dumps. In particular thisjhb2015-02-141-1/+2
| | | | | | | | | includes the shared page allowing debuggers to use the signal trampoline code to identify signal frames in core dumps. Differential Revision: https://reviews.freebsd.org/D1828 Reviewed by: alc, kib MFC after: 1 week
* The size value should be asserted when it is known.kib2014-11-221-1/+1
| | | | | Reported and tested by: pho Sponsored by: The FreeBSD Foundation
* Improve support for XSAVE with debuggers.jhb2014-11-211-3/+46
| | | | | | | | | | | | | | | | | | | - Dump an NT_X86_XSTATE note if XSAVE is in use. This note is designed to match what Linux does in that 1) it dumps the entire XSAVE area including the fxsave state, and 2) it stashes a copy of the current xsave mask in the unused padding between the fxsave state and the xstate header at the same location used by Linux. - Teach readelf() to recognize NT_X86_XSTATE notes. - Change PT_GET/SETXSTATE to take the entire XSAVE state instead of only the extra portion. This avoids having to always make two ptrace() calls to get or set the full XSAVE state. - Add a PT_GET_XSTATE_INFO which returns the length of the current XSTATE save area (so the size of the buffer needed for PT_GETXSTATE) and the current XSAVE mask (%xcr0). Differential Revision: https://reviews.freebsd.org/D1193 Reviewed by: kib MFC after: 2 weeks
* Fixes for i/o during coredumping:kib2014-10-041-4/+4
| | | | | | | | | | | | | | | | - Do not dump into system files. - Do not acquire write reference to the mount point where img.core is written, in the coredump(). The vn_rdwr() calls from ELF imgact request the write ref from vn_rdwr(). Recursive acqusition of the write ref deadlocks with the unmount. - Instead, take the range lock for the whole core file. This prevents parallel dumping from two processes executing the same image, converting the useless interleaved dump into sequential dumping, with second core overwriting the first. Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks
* Add missing proctree locking to fill_kinfo_proc consumers.mjg2014-08-301-0/+2
| | | | | | | | This fixes r270444. Pointy hat: mjg Reported by: many MFC after: 1 week
* Expand the elf brandelf infrastructure to give access to the whole ELFimp2014-08-181-0/+13
| | | | | | | | | | header (Elf_Ehdr) to determine if a particular interpretor wants to accept it or not. Use this mechanism to filter EABI arm on OABI arm kernels, and vice versa. This method could also be used to implement OABI on EABI arm kernels, if desired, or to allow a single mips kernel to run o32, n32 and n64 binaries. Differential Revision: https://reviews.freebsd.org/D609
* Remove ia64.marcel2014-07-071-2/+2
| | | | | | | | | | | | | | | | | This includes: o All directories named *ia64* o All files named *ia64* o All ia64-specific code guarded by __ia64__ o All ia64-specific makefile logic o Mention of ia64 in comments and documentation This excludes: o Everything under contrib/ o Everything under crypto/ o sys/xen/interface o sys/sys/elf_common.h Discussed at: BSDcan
OpenPOWER on IntegriCloud