task.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * AppArmor security module
  4. *
  5. * This file contains AppArmor task related definitions and mediation
  6. *
  7. * Copyright 2017 Canonical Ltd.
  8. */
  9. #ifndef __AA_TASK_H
  10. #define __AA_TASK_H
  11. static inline struct aa_task_ctx *task_ctx(struct task_struct *task)
  12. {
  13. return task->security + apparmor_blob_sizes.lbs_task;
  14. }
  15. /*
  16. * struct aa_task_ctx - information for current task label change
  17. * @nnp: snapshot of label at time of no_new_privs
  18. * @onexec: profile to transition to on next exec (MAY BE NULL)
  19. * @previous: profile the task may return to (MAY BE NULL)
  20. * @token: magic value the task must know for returning to @previous_profile
  21. */
  22. struct aa_task_ctx {
  23. struct aa_label *nnp;
  24. struct aa_label *onexec;
  25. struct aa_label *previous;
  26. u64 token;
  27. };
  28. int aa_replace_current_label(struct aa_label *label);
  29. int aa_set_current_onexec(struct aa_label *label, bool stack);
  30. int aa_set_current_hat(struct aa_label *label, u64 token);
  31. int aa_restore_previous_label(u64 cookie);
  32. struct aa_label *aa_get_task_label(struct task_struct *task);
  33. /**
  34. * aa_free_task_ctx - free a task_ctx
  35. * @ctx: task_ctx to free (MAYBE NULL)
  36. */
  37. static inline void aa_free_task_ctx(struct aa_task_ctx *ctx)
  38. {
  39. if (ctx) {
  40. aa_put_label(ctx->nnp);
  41. aa_put_label(ctx->previous);
  42. aa_put_label(ctx->onexec);
  43. }
  44. }
  45. /**
  46. * aa_dup_task_ctx - duplicate a task context, incrementing reference counts
  47. * @new: a blank task context (NOT NULL)
  48. * @old: the task context to copy (NOT NULL)
  49. */
  50. static inline void aa_dup_task_ctx(struct aa_task_ctx *new,
  51. const struct aa_task_ctx *old)
  52. {
  53. *new = *old;
  54. aa_get_label(new->nnp);
  55. aa_get_label(new->previous);
  56. aa_get_label(new->onexec);
  57. }
  58. /**
  59. * aa_clear_task_ctx_trans - clear transition tracking info from the ctx
  60. * @ctx: task context to clear (NOT NULL)
  61. */
  62. static inline void aa_clear_task_ctx_trans(struct aa_task_ctx *ctx)
  63. {
  64. AA_BUG(!ctx);
  65. aa_put_label(ctx->previous);
  66. aa_put_label(ctx->onexec);
  67. ctx->previous = NULL;
  68. ctx->onexec = NULL;
  69. ctx->token = 0;
  70. }
  71. #define AA_PTRACE_TRACE MAY_WRITE
  72. #define AA_PTRACE_READ MAY_READ
  73. #define AA_MAY_BE_TRACED AA_MAY_APPEND
  74. #define AA_MAY_BE_READ AA_MAY_CREATE
  75. #define PTRACE_PERM_SHIFT 2
  76. #define AA_PTRACE_PERM_MASK (AA_PTRACE_READ | AA_PTRACE_TRACE | \
  77. AA_MAY_BE_READ | AA_MAY_BE_TRACED)
  78. #define AA_SIGNAL_PERM_MASK (MAY_READ | MAY_WRITE)
  79. #define AA_SFS_SIG_MASK "hup int quit ill trap abrt bus fpe kill usr1 " \
  80. "segv usr2 pipe alrm term stkflt chld cont stop stp ttin ttou urg " \
  81. "xcpu xfsz vtalrm prof winch io pwr sys emt lost"
  82. int aa_may_ptrace(struct aa_label *tracer, struct aa_label *tracee,
  83. u32 request);
  84. #endif /* __AA_TASK_H */