policy_unpack.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * AppArmor security module
  3. *
  4. * This file contains AppArmor policy loading interface function definitions.
  5. *
  6. * Copyright (C) 1998-2008 Novell/SUSE
  7. * Copyright 2009-2010 Canonical Ltd.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation, version 2 of the
  12. * License.
  13. */
  14. #ifndef __POLICY_INTERFACE_H
  15. #define __POLICY_INTERFACE_H
  16. #include <linux/list.h>
  17. #include <linux/kref.h>
  18. #include <linux/dcache.h>
  19. #include <linux/workqueue.h>
  20. struct aa_load_ent {
  21. struct list_head list;
  22. struct aa_profile *new;
  23. struct aa_profile *old;
  24. struct aa_profile *rename;
  25. const char *ns_name;
  26. };
  27. void aa_load_ent_free(struct aa_load_ent *ent);
  28. struct aa_load_ent *aa_load_ent_alloc(void);
  29. #define PACKED_FLAG_HAT 1
  30. #define PACKED_MODE_ENFORCE 0
  31. #define PACKED_MODE_COMPLAIN 1
  32. #define PACKED_MODE_KILL 2
  33. #define PACKED_MODE_UNCONFINED 3
  34. struct aa_ns;
  35. enum {
  36. AAFS_LOADDATA_ABI = 0,
  37. AAFS_LOADDATA_REVISION,
  38. AAFS_LOADDATA_HASH,
  39. AAFS_LOADDATA_DATA,
  40. AAFS_LOADDATA_DIR, /* must be last actual entry */
  41. AAFS_LOADDATA_NDENTS /* count of entries */
  42. };
  43. /*
  44. * struct aa_loaddata - buffer of policy raw_data set
  45. *
  46. * there is no loaddata ref for being on ns list, nor a ref from
  47. * d_inode(@dentry) when grab a ref from these, @ns->lock must be held
  48. * && __aa_get_loaddata() needs to be used, and the return value
  49. * checked, if NULL the loaddata is already being reaped and should be
  50. * considered dead.
  51. */
  52. struct aa_loaddata {
  53. struct kref count;
  54. struct list_head list;
  55. struct work_struct work;
  56. struct dentry *dents[AAFS_LOADDATA_NDENTS];
  57. struct aa_ns *ns;
  58. char *name;
  59. size_t size;
  60. long revision; /* the ns policy revision this caused */
  61. int abi;
  62. unsigned char *hash;
  63. char *data;
  64. };
  65. int aa_unpack(struct aa_loaddata *udata, struct list_head *lh, const char **ns);
  66. /**
  67. * __aa_get_loaddata - get a reference count to uncounted data reference
  68. * @data: reference to get a count on
  69. *
  70. * Returns: pointer to reference OR NULL if race is lost and reference is
  71. * being repeated.
  72. * Requires: @data->ns->lock held, and the return code MUST be checked
  73. *
  74. * Use only from inode->i_private and @data->list found references
  75. */
  76. static inline struct aa_loaddata *
  77. __aa_get_loaddata(struct aa_loaddata *data)
  78. {
  79. if (data && kref_get_unless_zero(&(data->count)))
  80. return data;
  81. return NULL;
  82. }
  83. /**
  84. * aa_get_loaddata - get a reference count from a counted data reference
  85. * @data: reference to get a count on
  86. *
  87. * Returns: point to reference
  88. * Requires: @data to have a valid reference count on it. It is a bug
  89. * if the race to reap can be encountered when it is used.
  90. */
  91. static inline struct aa_loaddata *
  92. aa_get_loaddata(struct aa_loaddata *data)
  93. {
  94. struct aa_loaddata *tmp = __aa_get_loaddata(data);
  95. AA_BUG(data && !tmp);
  96. return tmp;
  97. }
  98. void __aa_loaddata_update(struct aa_loaddata *data, long revision);
  99. bool aa_rawdata_eq(struct aa_loaddata *l, struct aa_loaddata *r);
  100. void aa_loaddata_kref(struct kref *kref);
  101. struct aa_loaddata *aa_loaddata_alloc(size_t size);
  102. static inline void aa_put_loaddata(struct aa_loaddata *data)
  103. {
  104. if (data)
  105. kref_put(&data->count, aa_loaddata_kref);
  106. }
  107. #endif /* __POLICY_INTERFACE_H */