diff options
author | John Johansen <john.johansen@canonical.com> | 2017-06-09 22:47:17 +0300 |
---|---|---|
committer | John Johansen <john.johansen@canonical.com> | 2017-06-11 03:11:39 +0300 |
commit | 76a1d263aba3c97db7a2ba673059e0f17d983efb (patch) | |
tree | 8197758c98e68f807248bd819361f7fe0e1a5688 /security/apparmor/procattr.c | |
parent | 637f688dc3dc304a89f441d76f49a0e35bc49c08 (diff) | |
download | linux-76a1d263aba3c97db7a2ba673059e0f17d983efb.tar.xz |
apparmor: switch getprocattr to using label_print fns()
Signed-off-by: John Johansen <john.johansen@canonical.com>
Diffstat (limited to 'security/apparmor/procattr.c')
-rw-r--r-- | security/apparmor/procattr.c | 60 |
1 files changed, 25 insertions, 35 deletions
diff --git a/security/apparmor/procattr.c b/security/apparmor/procattr.c index dce970d1f46b..d81617379d63 100644 --- a/security/apparmor/procattr.c +++ b/security/apparmor/procattr.c @@ -34,51 +34,41 @@ * * Returns: size of string placed in @string else error code on failure */ -int aa_getprocattr(struct aa_profile *profile, char **string) +int aa_getprocattr(struct aa_label *label, char **string) { - char *str; - int len = 0, mode_len = 0, ns_len = 0, name_len; - const char *mode_str = aa_profile_mode_names[profile->mode]; - const char *ns_name = NULL; - struct aa_ns *ns = profile->ns; + struct aa_ns *ns = labels_ns(label); struct aa_ns *current_ns = aa_get_current_ns(); - char *s; + int len; - if (!aa_ns_visible(current_ns, ns, true)) + if (!aa_ns_visible(current_ns, ns, true)) { + aa_put_ns(current_ns); return -EACCES; + } - ns_name = aa_ns_name(current_ns, ns, true); - ns_len = strlen(ns_name); - - /* if the visible ns_name is > 0 increase size for : :// seperator */ - if (ns_len) - ns_len += 4; - - /* unconfined profiles don't have a mode string appended */ - if (!profile_unconfined(profile)) - mode_len = strlen(mode_str) + 3; /* + 3 for _() */ + len = aa_label_snxprint(NULL, 0, current_ns, label, + FLAG_SHOW_MODE | FLAG_VIEW_SUBNS | + FLAG_HIDDEN_UNCONFINED); + AA_BUG(len < 0); - name_len = strlen(profile->base.hname); - len = mode_len + ns_len + name_len + 1; /* + 1 for \n */ - s = str = kmalloc(len + 1, GFP_KERNEL); /* + 1 \0 */ - if (!str) + *string = kmalloc(len + 2, GFP_KERNEL); + if (!*string) { + aa_put_ns(current_ns); return -ENOMEM; + } - if (ns_len) { - /* skip over prefix current_ns->base.hname and separating // */ - sprintf(s, ":%s://", ns_name); - s += ns_len; + len = aa_label_snxprint(*string, len + 2, current_ns, label, + FLAG_SHOW_MODE | FLAG_VIEW_SUBNS | + FLAG_HIDDEN_UNCONFINED); + if (len < 0) { + aa_put_ns(current_ns); + return len; } - if (profile_unconfined(profile)) - /* mode string not being appended */ - sprintf(s, "%s\n", profile->base.hname); - else - sprintf(s, "%s (%s)\n", profile->base.hname, mode_str); - *string = str; - aa_put_ns(current_ns); - /* NOTE: len does not include \0 of string, not saved as part of file */ - return len; + (*string)[len] = '\n'; + (*string)[len + 1] = 0; + + aa_put_ns(current_ns); + return len + 1; } /** |