apparmorfs.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * AppArmor security module
  4. *
  5. * This file contains AppArmor filesystem definitions.
  6. *
  7. * Copyright (C) 1998-2008 Novell/SUSE
  8. * Copyright 2009-2010 Canonical Ltd.
  9. */
  10. #ifndef __AA_APPARMORFS_H
  11. #define __AA_APPARMORFS_H
  12. extern struct path aa_null;
  13. enum aa_sfs_type {
  14. AA_SFS_TYPE_BOOLEAN,
  15. AA_SFS_TYPE_STRING,
  16. AA_SFS_TYPE_U64,
  17. AA_SFS_TYPE_FOPS,
  18. AA_SFS_TYPE_DIR,
  19. };
  20. struct aa_sfs_entry;
  21. struct aa_sfs_entry {
  22. const char *name;
  23. struct dentry *dentry;
  24. umode_t mode;
  25. enum aa_sfs_type v_type;
  26. union {
  27. bool boolean;
  28. char *string;
  29. unsigned long u64;
  30. struct aa_sfs_entry *files;
  31. } v;
  32. const struct file_operations *file_ops;
  33. };
  34. extern const struct file_operations aa_sfs_seq_file_ops;
  35. #define AA_SFS_FILE_BOOLEAN(_name, _value) \
  36. { .name = (_name), .mode = 0444, \
  37. .v_type = AA_SFS_TYPE_BOOLEAN, .v.boolean = (_value), \
  38. .file_ops = &aa_sfs_seq_file_ops }
  39. #define AA_SFS_FILE_STRING(_name, _value) \
  40. { .name = (_name), .mode = 0444, \
  41. .v_type = AA_SFS_TYPE_STRING, .v.string = (_value), \
  42. .file_ops = &aa_sfs_seq_file_ops }
  43. #define AA_SFS_FILE_U64(_name, _value) \
  44. { .name = (_name), .mode = 0444, \
  45. .v_type = AA_SFS_TYPE_U64, .v.u64 = (_value), \
  46. .file_ops = &aa_sfs_seq_file_ops }
  47. #define AA_SFS_FILE_FOPS(_name, _mode, _fops) \
  48. { .name = (_name), .v_type = AA_SFS_TYPE_FOPS, \
  49. .mode = (_mode), .file_ops = (_fops) }
  50. #define AA_SFS_DIR(_name, _value) \
  51. { .name = (_name), .v_type = AA_SFS_TYPE_DIR, .v.files = (_value) }
  52. extern void __init aa_destroy_aafs(void);
  53. struct aa_profile;
  54. struct aa_ns;
  55. enum aafs_ns_type {
  56. AAFS_NS_DIR,
  57. AAFS_NS_PROFS,
  58. AAFS_NS_NS,
  59. AAFS_NS_RAW_DATA,
  60. AAFS_NS_LOAD,
  61. AAFS_NS_REPLACE,
  62. AAFS_NS_REMOVE,
  63. AAFS_NS_REVISION,
  64. AAFS_NS_COUNT,
  65. AAFS_NS_MAX_COUNT,
  66. AAFS_NS_SIZE,
  67. AAFS_NS_MAX_SIZE,
  68. AAFS_NS_OWNER,
  69. AAFS_NS_SIZEOF,
  70. };
  71. enum aafs_prof_type {
  72. AAFS_PROF_DIR,
  73. AAFS_PROF_PROFS,
  74. AAFS_PROF_NAME,
  75. AAFS_PROF_MODE,
  76. AAFS_PROF_ATTACH,
  77. AAFS_PROF_HASH,
  78. AAFS_PROF_RAW_DATA,
  79. AAFS_PROF_RAW_HASH,
  80. AAFS_PROF_RAW_ABI,
  81. AAFS_PROF_SIZEOF,
  82. };
  83. #define ns_dir(X) ((X)->dents[AAFS_NS_DIR])
  84. #define ns_subns_dir(X) ((X)->dents[AAFS_NS_NS])
  85. #define ns_subprofs_dir(X) ((X)->dents[AAFS_NS_PROFS])
  86. #define ns_subdata_dir(X) ((X)->dents[AAFS_NS_RAW_DATA])
  87. #define ns_subload(X) ((X)->dents[AAFS_NS_LOAD])
  88. #define ns_subreplace(X) ((X)->dents[AAFS_NS_REPLACE])
  89. #define ns_subremove(X) ((X)->dents[AAFS_NS_REMOVE])
  90. #define ns_subrevision(X) ((X)->dents[AAFS_NS_REVISION])
  91. #define prof_dir(X) ((X)->dents[AAFS_PROF_DIR])
  92. #define prof_child_dir(X) ((X)->dents[AAFS_PROF_PROFS])
  93. void __aa_bump_ns_revision(struct aa_ns *ns);
  94. void __aafs_profile_rmdir(struct aa_profile *profile);
  95. void __aafs_profile_migrate_dents(struct aa_profile *old,
  96. struct aa_profile *new);
  97. int __aafs_profile_mkdir(struct aa_profile *profile, struct dentry *parent);
  98. void __aafs_ns_rmdir(struct aa_ns *ns);
  99. int __aafs_ns_mkdir(struct aa_ns *ns, struct dentry *parent, const char *name,
  100. struct dentry *dent);
  101. struct aa_loaddata;
  102. #ifdef CONFIG_SECURITY_APPARMOR_EXPORT_BINARY
  103. void __aa_fs_remove_rawdata(struct aa_loaddata *rawdata);
  104. int __aa_fs_create_rawdata(struct aa_ns *ns, struct aa_loaddata *rawdata);
  105. #else
  106. static inline void __aa_fs_remove_rawdata(struct aa_loaddata *rawdata)
  107. {
  108. /* empty stub */
  109. }
  110. static inline int __aa_fs_create_rawdata(struct aa_ns *ns,
  111. struct aa_loaddata *rawdata)
  112. {
  113. return 0;
  114. }
  115. #endif /* CONFIG_SECURITY_APPARMOR_EXPORT_BINARY */
  116. #endif /* __AA_APPARMORFS_H */