Lines Matching +full:label +full:- +full:revision
1 // SPDX-License-Identifier: GPL-2.0-only
7 * Copyright (C) 1998-2008 Novell/SUSE
8 * Copyright 2009-2010 Canonical Ltd.
34 #include "include/label.h"
82 aa_put_loaddata(private->loaddata); in rawdata_f_data_free()
90 if (size > SIZE_MAX - sizeof(*ret)) in rawdata_f_data_alloc()
91 return ERR_PTR(-EINVAL); in rawdata_f_data_alloc()
95 return ERR_PTR(-ENOMEM); in rawdata_f_data_alloc()
102 * mangle_name - mangle a profile name to std profile layout form
121 else if (isalnum(*name) || strchr("._-", *name)) in mangle_name()
130 strchr("/._-", *name)) in mangle_name()
137 return t - target; in mangle_name()
142 * aafs - core fns and data for the policy tree
152 seq_printf(seq, "%s:[%lu]", AAFS_NAME, d_inode(dentry)->i_ino); in aafs_show_path()
158 if (S_ISLNK(inode->i_mode)) in aafs_free_inode()
159 kfree(inode->i_link); in aafs_free_inode()
177 sb->s_op = &aafs_super_ops; in apparmorfs_fill_super()
193 fc->ops = &apparmorfs_context_ops; in apparmorfs_init_fs_context()
205 * __aafs_setup_d_inode - basic inode setup for apparmorfs
219 struct inode *inode = new_inode(dir->i_sb); in __aafs_setup_d_inode()
225 return -ENOMEM; in __aafs_setup_d_inode()
227 inode->i_ino = get_next_ino(); in __aafs_setup_d_inode()
228 inode->i_mode = mode; in __aafs_setup_d_inode()
229 inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode); in __aafs_setup_d_inode()
230 inode->i_private = data; in __aafs_setup_d_inode()
232 inode->i_op = iops ? iops : &simple_dir_inode_operations; in __aafs_setup_d_inode()
233 inode->i_fop = &simple_dir_operations; in __aafs_setup_d_inode()
237 inode->i_op = iops ? iops : &simple_symlink_inode_operations; in __aafs_setup_d_inode()
238 inode->i_link = link; in __aafs_setup_d_inode()
240 inode->i_fop = fops; in __aafs_setup_d_inode()
249 * aafs_create - create a dentry in the apparmorfs filesystem
293 error = -EEXIST; in aafs_create()
315 * aafs_create_file - create a file in the apparmorfs filesystem
333 * aafs_create_dir - create a directory in the apparmorfs filesystem
347 * aafs_remove - removes a file or directory from the apparmorfs filesystem
358 dir = d_inode(dentry->d_parent); in aafs_remove()
374 * aa_fs - policy load/replace/remove
378 * aa_simple_write_to_buffer - common routine for getting policy from user
398 return ERR_PTR(-ESPIPE); in aa_simple_write_to_buffer()
405 data->size = copy_size; in aa_simple_write_to_buffer()
406 if (copy_from_user(data->data, userbuf, copy_size)) { in aa_simple_write_to_buffer()
408 return ERR_PTR(-EFAULT); in aa_simple_write_to_buffer()
418 struct aa_label *label; in policy_update() local
421 label = begin_current_label_crit_section(); in policy_update()
423 /* high level check about policy management - fine grained in in policy_update()
426 error = aa_may_manage_policy(current_cred(), label, ns, mask); in policy_update()
433 error = aa_replace_profiles(ns, label, mask, data); in policy_update()
437 end_current_label_crit_section(label); in policy_update()
446 struct aa_ns *ns = aa_get_ns(f->f_inode->i_private); in profile_load()
463 struct aa_ns *ns = aa_get_ns(f->f_inode->i_private); in profile_replace()
481 struct aa_label *label; in profile_remove() local
483 struct aa_ns *ns = aa_get_ns(f->f_inode->i_private); in profile_remove()
485 label = begin_current_label_crit_section(); in profile_remove()
486 /* high level check about policy management - fine grained in in profile_remove()
489 error = aa_may_manage_policy(current_cred(), label, ns, in profile_remove()
502 data->data[size] = 0; in profile_remove()
503 error = aa_remove_profiles(ns, label, data->data, size); in profile_remove()
507 end_current_label_crit_section(label); in profile_remove()
522 /* revision file hook fn for policy loads */
525 struct aa_revision *rev = file->private_data; in ns_revision_release()
528 aa_put_ns(rev->ns); in ns_revision_release()
538 struct aa_revision *rev = file->private_data; in ns_revision_read()
543 mutex_lock_nested(&rev->ns->lock, rev->ns->level); in ns_revision_read()
544 last_read = rev->last_read; in ns_revision_read()
545 if (last_read == rev->ns->revision) { in ns_revision_read()
546 mutex_unlock(&rev->ns->lock); in ns_revision_read()
547 if (file->f_flags & O_NONBLOCK) in ns_revision_read()
548 return -EAGAIN; in ns_revision_read()
549 if (wait_event_interruptible(rev->ns->wait, in ns_revision_read()
551 READ_ONCE(rev->ns->revision))) in ns_revision_read()
552 return -ERESTARTSYS; in ns_revision_read()
553 mutex_lock_nested(&rev->ns->lock, rev->ns->level); in ns_revision_read()
556 avail = sprintf(buffer, "%ld\n", rev->ns->revision); in ns_revision_read()
558 rev->last_read = rev->ns->revision; in ns_revision_read()
561 mutex_unlock(&rev->ns->lock); in ns_revision_read()
571 return -ENOMEM; in ns_revision_open()
573 rev->ns = aa_get_ns(inode->i_private); in ns_revision_open()
574 if (!rev->ns) in ns_revision_open()
575 rev->ns = aa_get_current_ns(); in ns_revision_open()
576 file->private_data = rev; in ns_revision_open()
583 struct aa_revision *rev = file->private_data; in ns_revision_poll()
587 mutex_lock_nested(&rev->ns->lock, rev->ns->level); in ns_revision_poll()
588 poll_wait(file, &rev->ns->wait, pt); in ns_revision_poll()
589 if (rev->last_read < rev->ns->revision) in ns_revision_poll()
591 mutex_unlock(&rev->ns->lock); in ns_revision_poll()
599 WRITE_ONCE(ns->revision, READ_ONCE(ns->revision) + 1); in __aa_bump_ns_revision()
600 wake_up_interruptible(&ns->wait); in __aa_bump_ns_revision()
615 struct aa_ruleset *rules = list_first_entry(&profile->rules, in profile_query_cb()
622 if (rules->file.dfa && *match_str == AA_CLASS_FILE) { in profile_query_cb()
623 state = aa_dfa_match_len(rules->file.dfa, in profile_query_cb()
624 rules->file.start[AA_CLASS_FILE], in profile_query_cb()
625 match_str + 1, match_len - 1); in profile_query_cb()
629 tmp = *(aa_lookup_fperms(&(rules->file), state, &cond)); in profile_query_cb()
631 } else if (rules->policy.dfa) { in profile_query_cb()
634 state = aa_dfa_match_len(rules->policy.dfa, in profile_query_cb()
635 rules->policy.start[0], in profile_query_cb()
638 tmp = *aa_lookup_perms(&rules->policy, state); in profile_query_cb()
646 * query_data - queries a policy and writes its data to buf
655 * The query should look like "<LABEL>\0<KEY>\0", where <LABEL> is the name of
657 * retrieve. <LABEL> and <KEY> must not be NUL-terminated.
661 * Returns: number of characters written to buf or -errno on failure
669 struct aa_label *label, *curr; in query_data() local
676 return -EINVAL; /* need a query */ in query_data()
680 return -EINVAL; /* not enough space for a non-empty key */ in query_data()
681 if (key + strnlen(key, query + query_len - key) >= query + query_len) in query_data()
682 return -EINVAL; /* must end with NUL */ in query_data()
685 return -EINVAL; /* not enough space */ in query_data()
688 label = aa_label_parse(curr, query, GFP_KERNEL, false, false); in query_data()
690 if (IS_ERR(label)) in query_data()
691 return PTR_ERR(label); in query_data()
705 label_for_each_confined(i, label, profile) { in query_data()
706 if (!profile->data) in query_data()
709 data = rhashtable_lookup_fast(profile->data, &key, in query_data()
710 profile->data->p); in query_data()
713 if (out + sizeof(outle32) + data->size > buf + in query_data()
715 aa_put_label(label); in query_data()
716 return -EINVAL; /* not enough space */ in query_data()
718 outle32 = __cpu_to_le32(data->size); in query_data()
721 memcpy(out, data->data, data->size); in query_data()
722 out += data->size; in query_data()
726 aa_put_label(label); in query_data()
728 outle32 = __cpu_to_le32(out - buf - sizeof(bytes)); in query_data()
733 return out - buf; in query_data()
737 * query_label - queries a label and writes permissions to buf
748 * the name of the label, in the current namespace, that is to be queried and
749 * DFA_STRING is a binary string to match against the label(s)'s DFA.
754 * Returns: number of characters written to buf or -errno on failure
760 struct aa_label *label, *curr; in query_label() local
767 return -EINVAL; in query_label()
772 return -EINVAL; in query_label()
781 match_len = query_len - label_name_len - 1; in query_label()
784 label = aa_label_parse(curr, label_name, GFP_KERNEL, false, false); in query_label()
786 if (IS_ERR(label)) in query_label()
787 return PTR_ERR(label); in query_label()
791 label_for_each_in_ns(i, labels_ns(label), label, profile) { in query_label()
795 label_for_each(i, label, profile) { in query_label()
799 aa_put_label(label); in query_label()
809 * possibly a read(s) which collects the result - which is stored in a
810 * file-local buffer. Once a new write is performed, a new set of results
811 * are stored in the file-local buffer.
819 #define MULTI_TRANSACTION_LIMIT (PAGE_SIZE - sizeof(struct multi_transaction))
833 kref_get(&(t->count)); in get_multi_transaction()
841 kref_put(&(t->count), multi_transaction_kref); in put_multi_transaction()
852 new->size = n; in multi_transaction_set()
853 spin_lock(&file->f_lock); in multi_transaction_set()
854 old = (struct multi_transaction *) file->private_data; in multi_transaction_set()
855 file->private_data = new; in multi_transaction_set()
856 spin_unlock(&file->f_lock); in multi_transaction_set()
866 if (size > MULTI_TRANSACTION_LIMIT - 1) in multi_transaction_new()
867 return ERR_PTR(-EFBIG); in multi_transaction_new()
871 return ERR_PTR(-ENOMEM); in multi_transaction_new()
872 kref_init(&t->count); in multi_transaction_new()
873 if (copy_from_user(t->data, buf, size)) { in multi_transaction_new()
875 return ERR_PTR(-EFAULT); in multi_transaction_new()
887 spin_lock(&file->f_lock); in multi_transaction_read()
888 t = get_multi_transaction(file->private_data); in multi_transaction_read()
889 spin_unlock(&file->f_lock); in multi_transaction_read()
894 ret = simple_read_from_buffer(buf, size, pos, t->data, t->size); in multi_transaction_read()
902 put_multi_transaction(file->private_data); in multi_transaction_release()
907 #define QUERY_CMD_LABEL "label\0"
917 * aa_write_access - generic permissions and data query
924 * sequence. The only queries currently supported are label-based queries for
927 * For permissions queries, ubuf must begin with "label\0", followed by the
931 * For data queries, ubuf must have the form "data\0<LABEL>\0<KEY>\0", where
932 * <LABEL> is the name of the security confinement context and <KEY> is the
935 * Returns: number of bytes written or -errno on failure
944 return -ESPIPE; in aa_write_access()
951 !memcmp(t->data, QUERY_CMD_PROFILE, QUERY_CMD_PROFILE_LEN)) { in aa_write_access()
952 len = query_label(t->data, MULTI_TRANSACTION_LIMIT, in aa_write_access()
953 t->data + QUERY_CMD_PROFILE_LEN, in aa_write_access()
954 count - QUERY_CMD_PROFILE_LEN, true); in aa_write_access()
956 !memcmp(t->data, QUERY_CMD_LABEL, QUERY_CMD_LABEL_LEN)) { in aa_write_access()
957 len = query_label(t->data, MULTI_TRANSACTION_LIMIT, in aa_write_access()
958 t->data + QUERY_CMD_LABEL_LEN, in aa_write_access()
959 count - QUERY_CMD_LABEL_LEN, true); in aa_write_access()
961 !memcmp(t->data, QUERY_CMD_LABELALL, in aa_write_access()
963 len = query_label(t->data, MULTI_TRANSACTION_LIMIT, in aa_write_access()
964 t->data + QUERY_CMD_LABELALL_LEN, in aa_write_access()
965 count - QUERY_CMD_LABELALL_LEN, false); in aa_write_access()
967 !memcmp(t->data, QUERY_CMD_DATA, QUERY_CMD_DATA_LEN)) { in aa_write_access()
968 len = query_data(t->data, MULTI_TRANSACTION_LIMIT, in aa_write_access()
969 t->data + QUERY_CMD_DATA_LEN, in aa_write_access()
970 count - QUERY_CMD_DATA_LEN); in aa_write_access()
972 len = -EINVAL; in aa_write_access()
993 struct aa_sfs_entry *fs_file = seq->private; in aa_sfs_seq_show()
998 switch (fs_file->v_type) { in aa_sfs_seq_show()
1000 seq_printf(seq, "%s\n", fs_file->v.boolean ? "yes" : "no"); in aa_sfs_seq_show()
1003 seq_printf(seq, "%s\n", fs_file->v.string); in aa_sfs_seq_show()
1006 seq_printf(seq, "%#08lx\n", fs_file->v.u64); in aa_sfs_seq_show()
1018 return single_open(file, aa_sfs_seq_show, inode->i_private); in aa_sfs_seq_open()
1051 struct aa_proxy *proxy = aa_get_proxy(inode->i_private); in seq_profile_open()
1055 file->private_data = NULL; in seq_profile_open()
1064 struct seq_file *seq = (struct seq_file *) file->private_data; in seq_profile_release()
1066 aa_put_proxy(seq->private); in seq_profile_release()
1072 struct aa_proxy *proxy = seq->private; in seq_profile_name_show()
1073 struct aa_label *label = aa_get_label_rcu(&proxy->label); in seq_profile_name_show() local
1074 struct aa_profile *profile = labels_profile(label); in seq_profile_name_show()
1075 seq_printf(seq, "%s\n", profile->base.name); in seq_profile_name_show()
1076 aa_put_label(label); in seq_profile_name_show()
1083 struct aa_proxy *proxy = seq->private; in seq_profile_mode_show()
1084 struct aa_label *label = aa_get_label_rcu(&proxy->label); in seq_profile_mode_show() local
1085 struct aa_profile *profile = labels_profile(label); in seq_profile_mode_show()
1086 seq_printf(seq, "%s\n", aa_profile_mode_names[profile->mode]); in seq_profile_mode_show()
1087 aa_put_label(label); in seq_profile_mode_show()
1094 struct aa_proxy *proxy = seq->private; in seq_profile_attach_show()
1095 struct aa_label *label = aa_get_label_rcu(&proxy->label); in seq_profile_attach_show() local
1096 struct aa_profile *profile = labels_profile(label); in seq_profile_attach_show()
1097 if (profile->attach.xmatch_str) in seq_profile_attach_show()
1098 seq_printf(seq, "%s\n", profile->attach.xmatch_str); in seq_profile_attach_show()
1099 else if (profile->attach.xmatch.dfa) in seq_profile_attach_show()
1102 seq_printf(seq, "%s\n", profile->base.name); in seq_profile_attach_show()
1103 aa_put_label(label); in seq_profile_attach_show()
1110 struct aa_proxy *proxy = seq->private; in seq_profile_hash_show()
1111 struct aa_label *label = aa_get_label_rcu(&proxy->label); in seq_profile_hash_show() local
1112 struct aa_profile *profile = labels_profile(label); in seq_profile_hash_show()
1115 if (profile->hash) { in seq_profile_hash_show()
1117 seq_printf(seq, "%.2x", profile->hash[i]); in seq_profile_hash_show()
1120 aa_put_label(label); in seq_profile_hash_show()
1139 return single_open(file, seq_ns_ ##NAME ##_show, inode->i_private); \
1152 struct aa_label *label; in seq_ns_stacked_show() local
1154 label = begin_current_label_crit_section(); in seq_ns_stacked_show()
1155 seq_printf(seq, "%s\n", label->size > 1 ? "yes" : "no"); in seq_ns_stacked_show()
1156 end_current_label_crit_section(label); in seq_ns_stacked_show()
1163 struct aa_label *label; in seq_ns_nsstacked_show() local
1168 label = begin_current_label_crit_section(); in seq_ns_nsstacked_show()
1170 if (label->size > 1) { in seq_ns_nsstacked_show()
1171 label_for_each(it, label, profile) in seq_ns_nsstacked_show()
1172 if (profile->ns != labels_ns(label)) { in seq_ns_nsstacked_show()
1179 end_current_label_crit_section(label); in seq_ns_nsstacked_show()
1186 struct aa_label *label; in seq_ns_level_show() local
1188 label = begin_current_label_crit_section(); in seq_ns_level_show()
1189 seq_printf(seq, "%d\n", labels_ns(label)->level); in seq_ns_level_show()
1190 end_current_label_crit_section(label); in seq_ns_level_show()
1197 struct aa_label *label = begin_current_label_crit_section(); in seq_ns_name_show() local
1198 seq_printf(seq, "%s\n", labels_ns(label)->base.name); in seq_ns_name_show()
1199 end_current_label_crit_section(label); in seq_ns_name_show()
1243 struct aa_loaddata *data = __aa_get_loaddata(inode->i_private); in seq_rawdata_open()
1248 return -ENOENT; in seq_rawdata_open()
1252 AA_BUG(file->private_data && in seq_rawdata_open()
1253 ((struct seq_file *)file->private_data)->private); in seq_rawdata_open()
1262 struct seq_file *seq = (struct seq_file *) file->private_data; in seq_rawdata_release()
1265 aa_put_loaddata(seq->private); in seq_rawdata_release()
1272 struct aa_loaddata *data = seq->private; in seq_rawdata_abi_show()
1274 seq_printf(seq, "v%d\n", data->abi); in seq_rawdata_abi_show()
1281 struct aa_loaddata *data = seq->private; in seq_rawdata_revision_show()
1283 seq_printf(seq, "%ld\n", data->revision); in seq_rawdata_revision_show()
1290 struct aa_loaddata *data = seq->private; in seq_rawdata_hash_show()
1293 if (data->hash) { in seq_rawdata_hash_show()
1295 seq_printf(seq, "%.2x", data->hash[i]); in seq_rawdata_hash_show()
1304 struct aa_loaddata *data = seq->private; in seq_rawdata_compressed_size_show()
1306 seq_printf(seq, "%zu\n", data->compressed_size); in seq_rawdata_compressed_size_show()
1312 SEQ_RAWDATA_FOPS(revision);
1328 ret = -ENOMEM; in decompress_zstd()
1333 ret = -ENOMEM; in decompress_zstd()
1338 ret = -EINVAL; in decompress_zstd()
1348 return -EINVAL; in decompress_zstd()
1356 struct rawdata_f_data *private = file->private_data; in rawdata_read()
1360 private->loaddata->size); in rawdata_read()
1365 rawdata_f_data_free(file->private_data); in rawdata_release()
1377 return -EACCES; in rawdata_open()
1379 loaddata = __aa_get_loaddata(inode->i_private); in rawdata_open()
1382 return -ENOENT; in rawdata_open()
1384 private = rawdata_f_data_alloc(loaddata->size); in rawdata_open()
1390 private->loaddata = loaddata; in rawdata_open()
1392 error = decompress_zstd(loaddata->data, loaddata->compressed_size, in rawdata_open()
1394 loaddata->size); in rawdata_open()
1398 file->private_data = private; in rawdata_open()
1422 if (!IS_ERR_OR_NULL(rawdata->dents[i])) { in remove_rawdata_dents()
1424 aafs_remove(rawdata->dents[i]); in remove_rawdata_dents()
1425 rawdata->dents[i] = NULL; in remove_rawdata_dents()
1432 AA_BUG(rawdata->ns && !mutex_is_locked(&rawdata->ns->lock)); in __aa_fs_remove_rawdata()
1434 if (rawdata->ns) { in __aa_fs_remove_rawdata()
1436 list_del_init(&rawdata->list); in __aa_fs_remove_rawdata()
1437 aa_put_ns(rawdata->ns); in __aa_fs_remove_rawdata()
1438 rawdata->ns = NULL; in __aa_fs_remove_rawdata()
1448 AA_BUG(!mutex_is_locked(&ns->lock)); in __aa_fs_create_rawdata()
1452 * just use ns revision dir was originally created at. This is in __aa_fs_create_rawdata()
1453 * under ns->lock and if load is successful revision will be in __aa_fs_create_rawdata()
1456 rawdata->name = kasprintf(GFP_KERNEL, "%ld", ns->revision); in __aa_fs_create_rawdata()
1457 if (!rawdata->name) in __aa_fs_create_rawdata()
1458 return -ENOMEM; in __aa_fs_create_rawdata()
1460 dir = aafs_create_dir(rawdata->name, ns_subdata_dir(ns)); in __aa_fs_create_rawdata()
1462 /* ->name freed when rawdata freed */ in __aa_fs_create_rawdata()
1464 rawdata->dents[AAFS_LOADDATA_DIR] = dir; in __aa_fs_create_rawdata()
1470 rawdata->dents[AAFS_LOADDATA_ABI] = dent; in __aa_fs_create_rawdata()
1472 dent = aafs_create_file("revision", S_IFREG | 0444, dir, rawdata, in __aa_fs_create_rawdata()
1476 rawdata->dents[AAFS_LOADDATA_REVISION] = dent; in __aa_fs_create_rawdata()
1483 rawdata->dents[AAFS_LOADDATA_HASH] = dent; in __aa_fs_create_rawdata()
1491 rawdata->dents[AAFS_LOADDATA_COMPRESSED_SIZE] = dent; in __aa_fs_create_rawdata()
1497 rawdata->dents[AAFS_LOADDATA_DATA] = dent; in __aa_fs_create_rawdata()
1498 d_inode(dent)->i_size = rawdata->size; in __aa_fs_create_rawdata()
1500 rawdata->ns = aa_get_ns(ns); in __aa_fs_create_rawdata()
1501 list_add(&rawdata->list, &ns->rawdata_list); in __aa_fs_create_rawdata()
1518 * Requires: @profile->ns->lock held
1528 list_for_each_entry(child, &profile->base.profiles, base.list) in __aafs_profile_rmdir()
1531 for (i = AAFS_PROF_SIZEOF - 1; i >= 0; --i) { in __aafs_profile_rmdir()
1533 if (!profile->dents[i]) in __aafs_profile_rmdir()
1536 proxy = d_inode(profile->dents[i])->i_private; in __aafs_profile_rmdir()
1537 aafs_remove(profile->dents[i]); in __aafs_profile_rmdir()
1539 profile->dents[i] = NULL; in __aafs_profile_rmdir()
1545 * Requires: @old->ns->lock held
1554 AA_BUG(!mutex_is_locked(&profiles_ns(old)->lock)); in __aafs_profile_migrate_dents()
1557 new->dents[i] = old->dents[i]; in __aafs_profile_migrate_dents()
1558 if (new->dents[i]) { in __aafs_profile_migrate_dents()
1559 struct inode *inode = d_inode(new->dents[i]); in __aafs_profile_migrate_dents()
1561 inode->i_mtime = inode_set_ctime_current(inode); in __aafs_profile_migrate_dents()
1563 old->dents[i] = NULL; in __aafs_profile_migrate_dents()
1571 struct aa_proxy *proxy = aa_get_proxy(profile->label.proxy); in create_profile_file()
1587 for (depth = 0; profile; profile = rcu_access_pointer(profile->parent)) in profile_depth()
1602 return ERR_PTR(-ENOMEM); in gen_symlink_name()
1604 for (; depth > 0; depth--) { in gen_symlink_name()
1607 size -= 6; in gen_symlink_name()
1613 return ERR_PTR(-ENAMETOOLONG); in gen_symlink_name()
1629 struct aa_proxy *proxy = inode->i_private; in rawdata_get_link_base()
1630 struct aa_label *label; in rawdata_get_link_base() local
1636 return ERR_PTR(-ECHILD); in rawdata_get_link_base()
1638 label = aa_get_label_rcu(&proxy->label); in rawdata_get_link_base()
1639 profile = labels_profile(label); in rawdata_get_link_base()
1641 target = gen_symlink_name(depth, profile->rawdata->name, name); in rawdata_get_link_base()
1642 aa_put_label(label); in rawdata_get_link_base()
1686 * Requires: @profile->ns->lock held
1695 AA_BUG(!mutex_is_locked(&profiles_ns(profile)->lock)); in __aafs_profile_mkdir()
1702 error = -ENOENT; in __aafs_profile_mkdir()
1712 if (!profile->dirname) { in __aafs_profile_mkdir()
1714 len = mangle_name(profile->base.name, NULL); in __aafs_profile_mkdir()
1715 id_len = snprintf(NULL, 0, ".%ld", profile->ns->uniq_id); in __aafs_profile_mkdir()
1717 profile->dirname = kmalloc(len + id_len + 1, GFP_KERNEL); in __aafs_profile_mkdir()
1718 if (!profile->dirname) { in __aafs_profile_mkdir()
1719 error = -ENOMEM; in __aafs_profile_mkdir()
1723 mangle_name(profile->base.name, profile->dirname); in __aafs_profile_mkdir()
1724 sprintf(profile->dirname + len, ".%ld", profile->ns->uniq_id++); in __aafs_profile_mkdir()
1727 dent = aafs_create_dir(profile->dirname, parent); in __aafs_profile_mkdir()
1736 profile->dents[AAFS_PROF_NAME] = dent; in __aafs_profile_mkdir()
1742 profile->dents[AAFS_PROF_MODE] = dent; in __aafs_profile_mkdir()
1748 profile->dents[AAFS_PROF_ATTACH] = dent; in __aafs_profile_mkdir()
1750 if (profile->hash) { in __aafs_profile_mkdir()
1755 profile->dents[AAFS_PROF_HASH] = dent; in __aafs_profile_mkdir()
1759 if (profile->rawdata) { in __aafs_profile_mkdir()
1762 profile->label.proxy, NULL, NULL, in __aafs_profile_mkdir()
1766 aa_get_proxy(profile->label.proxy); in __aafs_profile_mkdir()
1767 profile->dents[AAFS_PROF_RAW_HASH] = dent; in __aafs_profile_mkdir()
1770 profile->label.proxy, NULL, NULL, in __aafs_profile_mkdir()
1774 aa_get_proxy(profile->label.proxy); in __aafs_profile_mkdir()
1775 profile->dents[AAFS_PROF_RAW_ABI] = dent; in __aafs_profile_mkdir()
1778 profile->label.proxy, NULL, NULL, in __aafs_profile_mkdir()
1782 aa_get_proxy(profile->label.proxy); in __aafs_profile_mkdir()
1783 profile->dents[AAFS_PROF_RAW_DATA] = dent; in __aafs_profile_mkdir()
1787 list_for_each_entry(child, &profile->base.profiles, base.list) { in __aafs_profile_mkdir()
1809 struct aa_label *label; in ns_mkdir_op() local
1812 label = begin_current_label_crit_section(); in ns_mkdir_op()
1813 error = aa_may_manage_policy(current_cred(), label, NULL, in ns_mkdir_op()
1815 end_current_label_crit_section(label); in ns_mkdir_op()
1819 parent = aa_get_ns(dir->i_private); in ns_mkdir_op()
1827 mutex_lock_nested(&parent->lock, parent->level); in ns_mkdir_op()
1837 ns = __aa_find_or_create_ns(parent, READ_ONCE(dentry->d_name.name), in ns_mkdir_op()
1849 mutex_unlock(&parent->lock); in ns_mkdir_op()
1859 struct aa_label *label; in ns_rmdir_op() local
1862 label = begin_current_label_crit_section(); in ns_rmdir_op()
1863 error = aa_may_manage_policy(current_cred(), label, NULL, in ns_rmdir_op()
1865 end_current_label_crit_section(label); in ns_rmdir_op()
1869 parent = aa_get_ns(dir->i_private); in ns_rmdir_op()
1875 inode_unlock(dentry->d_inode); in ns_rmdir_op()
1877 mutex_lock_nested(&parent->lock, parent->level); in ns_rmdir_op()
1878 ns = aa_get_ns(__aa_findn_ns(&parent->sub_ns, dentry->d_name.name, in ns_rmdir_op()
1879 dentry->d_name.len)); in ns_rmdir_op()
1881 error = -ENOENT; in ns_rmdir_op()
1890 mutex_unlock(&parent->lock); in ns_rmdir_op()
1892 inode_lock(dentry->d_inode); in ns_rmdir_op()
1908 AA_BUG(!mutex_is_locked(&ns->lock)); in __aa_fs_list_remove_rawdata()
1910 list_for_each_entry_safe(ent, tmp, &ns->rawdata_list, list) in __aa_fs_list_remove_rawdata()
1916 * Requires: @ns->lock held
1926 AA_BUG(!mutex_is_locked(&ns->lock)); in __aafs_ns_rmdir()
1928 list_for_each_entry(child, &ns->base.profiles, base.list) in __aafs_ns_rmdir()
1931 list_for_each_entry(sub, &ns->sub_ns, base.list) { in __aafs_ns_rmdir()
1932 mutex_lock_nested(&sub->lock, sub->level); in __aafs_ns_rmdir()
1934 mutex_unlock(&sub->lock); in __aafs_ns_rmdir()
1940 sub = d_inode(ns_subns_dir(ns))->i_private; in __aafs_ns_rmdir()
1944 sub = d_inode(ns_subload(ns))->i_private; in __aafs_ns_rmdir()
1948 sub = d_inode(ns_subreplace(ns))->i_private; in __aafs_ns_rmdir()
1952 sub = d_inode(ns_subremove(ns))->i_private; in __aafs_ns_rmdir()
1956 sub = d_inode(ns_subrevision(ns))->i_private; in __aafs_ns_rmdir()
1960 for (i = AAFS_NS_SIZEOF - 1; i >= 0; --i) { in __aafs_ns_rmdir()
1961 aafs_remove(ns->dents[i]); in __aafs_ns_rmdir()
1962 ns->dents[i] = NULL; in __aafs_ns_rmdir()
1984 dent = aafs_create_file("revision", 0444, dir, ns, in __aafs_ns_mkdir_entries()
2024 * Requires: @ns->lock held
2036 AA_BUG(!mutex_is_locked(&ns->lock)); in __aafs_ns_mkdir()
2039 name = ns->base.name; in __aafs_ns_mkdir()
2054 list_for_each_entry(child, &ns->base.profiles, base.list) { in __aafs_ns_mkdir()
2061 list_for_each_entry(sub, &ns->sub_ns, base.list) { in __aafs_ns_mkdir()
2062 mutex_lock_nested(&sub->lock, sub->level); in __aafs_ns_mkdir()
2064 mutex_unlock(&sub->lock); in __aafs_ns_mkdir()
2081 * __next_ns - find the next namespace to list
2089 * Requires: ns->parent->lock to be held
2090 * NOTE: will not unlock root->lock
2098 AA_BUG(ns != root && !mutex_is_locked(&ns->parent->lock)); in __next_ns()
2101 if (!list_empty(&ns->sub_ns)) { in __next_ns()
2102 next = list_first_entry(&ns->sub_ns, typeof(*ns), base.list); in __next_ns()
2103 mutex_lock_nested(&next->lock, next->level); in __next_ns()
2108 parent = ns->parent; in __next_ns()
2110 mutex_unlock(&ns->lock); in __next_ns()
2112 if (!list_entry_is_head(next, &parent->sub_ns, base.list)) { in __next_ns()
2113 mutex_lock_nested(&next->lock, next->level); in __next_ns()
2117 parent = parent->parent; in __next_ns()
2124 * __first_profile - find the first profile in a namespace
2129 * Requires: profile->ns.lock to be held
2135 AA_BUG(ns && !mutex_is_locked(&ns->lock)); in __first_profile()
2138 if (!list_empty(&ns->base.profiles)) in __first_profile()
2139 return list_first_entry(&ns->base.profiles, in __first_profile()
2146 * __next_profile - step to the next profile in a profile tree
2152 * Requires: profile->ns.lock to be held
2157 struct aa_ns *ns = p->ns; in __next_profile()
2159 AA_BUG(!mutex_is_locked(&profiles_ns(p)->lock)); in __next_profile()
2162 if (!list_empty(&p->base.profiles)) in __next_profile()
2163 return list_first_entry(&p->base.profiles, typeof(*p), in __next_profile()
2167 parent = rcu_dereference_protected(p->parent, in __next_profile()
2168 mutex_is_locked(&p->ns->lock)); in __next_profile()
2171 if (!list_entry_is_head(p, &parent->base.profiles, base.list)) in __next_profile()
2174 parent = rcu_dereference_protected(parent->parent, in __next_profile()
2175 mutex_is_locked(&parent->ns->lock)); in __next_profile()
2180 if (!list_entry_is_head(p, &ns->base.profiles, base.list)) in __next_profile()
2187 * next_profile - step to the next profile in where ever it may be
2201 return __first_profile(root, __next_ns(root, profile->ns)); in next_profile()
2205 * p_start - start a depth first traversal of profile tree
2211 * acquires first ns->lock
2218 f->private = root; in p_start()
2221 mutex_lock_nested(&root->lock, root->level); in p_start()
2225 for (; profile && l > 0; l--) in p_start()
2232 * p_next - read the next profile entry
2244 struct aa_ns *ns = f->private; in p_next()
2251 * p_stop - stop depth first traversal
2260 struct aa_ns *root = f->private, *ns; in p_stop()
2263 for (ns = profile->ns; ns && ns != root; ns = ns->parent) in p_stop()
2264 mutex_unlock(&ns->lock); in p_stop()
2266 mutex_unlock(&root->lock); in p_stop()
2271 * seq_show_profile - show a profile entry
2280 struct aa_ns *root = f->private; in seq_show_profile()
2282 aa_label_seq_xprint(f, root, &profile->label, in seq_show_profile()
2299 return -EACCES; in profiles_open()
2389 AA_SFS_DIR("label", aa_sfs_entry_query_label),
2425 * entry_create_file - create a file entry in the apparmor securityfs
2436 fs_file->dentry = securityfs_create_file(fs_file->name, in entry_create_file()
2437 S_IFREG | fs_file->mode, in entry_create_file()
2439 fs_file->file_ops); in entry_create_file()
2440 if (IS_ERR(fs_file->dentry)) { in entry_create_file()
2441 error = PTR_ERR(fs_file->dentry); in entry_create_file()
2442 fs_file->dentry = NULL; in entry_create_file()
2449 * entry_create_dir - recursively create a directory entry in the securityfs
2462 dir = securityfs_create_dir(fs_dir->name, parent); in entry_create_dir()
2465 fs_dir->dentry = dir; in entry_create_dir()
2467 for (fs_file = fs_dir->v.files; fs_file && fs_file->name; ++fs_file) { in entry_create_dir()
2468 if (fs_file->v_type == AA_SFS_TYPE_DIR) in entry_create_dir()
2469 error = entry_create_dir(fs_file, fs_dir->dentry); in entry_create_dir()
2471 error = entry_create_file(fs_file, fs_dir->dentry); in entry_create_dir()
2485 * entry_remove_file - drop a single file entry in the apparmor securityfs
2490 if (!fs_file->dentry) in entry_remove_file()
2493 securityfs_remove(fs_file->dentry); in entry_remove_file()
2494 fs_file->dentry = NULL; in entry_remove_file()
2498 * entry_remove_dir - recursively drop a directory entry from the securityfs
2505 for (fs_file = fs_dir->v.files; fs_file && fs_file->name; ++fs_file) { in entry_remove_dir()
2506 if (fs_file->v_type == AA_SFS_TYPE_DIR) in entry_remove_dir()
2516 * aa_destroy_aafs - cleanup and free aafs
2535 int error = simple_pin_fs(parent->d_sb->s_type, &mount, &count); in aa_mk_null_file()
2546 inode = new_inode(parent->d_inode->i_sb); in aa_mk_null_file()
2548 error = -ENOMEM; in aa_mk_null_file()
2552 inode->i_ino = get_next_ino(); in aa_mk_null_file()
2553 inode->i_mode = S_IFCHR | S_IRUGO | S_IWUGO; in aa_mk_null_file()
2554 inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode); in aa_mk_null_file()
2582 return ERR_PTR(-ECHILD); in policy_get_link()
2600 d_inode(dentry)->i_ino); in policy_readlink()
2604 res = -ENOENT; in policy_readlink()
2616 * aa_create_aafs - create the apparmor security filesystem
2632 return -EEXIST; in aa_create_aafs()
2639 aafs_mnt->mnt_sb->s_flags &= ~SB_NOUSER; in aa_create_aafs()
2664 dent = securityfs_create_file("revision", 0444, aa_sfs_entry.dentry, in aa_create_aafs()
2671 mutex_lock_nested(&root_ns->lock, root_ns->level); in aa_create_aafs()
2672 error = __aafs_ns_mkdir(root_ns, aafs_mnt->mnt_root, ".policy", in aa_create_aafs()
2673 aafs_mnt->mnt_root); in aa_create_aafs()
2674 mutex_unlock(&root_ns->lock); in aa_create_aafs()