summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_environment.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC r293045, r293046:ian2016-01-241-3/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make the 'env' directive described in config(5) work on all architectures, providing compiled-in static environment data that is used instead of any data passed in from a boot loader. Previously 'env' worked only on i386 and arm xscale systems, because it required the MD startup code to examine the global envmode variable and decide whether to use static_env or an environment obtained from the boot loader, and set the global kern_envp accordingly. Most startup code wasn't doing so. Making things even more complex, some mips startup code uses an alternate scheme that involves calling init_static_kenv() to pass an empty buffer and its size, then uses a series of kern_setenv() calls to populate that buffer. Now all MD startup code calls init_static_kenv(), and that routine provides a single point where envmode is checked and the decision is made whether to use the compiled-in static_kenv or the values provided by the MD code. The routine also continues to serve its original purpose for mips; if a non-zero buffer size is passed the routine installs the empty buffer ready to accept kern_setenv() values. Now if the size is zero, the provided buffer full of existing env data is installed. A NULL pointer can be passed if the boot loader provides no env data; this allows the static env to be installed if envmode is set to do so. Most of the work here is a near-mechanical change to call the init function instead of directly setting kern_envp. A notable exception is in xen/pv.c; that code was originally installing a buffer full of preformatted env data along with its non-zero size (like mips code does), which would have allowed kern_setenv() calls to wipe out the preformatted data. Now it passes a zero for the size so that the buffer of data it installs is treated as non-writeable. Also, revert accidental change that snuck into r293045.
* MFC Alexander Motin's direct dispatch, multi-queue, and finer-grainedscottl2014-01-071-27/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | locking support for CAM r256826: Fix several target mode SIMs to not blindly clear ccb_h.flags field of ATIO CCBs. Not all CCB flags there belong to them. r256836: Remove hard limit on number of BIOs handled with one ATA TRIM request. r256843: Merge CAM locking changes from the projects/camlock branch to radically reduce lock congestion and improve SMP scalability of the SCSI/ATA stack, preparing the ground for the coming next GEOM direct dispatch support. r256888: Unconditionally acquire periph reference on CCB allocation failure. r256895: Fix memory and references leak due to unfreed path. r256960: Move CAM_UNQUEUED_INDEX setting to the last moment and under the periph lock. This fixes race condition with cam_periph_ccbwait(), causing use-after-free. r256975: Minor (mostly cosmetical) addition to r256960. r257054: Some microoptimizations for da and ada drivers: - Replace ordered_tag_count counter with single flag; - From da remove outstanding_cmds counter, duplicating pending_ccbs list; - From da_softc remove unused links field. r257482: Fix lock recursion, triggered by `smartctl -a /dev/adaX`. r257501: Make getenv_*() functions and respectively TUNABLE_*_FETCH() macros not allocate memory and so not require sleepable environment. getenv() has already used on-stack temporary storage, so just use it more rationally. getenv_string() receives buffer as argument, so don't need another one. r257914: Some CAM locks polishing: - Fix LOR and possible lock recursion when handling high-power commands. Introduce new lock to protect left power quota and list of frozen devices. - Correct locking around xpt periph creation. - Remove seems never used XPT_FLAG_OPEN xpt periph flag. Again, Netflix assisted with testing the merge, but all of the credit goes to Alexander and iX Systems. Submitted by: mav Sponsored by: iX Systems
* r249408 and r249436 cause a NULL pointer dereference on the CUBIEBOARDimp2013-04-161-1/+1
| | | | | since it doesn't set the kernel envrionment at all. Work around this by making sure kern_envp is non-NULL before dereferencing it.
* Fix changes made in r249408.jchandra2013-04-131-1/+1
| | | | | | | | | | In some cases, kern_envp is set by the architecture code and env_pos does not contain the length of the static kernel environment. In these cases r249408 causes the kernel to discard the environment. Fix this by updating the check for empty static env to *kern_envp != '\0' Reported by: np@
* Fix kenv behavior when there is no static environmentjchandra2013-04-121-13/+16
| | | | | | | | | | In case where there are no static kernel environment entries, the function init_dynamic_kenv() adds an incorrect entry at position 0 of the dynamic kernel environment. This in turn causes kenv(1) to print and empty list even though there are dynamic entries added later. Fix this by checking env_pos in init_dynamic_kenv() and adding dynamic entries only if there are static entries.
* Reserve room for the terminating NUL when setting or getting kerneljh2012-08-141-6/+6
| | | | | environment variables. KENV_MNAMELEN and KENV_MVALLEN doesn't include space for the terminating NUL.
* In order to maximize the re-usability of kernel code in user space thiskmacy2011-09-161-1/+1
| | | | | | | | | | | | | patch modifies makesyscalls.sh to prefix all of the non-compatibility calls (e.g. not linux_, freebsd32_) with sys_ and updates the kernel entry points and all places in the code that use them. It also fixes an additional name space collision between the kernel function psignal and the libc function of the same name by renaming the kernel psignal kern_psignal(). By introducing this change now we will ease future MFCs that change syscalls. Reviewed by: rwatson Approved by: re (bz)
* In init_dynamic_kenv(), ignore environment strings exceeding thejh2011-05-231-1/+7
| | | | | | | | | KENV_MNAMELEN + 1 + KENV_MVALLEN + 1 length limit to avoid buffer overflow in getenv(). Currenly loader(8) doesn't limit the length of environment strings. PR: kern/132104 MFC after: 1 month
* To avoid duplicated warning, move WITNESS_WARN() added in r221597 to thejh2011-05-071-1/+2
| | | | | | branch which doesn't call malloc(9). Suggested by: kib
* Add WITNESS_WARN() to getenv() to explicitly note that the function mayjh2011-05-071-0/+1
| | | | | sleep. This helps to expose bugs when the requested environment variable doesn't exist.
* Merge change r198561 from projects/mips to head:imp2010-01-101-0/+33
| | | | | | | r198561 | thompsa | 2009-10-28 15:25:22 -0600 (Wed, 28 Oct 2009) | 4 lines Allow a scratch buffer to be set in order to be able to use setenv() while booting, before dynamic kenv is running. A few platforms implement their own scratch+sprintf handling to save data from the boot environment.
* Move "options MAC" from opt_mac.h to opt_global.h, as it's now in GENERICrwatson2009-06-051-2/+0
| | | | | | | | and used in a large number of files, but also because an increasing number of incorrect uses of MAC calls were sneaking in due to copy-and-paste of MAC-aware code without the associated opt_mac.h include. Discussed with: pjd
* Correctly sanity-check timer IDs. [SA-09:06]cperciva2009-03-231-3/+7
| | | | | | | | | | Limit the size of malloced buffer when dumping environment variables. [EN-09:01] Approved by: so (cperciva) Approved by: re (kensmith) Security: FreeBSD-SA-09:06.ktimer Errata: FreeBSD-EN-09:01.kenv
* Implement the following macros for completeness:pjd2008-07-211-0/+8
| | | | | | | | | SYSCTL_QUAD() SYSCTL_ADD_QUAD() TUNABLE_QUAD() TUNABLE_QUAD_FETCH() Now we can use 64bit tunables on 32bit systems.
* Merge first in a series of TrustedBSD MAC Framework KPI changesrwatson2007-10-241-4/+4
| | | | | | | | | | | | | | | | | | | | | | | from Mac OS X Leopard--rationalize naming for entry points to the following general forms: mac_<object>_<method/action> mac_<object>_check_<method/action> The previous naming scheme was inconsistent and mostly reversed from the new scheme. Also, make object types more consistent and remove spaces from object types that contain multiple parts ("posix_sem" -> "posixsem") to make mechanical parsing easier. Introduce a new "netinet" object type for certain IPv4/IPv6-related methods. Also simplify, slightly, some entry point names. All MAC policy modules will need to be recompiled, and modules not updates as part of this commit will need to be modified to conform to the new KPI. Sponsored by: SPARTA (original patches against Mac OS X) Obtained from: TrustedBSD Project, Apple Computer
* I don't know what I was smoking when I wrote these three years ago; thedes2007-10-131-4/+19
| | | | | | return value is an error code, hence always an int. While I'm here, add getenv_uint() for completeness.
* Further system call comment cleanup:rwatson2007-03-051-2/+1
| | | | | | | | | | - Remove also "MP SAFE" after prior "MPSAFE" pass. (suggested by bde) - Remove extra blank lines in some cases. - Add extra blank lines in some cases. - Remove no-op comments consisting solely of the function name, the word "syscall", or the system call name. - Add punctuation. - Re-wrap some comments.
* Sweep kernel replacing suser(9) calls with priv(9) calls, assigningrwatson2006-11-061-3/+11
| | | | | | | | | | | | | specific privilege names to a broad range of privileges. These may require some future tweaking. Sponsored by: nCircle Network Security, Inc. Obtained from: TrustedBSD Project Discussed on: arch@ Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri, Alex Lyashkov <umka at sevcity dot net>, Skip Ford <skip dot ford at verizon dot net>, Antoine Brodin <antoine dot brodin at laposte dot net>
* Complete break-out of sys/sys/mac.h into sys/security/mac/mac_framework.hrwatson2006-10-221-1/+2
| | | | | | | | | | | | | begun with a repo-copy of mac.h to mac_framework.h. sys/mac.h now contains the userspace and user<->kernel API and definitions, with all in-kernel interfaces moved to mac_framework.h, which is now included across most of the kernel instead. This change is the first step in a larger cleanup and sweep of MAC Framework interfaces in the kernel, and will not be MFC'd. Obtained from: TrustedBSD Project Sponsored by: SPARTA
* Use a sleep mutex instead of an sx lock for the kernel environment. Thisscottl2006-07-091-24/+26
| | | | | | allows greater flexibility for drivers that want to query the environment. Reviewed by: jhb, mux
* Fix memory leak introduced in previous revision.netchild2006-03-151-3/+3
| | | | Discussed with: phk
* Ignore kenv strings which overflow the room we have, rather than pretendphk2006-03-091-1/+6
| | | | we have room for them.
* Reorder statements to avoid accessing unknown memory.davidxu2005-09-261-2/+2
| | | | | In theory, invoking kenv with very long string can panic kernel.
* Add bounds checking to the setenv part of the kernel environment.netchild2005-07-311-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | This has no security implications since only root is allowed to use kenv(1) (and corrupt the kernel memory after adding too much variables previous to this commit). This is based upon the PR [1] mentioned below, but extended to check both bounds (in case of an overflow of the counting variable) and to comply to the style of the function. An overflow of the counting variable shouldn't happen after adding the check for the upper bound, but better safe than sorry (in case some other function in the kernel overwrites random memory). An interested soul may want to add a printf to notify root in case the bounds are hit. Also allocate KENV_SIZE+1 entries (the array is NULL-terminated), since the comment for KENV_SIZE says it's the maximum number of environment strings. [2] PR: 83687 [1] Submitted by: Harry Coin <harrycoin@qconline.com> [1] Submitted by: Ariff Abdullah <skywizard@MyBSD.org.my> [2]
* My addled brains didn't realize that since vtp points into value, wedes2005-03-091-2/+5
| | | | | | can't freeenv(value) before we're done inspecting vtp[0]. Tested by: Anish Mistry <mistry.7@osu.edu>
* Teach getenv_quad() to recognize k/m/g/t suffixes in both lower- anddes2005-03-051-3/+15
| | | | upper-case. This means (almost) all tunables now support those suffixes.
* Make a bunch of malloc types static.phk2005-02-101-1/+1
| | | | Found by: src/tools/tools/kernxref
* Retire TUNABLE_QUAD_*.des2004-11-081-8/+0
|
* Add TUNABLE_LONG and TUNABLE_ULONG, and use the latter for thedes2004-10-311-0/+46
| | | | | | | hw.pci.host_mem_start tunable. Add comments to TUNABLE_INT and TUNABLE_QUAD recommending against their use. MFC after: 3 weeks
* If the buffer supplied to kenv(KENV_DUMP, ...) isn't big enough,das2004-04-281-21/+18
| | | | | return the number of bytes needed instead of 0. The manpage claims that we do this anyway.
* Use __FBSDID().obrien2003-06-111-2/+3
|
* Back out M_* changes, per decision of the TRB.imp2003-02-191-6/+6
| | | | Approved by: trb
* Remove M_TRYWAIT/M_WAITOK/M_WAIT. Callers should use 0.alfred2003-01-211-6/+6
| | | | Merge M_NOWAIT/M_DONTWAIT into a single flag M_NOWAIT.
* remove syscallarg().alfred2002-12-141-4/+4
| | | | Suggested by: peter
* SCARGS removal take II.alfred2002-12-141-14/+14
|
* Backout removal SCARGS, the code freeze is only "selectively" over.alfred2002-12-131-14/+14
|
* Remove SCARGS.alfred2002-12-131-14/+14
| | | | Reviewed by: md5
* Add MAC checks for various kenv() operations: dump, get, set, unset,rwatson2002-11-011-1/+23
| | | | | | | permitting MAC policies to limit access to the kernel environment. Obtained from: TrustedBSD Project Sponsored by: DARPA, Network Associates Laboratories
* Use strlcpy() instead of strncpy() to copy NUL terminated stringsrobert2002-10-171-2/+1
| | | | for safety and consistency.
* Cosmetic tweaks. Try and keep the style more consistent, catch some straypeter2002-05-011-42/+41
| | | | whitespace and update a comment.
* Fixed some longstanding bugs in _getenv_static():bde2002-04-251-3/+4
| | | | | | | | | | | | | - malformed environment strings (ones without an '=') were not rejected. There shouldn't be any of these, but when the static environment is empty it always begins with one of these; this one should be considered as the terminator after the end of the environment, but it isn't. - the comparison of the name being looked up with the name in the environment was fuzzy -- only the characters up to the length of the latter were compared, so _getenv_static("foobar") matched "foo=..." in the environment and everything matched "" in the empty environment. MFC after: 3 days
* Avoid calling malloc() or free() while holding themux2002-04-171-13/+26
| | | | | | kenv lock. Reviewed by: jake
* Rework the kernel environment subsystem. We now convert the staticmux2002-04-171-59/+308
| | | | | | | | | | | | | | | | | environment needed at boot time to a dynamic subsystem when VM is up. The dynamic kernel environment is protected by an sx lock. This adds some new functions to manipulate the kernel environment : freeenv(), setenv(), unsetenv() and testenv(). freeenv() has to be called after every getenv() when you have finished using the string. testenv() only tests if an environment variable is present, and doesn't require a freeenv() call. setenv() and unsetenv() are self explanatory. The kenv(2) syscall exports these new functionalities to userland, mainly for kenv(1). Reviewed by: peter
* Fix an inverted test csae. Success of getenv() is determined by a returnjhb2001-10-251-1/+1
| | | | | | | value of !NUL rather than NUL. Submitted by: luigi Pointy hat to: jhb
* - Change getenv_quad() to return an int instead of a quad_t since itjhb2001-10-231-1/+21
| | | | | | returns an success/failure code rather than the actual value. - Add getenv_string() which copies a string from the environment to another string and returns true on success.
* Make MAXTSIZ, DFLDSIZ, MAXDSIZ, DFLSSIZ, MAXSSIZ, SGROWSIZ loaderps2001-10-101-0/+8
| | | | | | | tunable. Reviewed by: peter MFC after: 2 weeks
* Add a pointer to kenv(1).peter2001-09-211-0/+3
|
* Revert last commit. The same functionality can be obtained through thejlemon2001-09-211-26/+27
| | | | 'kenv' command, which I obviously was unaware of.
* Add a sysctl MIB 'kern.env', that dumps the contents of the kerneljlemon2001-09-201-27/+26
| | | | | environment from the loader, as well as the kernel's compiled in static hints.
* Fix some warnings in kern_environment.c. Make the getenv*() familypeter2001-06-151-3/+3
| | | | | | take a const 'name', since they dont modify anything. 159: warning: passing arg 1 of `getenv_int' discards qualifiers... 167: warning: passing arg 1 of `getenv' discards qualifiers from pointer..
OpenPOWER on IntegriCloud