0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "include/apparmor.h"
0012 #include "include/cred.h"
0013 #include "include/policy.h"
0014 #include "include/policy_ns.h"
0015 #include "include/domain.h"
0016 #include "include/procattr.h"
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 int aa_getprocattr(struct aa_label *label, char **string)
0032 {
0033 struct aa_ns *ns = labels_ns(label);
0034 struct aa_ns *current_ns = aa_get_current_ns();
0035 int len;
0036
0037 if (!aa_ns_visible(current_ns, ns, true)) {
0038 aa_put_ns(current_ns);
0039 return -EACCES;
0040 }
0041
0042 len = aa_label_snxprint(NULL, 0, current_ns, label,
0043 FLAG_SHOW_MODE | FLAG_VIEW_SUBNS |
0044 FLAG_HIDDEN_UNCONFINED);
0045 AA_BUG(len < 0);
0046
0047 *string = kmalloc(len + 2, GFP_KERNEL);
0048 if (!*string) {
0049 aa_put_ns(current_ns);
0050 return -ENOMEM;
0051 }
0052
0053 len = aa_label_snxprint(*string, len + 2, current_ns, label,
0054 FLAG_SHOW_MODE | FLAG_VIEW_SUBNS |
0055 FLAG_HIDDEN_UNCONFINED);
0056 if (len < 0) {
0057 aa_put_ns(current_ns);
0058 return len;
0059 }
0060
0061 (*string)[len] = '\n';
0062 (*string)[len + 1] = 0;
0063
0064 aa_put_ns(current_ns);
0065 return len + 1;
0066 }
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 static char *split_token_from_name(const char *op, char *args, u64 *token)
0077 {
0078 char *name;
0079
0080 *token = simple_strtoull(args, &name, 16);
0081 if ((name == args) || *name != '^') {
0082 AA_ERROR("%s: Invalid input '%s'", op, args);
0083 return ERR_PTR(-EINVAL);
0084 }
0085
0086 name++;
0087 if (!*name)
0088 name = NULL;
0089 return name;
0090 }
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100 int aa_setprocattr_changehat(char *args, size_t size, int flags)
0101 {
0102 char *hat;
0103 u64 token;
0104 const char *hats[16];
0105 int count = 0;
0106
0107 hat = split_token_from_name(OP_CHANGE_HAT, args, &token);
0108 if (IS_ERR(hat))
0109 return PTR_ERR(hat);
0110
0111 if (!hat && !token) {
0112 AA_ERROR("change_hat: Invalid input, NULL hat and NULL magic");
0113 return -EINVAL;
0114 }
0115
0116 if (hat) {
0117
0118
0119
0120
0121
0122
0123 char *end = args + size;
0124 for (count = 0; (hat < end) && count < 16; ++count) {
0125 char *next = hat + strlen(hat) + 1;
0126 hats[count] = hat;
0127 AA_DEBUG("%s: (pid %d) Magic 0x%llx count %d hat '%s'\n"
0128 , __func__, current->pid, token, count, hat);
0129 hat = next;
0130 }
0131 } else
0132 AA_DEBUG("%s: (pid %d) Magic 0x%llx count %d Hat '%s'\n",
0133 __func__, current->pid, token, count, "<NULL>");
0134
0135 return aa_change_hat(hats, count, token, flags);
0136 }