Commit graph

28 commits

Author SHA1 Message Date
Mark Johnston dfabf3efaa libjail: Guard against programmer error in jailparam_export()
If the caller didn't use jailparam_import() to fetch the parameter
value, an attempt to export it will trigger a segfault.  Make it a bit
easier to figure out what's happening in this situation.

PR:		276809
Reviewed by:	jamie
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43732
2024-02-04 17:52:30 -05:00
Warner Losh a2f733abcf lib: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:23:59 -07:00
Warner Losh 1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh 4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Mark Johnston accd6aa25e libjail: Handle an error from reallocarray() when trimming the buffer.
There is no API guarantee that realloc() will not fail when the buffer
is shrinking.  Handle it by simply returning the untrimmed buffer.
While this is unlikely to ever happen in practice, it seems worth
handling just to silence static analyzer warnings.

PR:		243106
Submitted by:	Hans Christian Woithe <chwoithe@yahoo.com>
MFC after:	1 week
2020-01-07 21:44:27 +00:00
Devin Teske 6ab631e856 `libjail/jail.c' includes both <sys/param.h> and <sys/types.h>
Latter is undesired when including <sys/param.h> according to style(9)

Submitted by:	Faraz Vahedi
Reviewed by:	cem
Differential Revision:	https://reviews.freebsd.org/D20637
2019-06-22 15:39:34 +00:00
Alan Somers 123af6ec70 Rename fuse(4) to fusefs(4)
This makes it more consistent with other filesystems, which all end in "fs",
and more consistent with its mount helper, which is already named
"mount_fusefs".

Reviewed by:	cem, rgrimes
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D19649
2019-03-20 21:48:43 +00:00
Alan Somers 98f8234b13 libjail: fix handling of allow.mount.fusefs in jailparam_init
fusefs is inconsistently named. The kernel module is named "fuse", but the
mount helper is named "mount_fusefs" and the jail(8) parameter is named
"allow.mount.fusefs". Special case it in libjail.

Reviewed by:	jamie
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D17929
2018-11-10 03:10:22 +00:00
Jamie Gritton 0e5c6bd436 Make it easier for filesystems to count themselves as jail-enabled,
by doing most of the work in a new function prison_add_vfs in kern_jail.c
Now a jail-enabled filesystem need only mark itself with VFCF_JAIL, and
the rest is taken care of.  This includes adding a jail parameter like
allow.mount.foofs, and a sysctl like security.jail.mount_foofs_allowed.
Both of these used to be a static list of known filesystems, with
predefined permission bits.

Reviewed by:	kib
Differential Revision:	D14681
2018-05-04 20:54:27 +00:00
Jamie Gritton f047b92153 If a jail parameter isn't found, try loading a related kernel module. 2018-03-21 23:50:46 +00:00
Pedro F. Giffuni 5e53a4f90f lib: further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using mis-identified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.
2017-11-26 02:00:33 +00:00
Pedro F. Giffuni 6fd94039ef libjail: make allocation in jailparam_all() somewhat more robust.
Unsign some variables involved in allocation as they will never be
negative anyways. Provide some bounds checking through reallocarray(3).

This is all very unlikely to have any visible effect.

Reviewed by:	jamie
MFC after:	3 weeks
2017-04-16 19:23:10 +00:00
Ruslan Bukin e5edb77987 Fix libjail reached latest sysctl entry.
Reviewed by:	jamie
Sponsored by:	DARPA, AFRL
Sponsored by:	HEIF5
Differential Revision:	https://reviews.freebsd.org/D8096
2016-10-02 11:56:17 +00:00
Jamie Gritton d031802b05 In preparation for using clang's -Wcast-qual:
Use __DECONST (instead of my own attempted re-invention) for the iov
parameters to jail_get/set(2).  Similarly remove the decost-ish hack
from execvp's argv, except the __DECONST is only added at very end.

While I'm at it, remove an unused variable and fix a comment typo.
2014-11-25 21:01:08 +00:00
Jamie Gritton 49f903d5fc Fix some memory allocation errors:
* jail_setv will leak a parameter name if jailparam_import fails.
* jailparam_all loses the jailparam pointer on realloc error
  (a clear freshman mistake).
* If jailparam_init fails, the caller doesn't need to jailparam_free
  the buffer.  That's not really clear, so set things to NULL allowing
  jailparam_free to work without error (though it's still not required).
2012-10-04 19:07:05 +00:00
Jamie Gritton cee9d6cc1d The fix in r235291 re-broke the "allow.nomount" case. Re-fix it
by testing for the right parameter name.
2012-05-22 18:30:32 +00:00
Jamie Gritton fb8d1d4f19 The linker isn't consistent in the ordering of dynamic sysctls, so don't
assume that the unnamed final component of "security.jail.param.foo." is
one less than the "foo" component.  It might be one greater instead.
2012-05-11 21:22:52 +00:00
Jamie Gritton 699f40077b Handle the case where a boolean parameter is also a node.
PR:		bin/165515
MFC after:	2 weeks
2012-03-01 15:09:41 +00:00
Matthew D Fleming cbc134ad03 Introduce signed and unsigned version of CTLTYPE_QUAD, renaming
existing uses.  Rename sysctl_handle_quad() to sysctl_handle_64().
2011-01-19 23:00:25 +00:00
Jamie Gritton b81422ef7f Find a jail's type as part of jailparam_init rather than waiting until
it's absolutely necessary.

MFC after:	1 week
2010-10-27 21:01:53 +00:00
Jamie Gritton 881f6af44b Whitespace and comment fixes.
MFC after:	3 days
2010-08-31 23:14:03 +00:00
Jamie Gritton 4d02a3e762 Don't over-allocate array values in jailparam_export.
Fix a little comment typo.

MFC after:	3 days
2010-08-31 21:50:09 +00:00
Jamie Gritton c26c472cc8 Don't import parameter values in jail_getv, except for the search key.
Remove the internal jailparam_vlist, in favor of using variants of its
 logic separately in jail_setv and jail_getv.
Free the temporary parameter list and exported values in jail_setv
 and jail_getv.

Noted by:	Stanislav Uzunchev
MFC after:	3 days
2010-07-15 19:21:07 +00:00
Ruslan Ermilov f2ee2e68d2 realloc() with a proper amount of memory.
MFC after:	3 days
2010-02-17 16:45:03 +00:00
Jamie Gritton 1574e5ddd9 Add a null pointer check so "name" can be used as a key parameter in
jailparam_get.

PR:		bin/141692
Submitted by:	delphij
MFC after:	3 days
2009-12-17 05:06:56 +00:00
Jamie Gritton 7cbf72137f Some jail parameters (in particular, "ip4" and "ip6" for IP address
restrictions) were found to be inadequately described by a boolean.
Define a new parameter type with three values (disable, new, inherit)
to handle these and future cases.

Approved by:	re (kib), bz (mentor)
Discussed with:	rwatson
2009-07-25 14:48:57 +00:00
Jamie Gritton 69ea521eba Fix dynamic (re)allocation logic in jailparam_set and jailparam_get.
Touch up jailparam_import a bit while I'm at it.

Approved by:	bz (mentor)
2009-06-25 22:42:19 +00:00
Jamie Gritton de6f37045c Add libjail, a (somewhat) simpler interface to the jail_set and jail_get
system calls and the security.jail.param sysctls.

Approved by:	bz (mentor)
2009-06-24 18:18:35 +00:00