summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_proc.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC r309676vangyzen2016-12-151-1/+9
| | | | | | | | | | | | | Export the whole thread name in kinfo_proc kinfo_proc::ki_tdname is three characters shorter than thread::td_name. Add a ki_moretdname field for these three extra characters. Add the new field to kinfo_proc32, as well. Update all in-tree consumers to read the new field and assemble the full name, except for lldb's HostThreadFreeBSD.cpp, which I will handle separately. Bump __FreeBSD_version. Sponsored by: Dell EMC
* MFC r292384:bdrewery2016-06-271-16/+13
| | | | | | Fix style issues around existing SDT probes. ** Changes to sys/netinet/in_kdtrace.c and sys/netinet/in_kdtrace.h skipped.
* MFC r298173:markj2016-04-251-6/+3
| | | | Use a loop instead of a goto in sysctl_kern_proc_kstack().
* MFC r295391:kib2016-03-121-12/+7
| | | | Remove the assert which outlived its usefulness.
* MFC 287442,287537,288944:jhb2016-02-101-5/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix corruption of coredumps due to procstat notes changing size during coredump generation. The changes in r287442 required some reworking since the 'fo_fill_kinfo' file op does not exist in stable/10. 287442: Detect badly behaved coredump note helpers 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. 287537: Follow-up to r287442: Move sysctl to compiled-once file Avoid duplicate sysctl nodes. 288944: Fix core corruption caused by race in note_procstat_vmmap 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. Approved by: re (gjb)
* MFC 290728:jhb2016-01-181-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | Export various helper variables describing the layout and size of certain kernel structures for use by debuggers. This mostly aids in examining cores from a kernel without debug symbols as a debugger can infer these values if debug symbols are available. One set of variables describes the layout of 'struct linker_file' to walk the list of loaded kernel modules. A second set of variables describes the layout of 'struct proc' and 'struct thread' to walk the list of processes in the kernel and the threads in each process. The 'pcb_size' variable is used to index into the stoppcbs[] array. The 'vm_maxuser_address' is used to distinguish kernel virtual addresses from user addresses. This doesn't have to be perfect, and 'vm_maxuser_address' is a cheap and simple way to differentiate kernel pointers from simple values like TIDs and PIDs. While here, annotate the fields in struct pcb used by kgdb on amd64 and i386 to note that their ABI should be preserved. Annotations for other platforms will be added in the future.
* To facillitate an upcoming Linuxulator merging partiallydchagin2016-01-091-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | MFC r275121 (by kib). Only merge the syntax changes from r275121, PROC_*LOCK() macros still lock the same proc spinlock. The process spin lock currently has the following distinct uses: - Threads lifetime cycle, in particular, counting of the threads in the process, and interlocking with process mutex and thread lock. The main reason of this is that turnstile locks are after thread locks, so you e.g. cannot unlock blockable mutex (think process mutex) while owning thread lock. - Virtual and profiling itimers, since the timers activation is done from the clock interrupt context. Replace the p_slock by p_itimmtx and PROC_ITIMLOCK(). - Profiling code (profil(2)), for similar reason. Replace the p_slock by p_profmtx and PROC_PROFLOCK(). - Resource usage accounting. Need for the spinlock there is subtle, my understanding is that spinlock blocks context switching for the current thread, which prevents td_runtime and similar fields from changing (updates are done at the mi_switch()). Replace the p_slock by p_statmtx and PROC_STATLOCK(). Discussed with: kib
* MFC r292440:mjg2016-01-071-0/+1
| | | | | | | | | | | | proc: fix a race which could result in dereference of bad p_pgrp pointer on fork During fork p_starcopy - p_endcopy area of a process is populated with bcopy with only proc lock held. Another forking thread can find such a process and proceed to access p_pgrp included in said area. Fix the problem by moving the field outside. It is being properly assigned later.
* MFC r288336: save some bytes by using more concise SDT_PROBE<n>avg2015-10-231-6/+6
|
* MFC 287864:jhb2015-10-071-1/+1
| | | | | | | | | | When a process group leader exits, all of the processes in the group are sent SIGHUP and SIGCONT if any of the processes are stopped. Currently this behavior is triggered for any type of process stop including ptrace() stops and transient stops for single threading during exit() and execve(). Thus, if a debugger is attached to a process in a group when the leader exits, the entire group can be HUPed. Instead, only send the signals if a process in the group is stopped due to SIGSTOP.
* MFC r283924vangyzen2015-10-021-2/+18
| | | | | | | | | | | | | | | Provide vnode in memory map info for files on tmpfs When providing memory map information to userland, populate the vnode pointer for tmpfs files. Set the memory mapping to appear as a vnode type, to match FreeBSD 9 behavior. This fixes the use of tmpfs files with the dtrace pid provider, procstat -v, procfs, linprocfs, pmc (pmcstat), and ptrace (PT_VM_ENTRY). Submitted by: Eric Badger <eric@badgerio.us> (initial revision) Obtained from: Dell Inc. PR: 198431
* MFC r282086:trasz2015-08-031-1/+1
| | | | | | | | | Make setproctitle(3) work in Capsicum capability mode. This makes ctld(8) child processes to indicate initiator address and name in their titles, similar to what iscsid(8) child processes do. PR: 181352 Sponsored by: The FreeBSD Foundation
* MFC r272566:kib2015-03-121-8/+14
| | | | Convert -1 from sbuf_bcat() to ENOMEM.
* MFC r275745:kib2014-12-271-0/+139
| | | | | | | | | | Add facility to stop all userspace processes. MFC r275753: Fix gcc build. MFC r275820: Add missed break.
* MFC r269656:kib2014-08-211-3/+4
| | | | | | | | | | Implement and use proc_realparent(9). MFC r270024 (by markj): Correct the order of arguments passed to LIST_INSERT_AFTER(). For merge, the p_treeflag member of struct proc was moved to the end of the structure, to keep KBI intact.
* MFC r269205:kib2014-08-011-1/+1
| | | | Simplify the expression.
* MFC r268466:kib2014-07-241-35/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | Calculate the amount of resident pages by looking in the objects chain backing the region. Add a knob to disable the residency calculation at all. MFC r268490: Unconditionally initialize addr to handle the case of changed map timestamp while the map is unlocked. MFC r268711: Change the calculation of the kinfo_vmentry field kve_private_resident to reflect its name. MFC r268712: Followup to r268466. - Move the code to calculate resident count into separate function. It reduces the indent level and makes the operation of vmmap_skip_res_cnt tunable more clear. - Optimize the calculation of the resident page count for map entry. Skip directly to the next lowest available index and page among the whole shadow chain. - Restore the use of pmap_incore(9), only to verify that current mapping is indeed superpage. - Note the issue with the invalid pages.
* MFC 261780:jhb2014-02-191-0/+3
| | | | | Expose OBJT_MGTDEVICE VM objects used for GEM/TTM with drm2 as an explicit object type.
* MFC r258622: dtrace sdt: remove the ugly sname parameter of SDT_PROBE_DEFINEavg2014-01-171-6/+6
|
* MFC r258661:kib2013-12-031-0/+58
| | | | | | | Add sysctl KERN_PROC_SIGTRAMP to retrieve signal trampoline location for the given process. Approved by: re (gjb)
* Extend the support for exempting processes from being killed when swap isjhb2013-09-191-0/+2
| | | | | | | | | | | | | | | | | | | | | | exhausted. - Add a new protect(1) command that can be used to set or revoke protection from arbitrary processes. Similar to ktrace it can apply a change to all existing descendants of a process as well as future descendants. - Add a new procctl(2) system call that provides a generic interface for control operations on processes (as opposed to the debugger-specific operations provided by ptrace(2)). procctl(2) uses a combination of idtype_t and an id to identify the set of processes on which to operate similar to wait6(). - Add a PROC_SPROTECT control operation to manage the protection status of a set of processes. MADV_PROTECT still works for backwards compatability. - Add a p_flag2 to struct proc (and a corresponding ki_flag2 to kinfo_proc) the first bit of which is used to track if P_PROTECT should be inherited by new child processes. Reviewed by: kib, jilles (earlier version) Approved by: re (delphij) MFC after: 1 month
* Add the ability to display the default FIB number for a process to thewill2013-08-261-0/+2
| | | | | | | | | | | | | | | | | | ps(1) utility, e.g. "ps -O fib". bin/ps/keyword.c: Add the "fib" keyword and default its column name to "FIB". bin/ps/ps.1: Add "fib" as a supported keyword. sys/compat/freebsd32/freebsd32.h: sys/kern/kern_proc.c: sys/sys/user.h: Add the default fib number for a process (p->p_fibnum) to the user land accessible process data of struct kinfo_proc. Submitted by: Oliver Fromme <olli@fromme.com>, gibbs
* Specify SDT probe argument types in the probe definition itself rather thanmarkj2013-08-151-27/+12
| | | | | | | | | using SDT_PROBE_ARGTYPE(). This will make it easy to extend the SDT(9) API to allow probes with dynamically-translated types. There is no functional change. MFC after: 2 weeks
* Similarly to proc_getargv() and proc_getenvv(), export proc_getauxv()trociny2013-04-141-18/+29
| | | | | | to be able to reuse the code. MFC after: 3 weeks
* Re-factor the code to provide kern_proc_filedesc_out(), kern_proc_out(),trociny2013-04-141-52/+86
| | | | | | | | | | | and kern_proc_vmmap_out() functions to output process kinfo structures to sbuf, to make the code reusable. The functions are going to be used in the coredump routine to store procstat info in the core program header notes. Reviewed by: kib MFC after: 3 weeks
* Switch some "low-hanging fruit" to acquire read lock on vmobjectsattilio2013-04-081-10/+10
| | | | | | | | rather than write locks. Sponsored by: EMC / Isilon storage division Reviewed by: alc Tested by: pho
* Rename VM_OBJECT_LOCK(), VM_OBJECT_UNLOCK() and VM_OBJECT_TRYLOCK() toattilio2013-02-201-10/+10
| | | | | | their "write" versions. Sponsored by: EMC / Isilon storage division
* Switch vm_object lock to be a rwlock.attilio2013-02-201-0/+1
| | | | | | | | * VM_OBJECT_LOCK and VM_OBJECT_UNLOCK are mapped to write operations * VM_OBJECT_SLEEP() is introduced as a general purpose primitve to get a sleep operation using a VM_OBJECT_LOCK() as protection * The approach must bear with vm_pager.h namespace pollution so many files require including directly rwlock.h
* Look for zombie process only if we were given process id.pjd2012-11-251-5/+6
| | | | | | Reviewed by: kib MFC after: 2 weeks X-MFC-after-or-with: 243142
* In pget(9), if PGET_NOTWEXIT flag is not specified, also search thekib2012-11-161-21/+46
| | | | | | | | | | | | zombie list for the pid. This allows several kern.proc sysctls to report useful information for zombies. Hold the allproc_lock around all searches instead of relocking it. Remove private pfind_locked() from the new nfs client code. Requested and reviewed by: pjd Tested by: pho MFC after: 3 weeks
* enterpgrp: get rid of pgrp2 variable and use KASSERT directly on pgfind result.mjg2012-11-131-5/+1
| | | | | | | pgrp2 was used only for debugging, but pgrp2 = pgfind(..) was present in compiled code even for kernels without INVARIANTS Approved by: trasz (mentor) MFC after: 1 week
* Remove the support for using non-mpsafe filesystem modules.kib2012-10-221-9/+2
| | | | | | | | | | | | In particular, do not lock Giant conditionally when calling into the filesystem module, remove the VFS_LOCK_GIANT() and related macros. Stop handling buffers belonging to non-mpsafe filesystems. The VFS_VERSION is bumped to indicate the interface change which does not result in the interface signatures changes. Conducted and reviewed by: attilio Tested by: pho
* Don't include opt_ddb.h & <ddb/ddb.h> twice.obrien2012-08-151-2/+0
|
* After the PHYS_TO_VM_PAGE() function was de-inlined, the main reasonkib2012-08-051-0/+1
| | | | | | | | | | | | | to pull vm_param.h was removed. Other big dependency of vm_page.h on vm_param.h are PA_LOCK* definitions, which are only needed for in-kernel code, because modules use KBI-safe functions to lock the pages. Stop including vm_param.h into vm_page.h. Include vm_param.h explicitely for the kernel code which needs it. Suggested and reviewed by: alc MFC after: 2 weeks
* - Add support for displaying process stack memory regions.pgj2012-07-161-0/+4
| | | | | Approved by: rwatson MFC after: 3 days
* Fix ki_cow for compat32 binaries.kib2012-05-271-0/+1
| | | | MFC after: 3 days
* Calculate the count of per-process cow faults. Export the count tokib2012-05-231-0/+4
| | | | | | | userspace using the obscure spare int field in struct kinfo_proc. Submitted by: Andrey Zonov <andrey zonov org> MFC after: 1 week
* Allow for the process information sysctls to accept a thread id in additionkib2012-04-231-1/+30
| | | | | | | | | | | | | to the process id. It follows the ptrace(2) interface and allows debugging libraries to use thread ids directly, without slow and verbose conversion of thread id into pid. The PGET_NOTID flag is provided to allow a specific sysctl to disallow this behaviour. All current callers of pget(9) have useful semantic to operate on tid and do not need this flag. Reviewed by: jhb, trocini MFC after: 1 week
* Add a sysctl to set and retrieve binary osreldate of another process.trociny2012-03-231-0/+50
| | | | | | Suggested by: kib Reviewed by: kib MFC after: 2 weeks
* Make kern.proc.umask sysctl readonly.trociny2012-03-031-21/+4
| | | | | Requested by: src MFC after: 1 week
* Add sysctl to retrieve or set umask of another process.trociny2012-02-261-0/+48
| | | | | | | Submitted by: Dmitry Banschikov <me ubique spb ru> Discussed with: kib, rwatson Reviewed by: kib MFC after: 2 weeks
* Fix CTL flags in the declarations of KERN_PROC_ENV, AUXV andtrociny2012-01-251-8/+6
| | | | | | PS_STRINGS sysctls: they are read only. MFC after: 1 week
* Change kern.proc.rlimit sysctl to:trociny2012-01-221-16/+40
| | | | | | | | | | | | | - retrive only one, specified limit for a process, not the whole array, as it was previously (the sysctl has been added recently and has not been backported to stable yet, so this change is ok); - allow to set a resource limit for another process. Submitted by: Andrey Zonov <andrey at zonov.org> Discussed with: kib Reviewed by: kib MFC after: 2 weeks
* Abrogate nchr argument in proc_getargv() and proc_getenvv(): we always wanttrociny2012-01-151-13/+12
| | | | | | | | | | | | | | | to read strings completely to know the actual size. As a side effect it fixes the issue with kern.proc.args and kern.proc.env sysctls, which didn't return the size of available data when calling sysctl(3) with the NULL argument for oldp. Note, in get_ps_strings(), which does actual work for proc_getargv() and proc_getenvv(), we still have a safety limit on the size of data read in case of a corrupted procces stack. Suggested by: kib MFC after: 3 days
* Fix style and white spaces.trociny2011-12-171-14/+14
| | | | MFC after: 1 week
* On start most of sysctl_kern_proc functions use the same pattern:trociny2011-12-171-112/+80
| | | | | | | | | | | | | locate a process calling pfind() and do some additional checks like p_candebug(). To reduce this code duplication a new function pget() is introduced and used. As the function may be useful not only in kern_proc.c it is in the kernel name space. Suggested by: kib Reviewed by: kib MFC after: 2 weeks
* Really protect kern.proc.ps_strings sysctls with p_candebug(). Thistrociny2011-12-061-1/+1
| | | | | | | was intended to be in r228288. Spotted by: many MFC after: 1 week
* Protect kern.proc.auxv and kern.proc.ps_strings sysctls with p_candebug().trociny2011-12-051-2/+4
| | | | | | | | | | | | | | | | | | Citing jilles: If we are ever going to do ASLR, the AUXV information tells an attacker where the stack, executable and RTLD are located, which defeats much of the point of randomizing the addresses in the first place. Given that the AUXV information seems to be used by debuggers only anyway, I think it would be good to move it to p_candebug() now. The full virtual memory maps (KERN_PROC_VMMAP, procstat -v) are already under p_candebug(). Suggested by: jilles Discussed with: rwatson MFC after: 1 week
* In sysctl_kern_proc_ps_strings() there is no much sense in checkingtrociny2011-12-041-8/+0
| | | | | | for P_WEXIT and P_SYSTEM flags. Reviewed by: kib
* Add sysctl to retrieve ps_strings structure location of another process.trociny2011-11-271-0/+57
| | | | | Suggested by: kib Reviewed by: kib
OpenPOWER on IntegriCloud