diff options
author | Lukasz Pawelczyk <l.pawelczyk@samsung.com> | 2014-08-29 11:02:55 -0400 |
---|---|---|
committer | Casey Schaufler <casey@schaufler-ca.com> | 2014-08-29 13:10:55 -0400 |
commit | 21c7eae21a2100a89cfb8cebaf7b770271f32c6e (patch) | |
tree | 9747fd04fb0a18e98c31985c978ae559f7affc0b /security/smack/smackfs.c | |
parent | d01757904d9deb619e23c9450218829943a46822 (diff) |
Make Smack operate on smack_known struct where it still used char*
Smack used to use a mix of smack_known struct and char* throughout its
APIs and implementation. This patch unifies the behaviour and makes it
store and operate exclusively on smack_known struct pointers when managing
labels.
Signed-off-by: Lukasz Pawelczyk <l.pawelczyk@samsung.com>
Conflicts:
security/smack/smack_access.c
security/smack/smack_lsm.c
Diffstat (limited to 'security/smack/smackfs.c')
-rw-r--r-- | security/smack/smackfs.c | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c index 49a2248b525c..bce4e8f1b267 100644 --- a/security/smack/smackfs.c +++ b/security/smack/smackfs.c | |||
@@ -131,14 +131,17 @@ LIST_HEAD(smack_rule_list); | |||
131 | 131 | ||
132 | struct smack_parsed_rule { | 132 | struct smack_parsed_rule { |
133 | struct smack_known *smk_subject; | 133 | struct smack_known *smk_subject; |
134 | char *smk_object; | 134 | struct smack_known *smk_object; |
135 | int smk_access1; | 135 | int smk_access1; |
136 | int smk_access2; | 136 | int smk_access2; |
137 | }; | 137 | }; |
138 | 138 | ||
139 | static int smk_cipso_doi_value = SMACK_CIPSO_DOI_DEFAULT; | 139 | static int smk_cipso_doi_value = SMACK_CIPSO_DOI_DEFAULT; |
140 | 140 | ||
141 | const char *smack_cipso_option = SMACK_CIPSO_OPTION; | 141 | struct smack_known smack_cipso_option = { |
142 | .smk_known = SMACK_CIPSO_OPTION, | ||
143 | .smk_secid = 0, | ||
144 | }; | ||
142 | 145 | ||
143 | /* | 146 | /* |
144 | * Values for parsing cipso rules | 147 | * Values for parsing cipso rules |
@@ -339,7 +342,7 @@ static int smk_fill_rule(const char *subject, const char *object, | |||
339 | if (rule->smk_subject == NULL) | 342 | if (rule->smk_subject == NULL) |
340 | return -EINVAL; | 343 | return -EINVAL; |
341 | 344 | ||
342 | rule->smk_object = smk_import(object, len); | 345 | rule->smk_object = smk_import_entry(object, len); |
343 | if (rule->smk_object == NULL) | 346 | if (rule->smk_object == NULL) |
344 | return -EINVAL; | 347 | return -EINVAL; |
345 | } else { | 348 | } else { |
@@ -359,7 +362,7 @@ static int smk_fill_rule(const char *subject, const char *object, | |||
359 | kfree(cp); | 362 | kfree(cp); |
360 | if (skp == NULL) | 363 | if (skp == NULL) |
361 | return -ENOENT; | 364 | return -ENOENT; |
362 | rule->smk_object = skp->smk_known; | 365 | rule->smk_object = skp; |
363 | } | 366 | } |
364 | 367 | ||
365 | rule->smk_access1 = smk_perm_from_str(access1); | 368 | rule->smk_access1 = smk_perm_from_str(access1); |
@@ -598,13 +601,15 @@ static void smk_rule_show(struct seq_file *s, struct smack_rule *srp, int max) | |||
598 | * anything you read back. | 601 | * anything you read back. |
599 | */ | 602 | */ |
600 | if (strlen(srp->smk_subject->smk_known) >= max || | 603 | if (strlen(srp->smk_subject->smk_known) >= max || |
601 | strlen(srp->smk_object) >= max) | 604 | strlen(srp->smk_object->smk_known) >= max) |
602 | return; | 605 | return; |
603 | 606 | ||
604 | if (srp->smk_access == 0) | 607 | if (srp->smk_access == 0) |
605 | return; | 608 | return; |
606 | 609 | ||
607 | seq_printf(s, "%s %s", srp->smk_subject->smk_known, srp->smk_object); | 610 | seq_printf(s, "%s %s", |
611 | srp->smk_subject->smk_known, | ||
612 | srp->smk_object->smk_known); | ||
608 | 613 | ||
609 | seq_putc(s, ' '); | 614 | seq_putc(s, ' '); |
610 | 615 | ||
@@ -1073,7 +1078,7 @@ static int netlbladdr_seq_show(struct seq_file *s, void *v) | |||
1073 | for (maskn = 0; temp_mask; temp_mask <<= 1, maskn++); | 1078 | for (maskn = 0; temp_mask; temp_mask <<= 1, maskn++); |
1074 | 1079 | ||
1075 | seq_printf(s, "%u.%u.%u.%u/%d %s\n", | 1080 | seq_printf(s, "%u.%u.%u.%u/%d %s\n", |
1076 | hp[0], hp[1], hp[2], hp[3], maskn, skp->smk_label); | 1081 | hp[0], hp[1], hp[2], hp[3], maskn, skp->smk_label->smk_known); |
1077 | 1082 | ||
1078 | return 0; | 1083 | return 0; |
1079 | } | 1084 | } |
@@ -1153,10 +1158,10 @@ static void smk_netlbladdr_insert(struct smk_netlbladdr *new) | |||
1153 | static ssize_t smk_write_netlbladdr(struct file *file, const char __user *buf, | 1158 | static ssize_t smk_write_netlbladdr(struct file *file, const char __user *buf, |
1154 | size_t count, loff_t *ppos) | 1159 | size_t count, loff_t *ppos) |
1155 | { | 1160 | { |
1156 | struct smk_netlbladdr *skp; | 1161 | struct smk_netlbladdr *snp; |
1157 | struct sockaddr_in newname; | 1162 | struct sockaddr_in newname; |
1158 | char *smack; | 1163 | char *smack; |
1159 | char *sp; | 1164 | struct smack_known *skp; |
1160 | char *data; | 1165 | char *data; |
1161 | char *host = (char *)&newname.sin_addr.s_addr; | 1166 | char *host = (char *)&newname.sin_addr.s_addr; |
1162 | int rc; | 1167 | int rc; |
@@ -1219,15 +1224,15 @@ static ssize_t smk_write_netlbladdr(struct file *file, const char __user *buf, | |||
1219 | * If smack begins with '-', it is an option, don't import it | 1224 | * If smack begins with '-', it is an option, don't import it |
1220 | */ | 1225 | */ |
1221 | if (smack[0] != '-') { | 1226 | if (smack[0] != '-') { |
1222 | sp = smk_import(smack, 0); | 1227 | skp = smk_import_entry(smack, 0); |
1223 | if (sp == NULL) { | 1228 | if (skp == NULL) { |
1224 | rc = -EINVAL; | 1229 | rc = -EINVAL; |
1225 | goto free_out; | 1230 | goto free_out; |
1226 | } | 1231 | } |
1227 | } else { | 1232 | } else { |
1228 | /* check known options */ | 1233 | /* check known options */ |
1229 | if (strcmp(smack, smack_cipso_option) == 0) | 1234 | if (strcmp(smack, smack_cipso_option.smk_known) == 0) |
1230 | sp = (char *)smack_cipso_option; | 1235 | skp = &smack_cipso_option; |
1231 | else { | 1236 | else { |
1232 | rc = -EINVAL; | 1237 | rc = -EINVAL; |
1233 | goto free_out; | 1238 | goto free_out; |
@@ -1250,9 +1255,9 @@ static ssize_t smk_write_netlbladdr(struct file *file, const char __user *buf, | |||
1250 | nsa = newname.sin_addr.s_addr; | 1255 | nsa = newname.sin_addr.s_addr; |
1251 | /* try to find if the prefix is already in the list */ | 1256 | /* try to find if the prefix is already in the list */ |
1252 | found = 0; | 1257 | found = 0; |
1253 | list_for_each_entry_rcu(skp, &smk_netlbladdr_list, list) { | 1258 | list_for_each_entry_rcu(snp, &smk_netlbladdr_list, list) { |
1254 | if (skp->smk_host.sin_addr.s_addr == nsa && | 1259 | if (snp->smk_host.sin_addr.s_addr == nsa && |
1255 | skp->smk_mask.s_addr == mask.s_addr) { | 1260 | snp->smk_mask.s_addr == mask.s_addr) { |
1256 | found = 1; | 1261 | found = 1; |
1257 | break; | 1262 | break; |
1258 | } | 1263 | } |
@@ -1260,26 +1265,26 @@ static ssize_t smk_write_netlbladdr(struct file *file, const char __user *buf, | |||
1260 | smk_netlabel_audit_set(&audit_info); | 1265 | smk_netlabel_audit_set(&audit_info); |
1261 | 1266 | ||
1262 | if (found == 0) { | 1267 | if (found == 0) { |
1263 | skp = kzalloc(sizeof(*skp), GFP_KERNEL); | 1268 | snp = kzalloc(sizeof(*snp), GFP_KERNEL); |
1264 | if (skp == NULL) | 1269 | if (snp == NULL) |
1265 | rc = -ENOMEM; | 1270 | rc = -ENOMEM; |
1266 | else { | 1271 | else { |
1267 | rc = 0; | 1272 | rc = 0; |
1268 | skp->smk_host.sin_addr.s_addr = newname.sin_addr.s_addr; | 1273 | snp->smk_host.sin_addr.s_addr = newname.sin_addr.s_addr; |
1269 | skp->smk_mask.s_addr = mask.s_addr; | 1274 | snp->smk_mask.s_addr = mask.s_addr; |
1270 | skp->smk_label = sp; | 1275 | snp->smk_label = skp; |
1271 | smk_netlbladdr_insert(skp); | 1276 | smk_netlbladdr_insert(snp); |
1272 | } | 1277 | } |
1273 | } else { | 1278 | } else { |
1274 | /* we delete the unlabeled entry, only if the previous label | 1279 | /* we delete the unlabeled entry, only if the previous label |
1275 | * wasn't the special CIPSO option */ | 1280 | * wasn't the special CIPSO option */ |
1276 | if (skp->smk_label != smack_cipso_option) | 1281 | if (snp->smk_label != &smack_cipso_option) |
1277 | rc = netlbl_cfg_unlbl_static_del(&init_net, NULL, | 1282 | rc = netlbl_cfg_unlbl_static_del(&init_net, NULL, |
1278 | &skp->smk_host.sin_addr, &skp->smk_mask, | 1283 | &snp->smk_host.sin_addr, &snp->smk_mask, |
1279 | PF_INET, &audit_info); | 1284 | PF_INET, &audit_info); |
1280 | else | 1285 | else |
1281 | rc = 0; | 1286 | rc = 0; |
1282 | skp->smk_label = sp; | 1287 | snp->smk_label = skp; |
1283 | } | 1288 | } |
1284 | 1289 | ||
1285 | /* | 1290 | /* |
@@ -1287,10 +1292,10 @@ static ssize_t smk_write_netlbladdr(struct file *file, const char __user *buf, | |||
1287 | * this host so that incoming packets get labeled. | 1292 | * this host so that incoming packets get labeled. |
1288 | * but only if we didn't get the special CIPSO option | 1293 | * but only if we didn't get the special CIPSO option |
1289 | */ | 1294 | */ |
1290 | if (rc == 0 && sp != smack_cipso_option) | 1295 | if (rc == 0 && skp != &smack_cipso_option) |
1291 | rc = netlbl_cfg_unlbl_static_add(&init_net, NULL, | 1296 | rc = netlbl_cfg_unlbl_static_add(&init_net, NULL, |
1292 | &skp->smk_host.sin_addr, &skp->smk_mask, PF_INET, | 1297 | &snp->smk_host.sin_addr, &snp->smk_mask, PF_INET, |
1293 | smack_to_secid(skp->smk_label), &audit_info); | 1298 | snp->smk_label->smk_secid, &audit_info); |
1294 | 1299 | ||
1295 | if (rc == 0) | 1300 | if (rc == 0) |
1296 | rc = count; | 1301 | rc = count; |