net.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * AppArmor security module
  3. *
  4. * This file contains AppArmor network mediation definitions.
  5. *
  6. * Copyright (C) 1998-2008 Novell/SUSE
  7. * Copyright 2009-2017 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_NET_H
  15. #define __AA_NET_H
  16. #include <net/sock.h>
  17. #include <linux/path.h>
  18. #include "apparmorfs.h"
  19. #include "label.h"
  20. #include "perms.h"
  21. #include "policy.h"
  22. #define AA_MAY_SEND AA_MAY_WRITE
  23. #define AA_MAY_RECEIVE AA_MAY_READ
  24. #define AA_MAY_SHUTDOWN AA_MAY_DELETE
  25. #define AA_MAY_CONNECT AA_MAY_OPEN
  26. #define AA_MAY_ACCEPT 0x00100000
  27. #define AA_MAY_BIND 0x00200000
  28. #define AA_MAY_LISTEN 0x00400000
  29. #define AA_MAY_SETOPT 0x01000000
  30. #define AA_MAY_GETOPT 0x02000000
  31. #define NET_PERMS_MASK (AA_MAY_SEND | AA_MAY_RECEIVE | AA_MAY_CREATE | \
  32. AA_MAY_SHUTDOWN | AA_MAY_BIND | AA_MAY_LISTEN | \
  33. AA_MAY_CONNECT | AA_MAY_ACCEPT | AA_MAY_SETATTR | \
  34. AA_MAY_GETATTR | AA_MAY_SETOPT | AA_MAY_GETOPT)
  35. #define NET_FS_PERMS (AA_MAY_SEND | AA_MAY_RECEIVE | AA_MAY_CREATE | \
  36. AA_MAY_SHUTDOWN | AA_MAY_CONNECT | AA_MAY_RENAME |\
  37. AA_MAY_SETATTR | AA_MAY_GETATTR | AA_MAY_CHMOD | \
  38. AA_MAY_CHOWN | AA_MAY_CHGRP | AA_MAY_LOCK | \
  39. AA_MAY_MPROT)
  40. #define NET_PEER_MASK (AA_MAY_SEND | AA_MAY_RECEIVE | AA_MAY_CONNECT | \
  41. AA_MAY_ACCEPT)
  42. struct aa_sk_ctx {
  43. struct aa_label *label;
  44. struct aa_label *peer;
  45. };
  46. #define SK_CTX(X) ((X)->sk_security)
  47. #define SOCK_ctx(X) SOCK_INODE(X)->i_security
  48. #define DEFINE_AUDIT_NET(NAME, OP, SK, F, T, P) \
  49. struct lsm_network_audit NAME ## _net = { .sk = (SK), \
  50. .family = (F)}; \
  51. DEFINE_AUDIT_DATA(NAME, \
  52. ((SK) && (F) != AF_UNIX) ? LSM_AUDIT_DATA_NET : \
  53. LSM_AUDIT_DATA_NONE, \
  54. OP); \
  55. NAME.u.net = &(NAME ## _net); \
  56. aad(&NAME)->net.type = (T); \
  57. aad(&NAME)->net.protocol = (P)
  58. #define DEFINE_AUDIT_SK(NAME, OP, SK) \
  59. DEFINE_AUDIT_NET(NAME, OP, SK, (SK)->sk_family, (SK)->sk_type, \
  60. (SK)->sk_protocol)
  61. #define af_select(FAMILY, FN, DEF_FN) \
  62. ({ \
  63. int __e; \
  64. switch ((FAMILY)) { \
  65. default: \
  66. __e = DEF_FN; \
  67. } \
  68. __e; \
  69. })
  70. extern struct aa_sfs_entry aa_sfs_entry_network[];
  71. void audit_net_cb(struct audit_buffer *ab, void *va);
  72. int aa_profile_af_perm(struct aa_profile *profile, struct common_audit_data *sa,
  73. u32 request, u16 family, int type);
  74. int aa_af_perm(struct aa_label *label, const char *op, u32 request, u16 family,
  75. int type, int protocol);
  76. static inline int aa_profile_af_sk_perm(struct aa_profile *profile,
  77. struct common_audit_data *sa,
  78. u32 request,
  79. struct sock *sk)
  80. {
  81. return aa_profile_af_perm(profile, sa, request, sk->sk_family,
  82. sk->sk_type);
  83. }
  84. int aa_sk_perm(const char *op, u32 request, struct sock *sk);
  85. int aa_sock_file_perm(struct aa_label *label, const char *op, u32 request,
  86. struct socket *sock);
  87. #endif /* __AA_NET_H */