path.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * AppArmor security module
  3. *
  4. * This file contains AppArmor basic path manipulation 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 __AA_PATH_H
  15. #define __AA_PATH_H
  16. enum path_flags {
  17. PATH_IS_DIR = 0x1, /* path is a directory */
  18. PATH_CONNECT_PATH = 0x4, /* connect disconnected paths to / */
  19. PATH_CHROOT_REL = 0x8, /* do path lookup relative to chroot */
  20. PATH_CHROOT_NSCONNECT = 0x10, /* connect paths that are at ns root */
  21. PATH_DELEGATE_DELETED = 0x08000, /* delegate deleted files */
  22. PATH_MEDIATE_DELETED = 0x10000, /* mediate deleted paths */
  23. };
  24. int aa_path_name(const struct path *path, int flags, char *buffer,
  25. const char **name, const char **info,
  26. const char *disconnected);
  27. #define MAX_PATH_BUFFERS 2
  28. /* Per cpu buffers used during mediation */
  29. /* preallocated buffers to use during path lookups */
  30. struct aa_buffers {
  31. char *buf[MAX_PATH_BUFFERS];
  32. };
  33. #include <linux/percpu.h>
  34. #include <linux/preempt.h>
  35. DECLARE_PER_CPU(struct aa_buffers, aa_buffers);
  36. #define ASSIGN(FN, A, X, N) ((X) = FN(A, N))
  37. #define EVAL1(FN, A, X) ASSIGN(FN, A, X, 0) /*X = FN(0)*/
  38. #define EVAL2(FN, A, X, Y...) \
  39. do { ASSIGN(FN, A, X, 1); EVAL1(FN, A, Y); } while (0)
  40. #define EVAL(FN, A, X...) CONCATENATE(EVAL, COUNT_ARGS(X))(FN, A, X)
  41. #define for_each_cpu_buffer(I) for ((I) = 0; (I) < MAX_PATH_BUFFERS; (I)++)
  42. #ifdef CONFIG_DEBUG_PREEMPT
  43. #define AA_BUG_PREEMPT_ENABLED(X) AA_BUG(preempt_count() <= 0, X)
  44. #else
  45. #define AA_BUG_PREEMPT_ENABLED(X) /* nop */
  46. #endif
  47. #define __get_buffer(C, N) ({ \
  48. AA_BUG_PREEMPT_ENABLED("__get_buffer without preempt disabled"); \
  49. (C)->buf[(N)]; })
  50. #define __get_buffers(C, X...) EVAL(__get_buffer, C, X)
  51. #define __put_buffers(X, Y...) ((void)&(X))
  52. #define get_buffers(X...) \
  53. do { \
  54. struct aa_buffers *__cpu_var = get_cpu_ptr(&aa_buffers); \
  55. __get_buffers(__cpu_var, X); \
  56. } while (0)
  57. #define put_buffers(X, Y...) \
  58. do { \
  59. __put_buffers(X, Y); \
  60. put_cpu_ptr(&aa_buffers); \
  61. } while (0)
  62. #endif /* __AA_PATH_H */