summaryrefslogtreecommitdiffstats
path: root/sys/security/mac/mac_pipe.c
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2003-06-23 01:26:34 +0000
committerrwatson <rwatson@FreeBSD.org>2003-06-23 01:26:34 +0000
commit80e2b7dc48234eba1ff0da80571d2c0354a353b9 (patch)
tree92d01b6fe3965640d61d19263fdb1f40b50d0183 /sys/security/mac/mac_pipe.c
parentb205310e4310331bdb7215e20334462aef1a80c4 (diff)
downloadFreeBSD-src-80e2b7dc48234eba1ff0da80571d2c0354a353b9.zip
FreeBSD-src-80e2b7dc48234eba1ff0da80571d2c0354a353b9.tar.gz
Redesign the externalization APIs from the MAC Framework to
the MAC policy modules to improve robustness against C string bugs and vulnerabilities. Following these revisions, all string construction of labels for export to userspace (or elsewhere) is performed using the sbuf API, which prevents the consumer from having to perform laborious and intricate pointer and buffer checks. This substantially simplifies the externalization logic, both at the MAC Framework level, and in individual policies; this becomes especially useful when policies export more complex label data, such as with compartments in Biba and MLS. Bundled in here are some other minor fixes associated with externalization: including avoiding malloc while holding the process mutex in mac_lomac, and hence avoid a failure mode when printing labels during a downgrade operation due to the removal of the M_NOWAIT case. This has been running in the MAC development tree for about three weeks without problems. Obtained from: TrustedBSD Project Sponsored by: DARPA, Network Associates Laboratories
Diffstat (limited to 'sys/security/mac/mac_pipe.c')
-rw-r--r--sys/security/mac/mac_pipe.c60
1 files changed, 20 insertions, 40 deletions
diff --git a/sys/security/mac/mac_pipe.c b/sys/security/mac/mac_pipe.c
index 79a12ec..0d6bf29 100644
--- a/sys/security/mac/mac_pipe.c
+++ b/sys/security/mac/mac_pipe.c
@@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$");
#include <sys/mac.h>
#include <sys/module.h>
#include <sys/proc.h>
+#include <sys/sbuf.h>
#include <sys/systm.h>
#include <sys/sysproto.h>
#include <sys/sysent.h>
@@ -398,65 +399,44 @@ mac_policy_list_unbusy(void)
#define MAC_EXTERNALIZE(type, label, elementlist, outbuf, \
outbuflen) do { \
- char *curptr, *curptr_start, *element_name, *element_temp; \
- size_t left, left_start, len; \
- int claimed, first, first_start, ignorenotfound; \
+ int claimed, first, ignorenotfound, savedlen; \
+ char *element_name, *element_temp; \
+ struct sbuf sb; \
\
error = 0; \
- element_temp = elementlist; \
- curptr = outbuf; \
- curptr[0] = '\0'; \
- left = outbuflen; \
first = 1; \
+ sbuf_new(&sb, outbuf, outbuflen, SBUF_FIXEDLEN); \
+ element_temp = elementlist; \
while ((element_name = strsep(&element_temp, ",")) != NULL) { \
- curptr_start = curptr; \
- left_start = left; \
- first_start = first; \
if (element_name[0] == '?') { \
element_name++; \
ignorenotfound = 1; \
- } else \
+ } else \
ignorenotfound = 0; \
- claimed = 0; \
+ savedlen = sbuf_len(&sb); \
if (first) { \
- len = snprintf(curptr, left, "%s/", \
- element_name); \
+ error = sbuf_printf(&sb, "%s/", element_name); \
first = 0; \
} else \
- len = snprintf(curptr, left, ",%s/", \
- element_name); \
- if (len >= left) { \
- error = EINVAL; /* XXXMAC: E2BIG */ \
+ error = sbuf_printf(&sb, ",%s/", element_name); \
+ if (error == -1) { \
+ error = EINVAL; /* XXX: E2BIG? */ \
break; \
} \
- curptr += len; \
- left -= len; \
- \
+ claimed = 0; \
MAC_CHECK(externalize_ ## type, label, element_name, \
- curptr, left, &len, &claimed); \
+ &sb, &claimed); \
if (error) \
break; \
- if (claimed == 1) { \
- if (len >= outbuflen) { \
- error = EINVAL; /* XXXMAC: E2BIG */ \
- break; \
- } \
- curptr += len; \
- left -= len; \
- } else if (claimed == 0 && ignorenotfound) { \
- /* \
- * Revert addition of the label element \
- * name. \
- */ \
- curptr = curptr_start; \
- *curptr = '\0'; \
- left = left_start; \
- first = first_start; \
- } else { \
- error = EINVAL; /* XXXMAC: ENOLABEL */ \
+ if (claimed == 0 && ignorenotfound) { \
+ /* Revert last label name. */ \
+ sbuf_setpos(&sb, savedlen); \
+ } else if (claimed != 1) { \
+ error = EINVAL; /* XXX: ENOLABEL? */ \
break; \
} \
} \
+ sbuf_finish(&sb); \
} while (0)
#define MAC_INTERNALIZE(type, label, instring) do { \
OpenPOWER on IntegriCloud