diff options
author | rwatson <rwatson@FreeBSD.org> | 2003-06-23 01:26:34 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2003-06-23 01:26:34 +0000 |
commit | 80e2b7dc48234eba1ff0da80571d2c0354a353b9 (patch) | |
tree | 92d01b6fe3965640d61d19263fdb1f40b50d0183 /sys/security/mac_biba | |
parent | b205310e4310331bdb7215e20334462aef1a80c4 (diff) | |
download | FreeBSD-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_biba')
-rw-r--r-- | sys/security/mac_biba/mac_biba.c | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/sys/security/mac_biba/mac_biba.c b/sys/security/mac_biba/mac_biba.c index fa9d5e2..60575c0 100644 --- a/sys/security/mac_biba/mac_biba.c +++ b/sys/security/mac_biba/mac_biba.c @@ -576,57 +576,49 @@ mac_biba_element_to_string(struct sbuf *sb, struct mac_biba_element *element) } /* - * mac_biba_to_string() converts an Biba label to a string, placing the - * results in the passed string buffer. It returns 0 on success, - * or EINVAL if there isn't room in the buffer. The size of the - * string appended, leaving out the nul termination, is returned to - * the caller via *caller_len. Eventually, we should expose the - * sbuf to the caller rather than using C strings at this layer. + * mac_biba_to_string() converts a Biba label to a string, and places + * the results in the passed sbuf. It returns 0 on success, or EINVAL + * if there isn't room in the sbuf. Note: the sbuf will be modified + * even in a failure case, so the caller may need to revert the sbuf + * by restoring the offset if that's undesired. */ static int -mac_biba_to_string(char *string, size_t size, size_t *caller_len, - struct mac_biba *mac_biba) +mac_biba_to_string(struct sbuf *sb, struct mac_biba *mac_biba) { - struct sbuf sb; - - sbuf_new(&sb, string, size, SBUF_FIXEDLEN); if (mac_biba->mb_flags & MAC_BIBA_FLAG_SINGLE) { - if (mac_biba_element_to_string(&sb, &mac_biba->mb_single) + if (mac_biba_element_to_string(sb, &mac_biba->mb_single) == -1) return (EINVAL); } if (mac_biba->mb_flags & MAC_BIBA_FLAG_RANGE) { - if (sbuf_putc(&sb, '(') == -1) + if (sbuf_putc(sb, '(') == -1) return (EINVAL); - if (mac_biba_element_to_string(&sb, &mac_biba->mb_rangelow) + if (mac_biba_element_to_string(sb, &mac_biba->mb_rangelow) == -1) return (EINVAL); - if (sbuf_putc(&sb, '-') == -1) + if (sbuf_putc(sb, '-') == -1) return (EINVAL); - if (mac_biba_element_to_string(&sb, &mac_biba->mb_rangehigh) + if (mac_biba_element_to_string(sb, &mac_biba->mb_rangehigh) == -1) return (EINVAL); - if (sbuf_putc(&sb, ')') == -1) + if (sbuf_putc(sb, ')') == -1) return (EINVAL); } - sbuf_finish(&sb); - *caller_len = strlen(string); return (0); } static int mac_biba_externalize_label(struct label *label, char *element_name, - char *element_data, size_t size, size_t *len, int *claimed) + struct sbuf *sb, int *claimed) { struct mac_biba *mac_biba; - int error; if (strcmp(MAC_BIBA_LABEL_NAME, element_name) != 0) return (0); @@ -634,11 +626,7 @@ mac_biba_externalize_label(struct label *label, char *element_name, (*claimed)++; mac_biba = SLOT(label); - error = mac_biba_to_string(element_data, size, len, mac_biba); - if (error) - return (error); - - return (0); + return (mac_biba_to_string(sb, mac_biba)); } static int |