af_unix.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * AppArmor security module
  4. *
  5. * This file contains AppArmor af_unix fine grained mediation
  6. *
  7. * Copyright 2023 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_AF_UNIX_H
  15. #include <net/af_unix.h>
  16. #include "label.h"
  17. #define unix_addr(A) ((struct sockaddr_un *)(A))
  18. #define unix_addr_len(L) ((L) - sizeof(sa_family_t))
  19. #define unix_peer(sk) (unix_sk(sk)->peer)
  20. #define is_unix_addr_abstract_name(B) ((B)[0] == 0)
  21. #define is_unix_addr_anon(A, L) ((A) && unix_addr_len(L) <= 0)
  22. #define is_unix_addr_fs(A, L) (!is_unix_addr_anon(A, L) && \
  23. !is_unix_addr_abstract_name(unix_addr(A)->sun_path))
  24. #define is_unix_anonymous(U) (!unix_sk(U)->addr)
  25. #define is_unix_fs(U) (!is_unix_anonymous(U) && \
  26. unix_sk(U)->addr->name->sun_path[0])
  27. #define is_unix_connected(S) ((S)->state == SS_CONNECTED)
  28. struct sockaddr_un *aa_sunaddr(const struct unix_sock *u, int *addrlen);
  29. int aa_unix_peer_perm(const struct cred *subj_cred,
  30. struct aa_label *label, const char *op, u32 request,
  31. struct sock *sk, struct sock *peer_sk,
  32. struct aa_label *peer_label);
  33. int aa_unix_sock_perm(const char *op, u32 request, struct socket *sock);
  34. int aa_unix_create_perm(struct aa_label *label, int family, int type,
  35. int protocol);
  36. int aa_unix_bind_perm(struct socket *sock, struct sockaddr *address,
  37. int addrlen);
  38. int aa_unix_connect_perm(struct socket *sock, struct sockaddr *address,
  39. int addrlen);
  40. int aa_unix_listen_perm(struct socket *sock, int backlog);
  41. int aa_unix_accept_perm(struct socket *sock, struct socket *newsock);
  42. int aa_unix_msg_perm(const char *op, u32 request, struct socket *sock,
  43. struct msghdr *msg, int size);
  44. int aa_unix_opt_perm(const char *op, u32 request, struct socket *sock, int level,
  45. int optname);
  46. int aa_unix_file_perm(const struct cred *subj_cred, struct aa_label *label,
  47. const char *op, u32 request, struct file *file);
  48. #endif /* __AA_AF_UNIX_H */